The requirement is to generate a sine wave with frequencies ranging from 1 Hz to 10 Hz.
The conditions are
- The amplitude is one volt for all sine wave frequencies
- The 1 Hz signal must be sampled into 100 wave points.
- Similarly 2 Hz signal must be sampled into 200 samples per second and 3 Hz signal must be sampled into 300 samples per second and 4 Hz signal to 400 samples/sec and so on up to 10 Hz.
4.All these values must be written into Csv file and also converted to excel file.
Thus excel has 10 columns named 1 Hz to 10 Hz. and each column have values accordingly.
1st column has values of 100 samples 2nd column has values of 200 samples and so on up to 10th column.
can anyone help to solve this. I coded for 1 Hz to 10 Hz with same sampling ratio and with all columns with same number of rows.
import numpy as np
import pandas as pd
def get_values_for_frequency(freq):
# sampling information
Fs = 100 #sample rate- no of samples per second
T = 1/Fs #sampling period %sample per second
t = 1 #seconds of sampling
N = Fs*t #total points in signal
# signal information
omega = 2*np.pi*freq # angular frequency for sine waves
t_vec = np.arange(N)*T # time
y = np.sin(omega*t_vec) #sine wave generation
return y
#columns are created for sine wave frequencies
df = pd.DataFrame(columns =['1Hz','2Hz', '3Hz', '4Hz', '5Hz', '6Hz', '7Hz'])
df['1Hz']=pd.Series(get_values_for_frequency(1))
df['2Hz']=pd.Series(get_values_for_frequency(2))
df['3Hz']=pd.Series(get_values_for_frequency(3))
df['4Hz']=pd.Series(get_values_for_frequency(4))
df['5Hz']=pd.Series(get_values_for_frequency(5))
df['6Hz']=pd.Series(get_values_for_frequency(6))
df['7Hz']=pd.Series(get_values_for_frequency(7))
df = df.round(decimals = 3) #Round a table values in DataFrame to3 decimal places
print("created table datatype\n",df.dtypes) #viewing the datatype of table
df.to_csv("float_csvfile.csv",index=False) #the raw values are written into the csv file.
I tired to give two inputs to the function as def
get_values_for_frequency(freq,samplepoints):
and called the function with
df = pd.DataFrame(columns =['1Hz','2Hz', '3Hz', '4Hz', '5Hz', '6Hz', '7Hz'])
df['1Hz']=pd.Series(get_values_for_frequency(1,100))
df['2Hz']=pd.Series(get_values_for_frequency(2,200))
df['3Hz']=pd.Series(get_values_for_frequency(3,300))
df['4Hz']=pd.Series(get_values_for_frequency(4,400))
df['5Hz']=pd.Series(get_values_for_frequency(5,500))
df['6Hz']=pd.Series(get_values_for_frequency(6,600))
df['7Hz']=pd.Series(get_values_for_frequency(7,700))
yet I receive the same column length for each column. Can anyone help me to solve for different column lengths. Thanks