Reputation: 37
I am trying to plot an amplitude spectrum of a signal. Here is the code:
%My signal: y = 0.001*cos(0.005*pi*t+pi/4);
A = 0.001;
T = 400;
f = 0.0025;
pi = 3.14;
syms m
m=-1:1;
wm=(1/T)*(int((0.001*cos(0.005*pi*t + pi/4))*exp(-j*m*0.005*pi*t),t,0,T));
ww=double(wm);
Amp=abs(ww);
fi=angle(ww);
w=m*2*pi/T;
f=w/(2*pi);
figure('Name','Amplitude spectrum');
stem(f,Amp,'linewidth',2,'color','r'),grid on;
title('Amplitude spectrum'), xlabel('?[rad/s]'), ylabel('|wm|');
But it's plotted with a wrong amplitude. 5x10^-4 instead of 5x10^-3. Where did I do the mistake?
Upvotes: 1
Views: 79
Reputation: 104504
The magnitude of your plot is correct.
The magnitudes of the impulses located at the fundamental frequency come from the scale of the cosine wave and get divided by 2: 0.001 / 2 = 5e-4
. This is because the cos
function can be expressed using Euler's formula such that it is a combination of two complex exponentials that are both scaled by half.
Source: Wikipedia
As such, the Fourier Transform of a complex exponential at the desired frequency is a unit-length impulse (i.e. the magnitude is 1). The cosine wave can be expressed as two complex exponentials centered at the positive and negative versions of the fundamental frequency. We further scale by 1/2
due to Euler's formula and with the property of linearity for the Fourier Transform, the impulses additionally get scaled by 1/2
. You further have an additional scaling factor for your cosine wave, which scales the impulses yet again. The combination of scales: (1)(1/2)(0.001)
thus gives 5e-4
.
There's nothing wrong with that output. Also, your scale should be in Hertz, not rad/s. This is because of the formulation of your exponential has pi
in it.
I can understand why you'd want to use the symbolic toobox here, but I highly recommend using fft
instead. There's no need to get a slow symbolic calculator to compute the frequency representation of a signal when the fft
is a faster algorithm to do so. If you are doing this purely to verify what the theoretical magnitude response is for your signal, then that's fine but do not do this when calculating the frequency response in practice.
Upvotes: 3