Sometimes I need a signal of different frequencies for testing, so I wrote a simple Python code to produce compound sinusoidal signal by adding several cosine waves of different frequencies, amplitudes, and phases.
The code is listed as the follows. (download)
from scipy import *
from pylab import *
data_size = 10 # number of sinusoidal waves
A = rand(data_size)
theta = rand(data_size)
f = [i for i in range(1,data_size+1)]
t = linspace(0,10,1024)
y = [0.0 for i in range(len(t))]
for i in range(data_size):
y += A[i]*cos(2*pi*f[i]*t + theta[i])
plot(t,y)
show()
No comments:
Post a Comment