[SciPy-user] Fourier series
Wed Oct 22 12:32:32 CDT 2008
Maybe this simple matlab code can help you to develop ideas further:
N = 1000;
%time covers only one period, excluding the last point, as that
% is the begining of the next period
dt = t(2) - t(1);
% set the sampling frequency to some reasonable value
% uncomment if you want only one cos function. This function is periodic,
% period T = 1 / f => fundamental frequency is
X = 1/length(t)*fft(x);
nonzero_index = find(abs(X) > 1e-3);
l = length(nonzero_index);
n = (nonzero_index(1:l/2)-1)/f
a = 2*real(X(nonzero_index))
b = -2*imag(X(nonzero_index))
As you know, cos() is a periodic function with only one non-zero coefficient
in the fourier sereis. In this trivial example,
you will get n =1 and a_n and b_n coefficients if you use the signal from
the first line, or n=1,2 for the signal from the second line.
It works even if you lower N down to 10 or some other number that is a
multiple of 5 (for this example).
Look at the comments too, to know when to end the period of the signal.
Granted, this is a simplified example, and you may want to figure out how
many sample points you need. Just to remind you,
from Parseval's theorem you know that the power of a periodic signal (which
has a finite power) is the sum of all these
coefficients squared. This means that for any signal that is F-transformable
you will find that you only need a finite number
of sample points.
This is of course far away from the real deal, I just thougt that this might
give you some ideas on which way to go. Or, maybe somebody else has already
done this, which I wouldn't be surprised, and you will get your answer
without much work.
. In thi
2008/10/22 Nils Wagner <firstname.lastname@example.org>
> Hi all,
> Is there a function in scipy to compute the Fourier
> a_0, a_1, b_1, a_2, b_2 of a periodic function f(t)=f(t+T)
> An example would be appreciated.
> SciPy-user mailing list
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the SciPy-user