Can i plot spectrum of a signal in Matlab
조회 수: 7 (최근 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!