Plotting energy density spectrum as a function of angular frequency
조회 수: 15 (최근 30일)
이전 댓글 표시
I have a variable in an external file with a fixed length. I need some help on how to plot the energy density spectra as a function of angular frequency on matlab. I know that I need to use fft command, but I'm not sure how to do it. Hope someone could help me out with this as I'm quite new at matlab.
댓글 수: 0
답변 (1개)
Wayne King
2013년 4월 13일
편집: Wayne King
2013년 4월 13일
If you just want it in terms of angular frequency (radians/sample) and not (radians/second), the frequency bins are spaced at increments of (2*pi)/N where N is the length of the signal.
n = 0:159;
x = cos(pi/4*n)+randn(size(n));
xdft = fft(x);
omega = 0:(2*pi)/length(x):(2*pi)-(2*pi)/length(x);
plot(omega,abs(xdft).^2);
If the signal is real-valued you only need the first N/2+1 DFT bins (assuming N even)
plot(omega(1:length(x)/2+1),abs(xdft(1:length(x)/2+1)))
If you want radians/second, you need to multiply the increment by the sampling frequency, Fs
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
xdft = fft(x);
Fs = 1000;
omega = 0:(2*pi*Fs)/length(x):(2*pi*Fs)-(2*pi*Fs)/length(x);
plot(omega(1:length(x)/2+1),abs(xdft(1:length(x)/2+1)))
댓글 수: 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!