- #1
magnifik
- 360
- 0
i am trying to plot the amplitude spectrum for a function which has the following properties:
f(t) = 1, 0 < t < 10
f(t) = 0, 10 < t < 20
the period of the function is 20
i found the Fourier coefficients to be Fn = -(1/n*pi)(cos(n*pi) - 1)
i tried to use the following code to plot the amplitude spectrum in MATLAB:
% up to the 10th harmonic
n = 10;
for n = -N:2:N,
cn = (-cos(n*pi)+1)/(n*pi); % Fourier coefficient
stem(n, abs(cn))
end
however, this plots a straight line with a circle at 10. I'm not sure how to fix this as i am a MATLAB newbie
f(t) = 1, 0 < t < 10
f(t) = 0, 10 < t < 20
the period of the function is 20
i found the Fourier coefficients to be Fn = -(1/n*pi)(cos(n*pi) - 1)
i tried to use the following code to plot the amplitude spectrum in MATLAB:
% up to the 10th harmonic
n = 10;
for n = -N:2:N,
cn = (-cos(n*pi)+1)/(n*pi); % Fourier coefficient
stem(n, abs(cn))
end
however, this plots a straight line with a circle at 10. I'm not sure how to fix this as i am a MATLAB newbie