Experiment No 7 : Simple Data Analysis with Spreadsheets

 Objectives

  • Display an electrical signal and export it as a .csv file.

  • Read this .csv or .xls file as an array and plot it.

  • Compute the mean and standard deviation of the signal. Plot its histogram with an appropriate bin size.

Theory

Pandas is a powerful and flexible Python package that allows you to work with labeled and time series data. It also provides statistics methods, enables plotting, and more. One crucial feature of Pandas is its ability to write and read Excel, CSV, and many other types of files. Functions like the Pandas read_csv() method enable you to work with files effectively. You can use them to save the data and labels from Pandas objects to a file and load them later as Pandas Series or DataFrame instances. A comma-separated values (CSV) file is a plaintext file with a .csv extension that holds tabular data. This is one of the most popular file formats for storing large amounts of data. Each row of the CSV file represents a single table row. The values in the same row are by default separated with commas, but you could change the separator to a semicolon, tab, space, or some other character.

Steps to follow

  1. First you have to create generate a sine signal values 

  2. Save that  values to a variable dat

  3. You can use this dat to create an instance of a Pandas DataFrame. 

  4. For that you need to import Pandas

  5. You can reverse the rows and columns of a DataFrame with the property .T:

  6. You can save your Pandas DataFrame as a CSV file with .to_csv():

  7. Once your data is saved in a CSV file, you’ll likely want to load and use it from time to time. You can do that with the Pandas read_csv() function:

  8. Use pandas .plot() function to plot the read data

  9. Use .hist() to plot the histogram of the data 

  10. Use .std() function to find the standard deviation

  11. Use .mean() function to find the mean 

Program 

#importing libraries

import numpy as np

import pandas as pd

import matplotlib.pyplot as plt

# Get x values of the wave

t = np.linspace(0,1,100)

# calculating the amplitude

y = np.sin(2*np.pi*t) # calculating sine wave

dat = [t,y]

# writing the value in to data.csv

df = pd.DataFrame(data=dat,index=["Time","Amplitude"]).T

# df

df.to_csv('data.csv')

#Reading the file data.csv

df1=pd.read_csv('data.csv',index_col=0)

# df1

#Plotting the function from read value

df1.plot(x="Time",y="Amplitude")

plt.show()

 

# Creating histogram 

df1.hist(column="Amplitude")

# Show plot 

plt.show() 

# Standard deviation of the value

print("Standard Deviation")

print(df1.std(0))

# Mean of the values

print("Mean")

print(df1.mean(0))

Output

Standard Deviation

Time         0.293045

Amplitude    0.707107

dtype: float64

Mean

Time         5.000000e-01

Amplitude   -1.604953e-17

dtype: float64

Inference 

  • Generated  an electrical signal and exported it as a .csv file.

  • Read that .csv  file as an array and plotted it.

  • Computed the mean and standard deviation of the signal. Plotted its histogram with an appropriate bin size.

No comments:

Post a Comment

Signals & System Lect 15 | Stable & Unstable Systems | Solved examples

  ECT 204 SIGNALS AND SYSTEMS Topics covered  00:00 - Introduction to Stable & unstable Systems 01:08 - BIBO criteria 03:38 Problem No 1...