The problem: My class was told to write a program which uses the built-in Matlab commands to transform the function
y = 0.25*cos(2*pi*t*f0) + 0.5*sin(2*pi*3*t*f0) - 0.25*cos(2*pi*t*10*f0)
to a frequency function (f0 = 100). We then are supposed to filter out any frequencies above 200 and below 500, take the inverse transform, and plot the resulting graph against the approximation y = 0.5*sin(2*pi*3*t*f0).
My code:
clear;
delta_t = 0.000025;
N = 1024;
t = 0:delta_t:N*delta_t;
T_func = 0.25*cos(2*pi*t*100) + 0.5*sin(2*pi*3*t*100) - 0.25*cos(2*pi*t*10*100);
Transform = fft(T_func);
Amp = sqrt(Transform.*conj(Transform));
freq = 0:700/N:700;
figure(1);
subplot(2,1,1);
plot(freq, Amp);
cut = 200/(700/N);
Transform(1:cut) = 0;
Transform(N+1-cut:N+2) = 0;
New_Amp = sqrt(Transform.*conj(Transform));
subplot(2,1,2);
plot(freq, New_Amp);
Inv_Trans = ifft(Transform);
Inverse_Amp = sqrt(Inv_Trans.*conj(Inv_Trans));
Approximation = 0.5*sin(2*pi*3*t*100);
figure(2);
plot(t, Approximation, t, Inverse_Amp, 'r');
What's happening: The first transform and filtering are going perfectly, and I come up with these plots: http://tinypic.com/r/2u90th2/6. These look to me to be correct. However, when I take the inverse transform, I come up with this plot: http://tinypic.com/r/25utsa9/6. This looks to be very incorrect. Since I'm using built-in programs, I can't figure out where the error could possibly be. Does anybody have any idea? Thank you!