Can i plot spectrum of a signal in Matlab
Show older comments
I want to plot spectrum diagram which gives the frequency content of a signal x(t) for example if i draw spectrum of x(t) = 14 cos(200*pi*t -pi/3)
by hand it will be two arrows at -100 and +100 with values 7e^(jpi/3) and 7e^(-jpi/3)
Can some software or matlab can do this for me
Accepted Answer
More Answers (6)
moonman
on 1 Oct 2011
0 votes
2 Comments
Wayne King
on 1 Oct 2011
Yes, 200 is right, but I would sample at least a bit more than that, 200 would put the 100 Hz component right at the Nyquist. I would avoid that.
Not sure exactly what you're asking in the 2nd, you should sample based on the bandwidth of your signal, which is 2000 Hz here (you have a component at -1000 and 1000) so 1000-(-1000)=2000. You have to sample at least at the bandwidth (2 kHz).
Wayne King
on 1 Oct 2011
sorry I misread above-- your bandwidth is 1 kHz (500-(-500))=1000. I misread the frequency as (2*1000*pi) instead of (1000*pi). you have to sample at least at the bandwidth. (1 kHz).
moonman
on 1 Oct 2011
0 votes
1 Comment
Wayne King
on 1 Oct 2011
Oh sorry! yes, for some reason, I read 2*pi*1000 in your first post, you are right. it's 500 Hz so it has to be sampled at a minimum of 1 kHz.
moonman
on 1 Oct 2011
0 votes
2 Comments
moonman
on 1 Oct 2011
Wayne King
on 1 Oct 2011
The factor your refer to is the phase, you can get that by plotting the angle() (but that tends to be messy unless you unwrap it which is another matter), or you can query it directly. For example, xdft(101) corresponds to the DFT bin for 100 Hz in the example I gave you. Because the bins are spaced at Fs/length(x) with the first bin corresponding to zero frequency, DC. If you query
angle(xdft(101))
you get -1.0472, which is -pi/3
Wayne King
on 1 Oct 2011
as far as your multiplication problem, use the .* operator
x = cos(1000*pi*t+pi/3).*(sin(500*pi*t+pi/4));
Wayne King
on 1 Oct 2011
That is because you changed the sampling frequency, in your frequency vector
freq = -2000:(Fs/length(x)):2000-(Fs/length(x));
Your frequency vector is set up for a 4000 Hz sampling rate. However you left
Fs = 1000;
So your sizes are not correct.
Also you are creating a modulated signal above, so you have to think about what the spectrum of that signal is. That is different than just adding components.
Fs = 4000;
t = 0:1/Fs:1-(1/Fs);
x = cos(1000*pi*t+pi/3).*(sin(500*pi*t+pi/4));
xdft = (1/length(x))*fft(x);
freq = -2000:(Fs/length(x)):2000-(Fs/length(x));
plot(freq,abs(fftshift(xdft)));
moonman
on 1 Oct 2011
0 votes
Categories
Find more on Spectral Measurements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!