Professional Documents
Culture Documents
Fourier Coeffs From FFT
Fourier Coeffs From FFT
Fourier Coeffs From FFT
x t
Let N
Xi e ji T t
2
(1)
xn
Xi e jin N
Xi e jin N
M
1
N 1
l M 1
Xl
Ne
(2)
jln 2
N
2
Xie jin N
i 0
defining l
i N
Xi N . Then we have
xn
2
Xi e jin N
i 0
(3)
M = 8; % example
N = 2*M+1;
T = 1; % example; signal should be periodic with this T
tpts = (0:(N-1))/N*T;
% samples = evalx(tpts); % get the time samples
samples = cos(2*pi/T*tpts) + 3*sin(3*2*pi/T*tpts); % example
tmp = fft(samples)/N;
% tmp(1) is X_0; tmp(2:M+1) are X_1 to X_M;
% tmp(N:-1:M+2) are X_{-1} to X{-M}
% now reorder tmp
% for loops are inefficient
%for j = 1:M
%
Xarray(j) = tmp(M+1+j);
2
%
Xarray(j+M+1) = tmp(j+1);
%end
Xarray(1:M) = tmp(M+2:N);
Xarray((M+2):N) = tmp(2:(M+1));
Xarray(M+1) = tmp(1);
% now Xarray(1:M) are X_{-M} to X{-1};
% Xarray(M+1:N) are X(0) to X(N)
stem(-M:M, abs(Xarray));
oof = sprintf(Fourier Coeffiecient index (multiples of f0=%g), 1/T);
xlabel(oof);
ylabel(magnitude of Fourier Coefficient);
lim ST f
ST f
1
T
T
0
s t e
j2 f t
2
dt
Note: setting s t to a deterministic periodic signal will result in delta functions for the
above at its harmonics. Also, the above might not hold for white noise (infinite power)
waveforms.
We assume that x t is zero outside the interval 0
T , and also, for simplicity, that
it is continuous, so its values at t 0 and t T are exactly zero. If x t is bounded
then it has finite energy, so its Fourier Transform X f exists.
Now, we form the periodic function
xT t
x t mT
or X n f0 T Xn
Xi can be obtained using the DFT.
The above may work well enough for deterministic signals, but it does not work
well at all for estimating the PSD of random signals - see the code in the appendix.
There is a considerable body of literature on this, see Numerical Recipes for a good
overview.
3
Matlab has convenient functions for PSD estimation using the Welch periodogram
- see the attached file PSDs.m. There are some issues with it that are not clear particularly when interpolation is used. See the notes inside PSD.m.
Here is some code to calculate the FT of a time-limited sequence. The time sequence
is not periodic (but could be made so by extending the boundaries). We ignore the lack
of periodicity of the end points, they probably wont make much difference for long
sequences.
Note that the code as shown below is not very useful for random inputs. For that,
one should use the Welch periodogram - see Numerical Recipes and Matlabs psd and
pwelch functions.
% we assume that time samples of length N = 2*M+1 are in samples
% we assume, M, N, T samples are set up
% example 1 - deterministic periodic - this wont converge because
% it leads to a delta function
T = 1; % this should exactly divide Twindow
Twindow = 200000;
M = 215; N = 2*M+1;
tpts = (0:(N-1))/N*Twindow;
% samples = cos(2*pi/T*tpts).2;
% example 2 - finite-BW coloured noise. How to generate finite BW
% coloured noise requires some justification - this has been already
% done in a separate document previously. Here we hack it.
NoiseBW = 1e3; % Hz
Tsamp = 1/NoiseBW;
Twindow = 1000; % sec
Nsamp = round(Twindow/Tsamp);
Tsamp = Twindow/Nsamp;
tsamps = (0:(Nsamp-1))/Nsamp*Twindow;
whitenoisesamps = randn(Nsamp,1);
M = 219; N = 2*M+1;
tpts = (0:(N-1))/N*Twindow;
samples = interp1(tsamps,whitenoisesamps,tpts,linear,0);