I am still finding my way in Python so this question may be very basic: I am trying to generate some cosine waves in python and then do a Fourier transform on them. I am wrote the following code:
from pylab import *
from numpy import *
x = linspace(-5,5,100)
t = linspace(0,2000,2001)
w1=cos(2*pi*3*t/2001)
w2=cos(2*pi*10*t/2001)
fourier=0
long(fourier)
Trace = w1+w2
for i in range(1,125,1):
fourier[i] = sum(cos(2*pi*i*t/2001)*Trace)
print fourier
f=linspace(1,125,125)
plot(f,fourier)
show()
so instead of calculating the values frequency by frequency I want to make a loop that takes each frequency from 1 to 125 and store the outputs in one list so that I can plot them.
Python does not like this and gives a message saying:
fourier[i] = sum(cos(2*pi*i*t/2001)*Trace)
TypeError: 'int' object does not support item assignment
Any idea why?
range(1,126)to match the the dimensions offfor plotting