Plotting energy density spectrum as a function of angular frequency
Mostrar comentarios más antiguos
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.
Respuestas (1)
Wayne King
el 13 de Abr. de 2013
Editada: Wayne King
el 13 de Abr. de 2013
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)))
Categorías
Más información sobre Spectral Measurements en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!