In this lecture we showed that the Fourier coefficients appear in the solution to a least squares approximation with trigonometric polynomials. A remarkable property is that the Fourier coefficients are independent of the degree of the trigonometric polynomial.
Below are the MATLAB scripts used to produce illustrations of the FFT transform.
% File : exsig.m
% script to understand the use of the fft transform
% first we define a signal
%
dt = 1/100; % sampling rate
et = 4; % end of the interval
t = 0:dt:et; % sampling range
y = 3*sin(4*2*pi*t) + 5*sin(2*2*pi*t); % sample signal
%
% the plot shows the amplitude versus time
%
figure
subplot(2,1,1);
plot(t,y); grid on
axis([0 et -8 8]);
xlabel('Time (s)');
ylabel('Amplitude');
%
% we compute the Fourier Transform of the signal
% and the amplitude spectrum; the use of n is important
%
Y = fft(y);
n = size(y,2)/2;
amp_spec = abs(Y)/n;
%
% the plot shows the amplitude spectrum
% the smaller we take dt, the more accurate we see "1" in amp_spec
%
subplot(2,1,2);
freq = (0:79)/(2*n*dt);
plot(freq,amp_spec(1:80)); grid on
xlabel('Frequency (Hz)');
ylabel('Amplitude');
The second slide was produced with the following
% File : exsigp.m
% script to demonstrate the use of ftt to filter signals
% we assume that exsig has been executed
%
noise = randn(1,size(y,2)); % random noise
ey = y + noise; % samples with noise
%
% the plot shows the amplitude versus time
%
figure
subplot(2,1,1);
plot(t,ey); grid on
axis([0 et -8 8]);
xlabel('Time');
ylabel('Amplitude');
%
% we compute the Fourier Transform of the signal
% and the amplitude spectrum; the use of n is important
%
eY = fft(ey);
n = size(ey,2)/2;
amp_spec = abs(eY)/n;
%
% the plot shows the amplitude spectrum
% the smaller we take dt, the more accurate we see "1" in amp_spec
%
subplot(2,1,2);
freq = (0:79)/(2*n*dt);
plot(freq,amp_spec(1:80)); grid on
xlabel('Frequency');
ylabel('Amplitude');
Finally, the script that showed four plots is
% File : exsigc.m
% script to demonstrate the use of ftt to filter signals
% we assume that exsig and exsigp have been executed
%
% first we plot the original signal
%
figure
subplot(2,2,1);
plot(t,y); grid on
axis([0 et -8 8]);
xlabel('Time');
ylabel('Amplitude');
%
%
% second we plot the noisy signal
%
subplot(2,2,2);
plot(t,ey); grid on
axis([0 et -8 8]);
xlabel('Time');
ylabel('Amplitude');
%
% the plot shows the amplitude spectrum
% the smaller we take dt, the more accurate we see "1" in amp_spec
%
subplot(2,2,3);
freq = (0:79)/(2*n*dt);
plot(freq,amp_spec(1:80)); grid on
xlabel('Frequency');
ylabel('Amplitude');
%
% the last plot is the corrected signal
%
subplot(2,2,4);
fY = fix(eY/100)*100;
ifY = ifft(fY);
cy = real(ifY);
plot(t,cy); grid on
axis([0 et -8 8]);
xlabel('Time');
ylabel('Amplitude');