Can i plot spectrum of a signal in Matlab
2 次查看(过去 30 天)
显示 更早的评论
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
0 个评论
采纳的回答
Wayne King
2011-10-1
Fs = 1000;
t = 0:1/Fs:1-(1/Fs);
x = 14*cos(200*pi*t-pi/3);
xdft = (1/length(x))*fft(x);
freq = -500:(Fs/length(x)):500-(Fs/length(x));
plot(freq,abs(fftshift(xdft)));
2 个评论
Wayne King
2011-10-1
Your frequency above is actually 100 Hz (2*100*pi*t). You have not given the sampling rate, so I just assumed 1000 Hz here.
Amna
2023-10-12
Can anyone plz explain what will be the spectrum of j*cos(2*pi*10*t) , j*exp(-j*2*pi*10*t),
-j*exp(-j*2*pi*10*t) and -j*cos(2*pi*10*t) ?? please plot them i'm not asking for magnitude plot show me actual plots please help.
更多回答(6 个)
moonman
2011-10-1
2 个评论
Wayne King
2011-10-1
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
2011-10-1
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
2011-10-1
1 个评论
Wayne King
2011-10-1
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
2011-10-1
2 个评论
Wayne King
2011-10-1
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
2011-10-1
as far as your multiplication problem, use the .* operator
x = cos(1000*pi*t+pi/3).*(sin(500*pi*t+pi/4));
Wayne King
2011-10-1
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)));
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Spectral Measurements 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!