If you just want a plot of the power spectral density, you can run
periodogram(x)
and you get a plot of the power spectral density (in dB) over normalized frequency. If you want the density over actual frequency (in Hz), you need to specify the sampling rate of your data. The syntax is
periodogram(x, [], [], Fs)
where Fs
is the sampling frequency (in Hz). You then get a plot with a horizontal axis from 0 to Fs / 2
(the Nyquist frequency).
The two parameters given as []
can be used to specify the window length for the periodogram method and the number of data points used for the underlying FFT. You can use these, especially the window length, in order to regulate the trade-off between frequency resolution of the spectrum and the precision to which the power spectral density is estimated.
With none of these syntaxes does periodogram
return any output. You can however use the syntax
[P, f] = periodogram(x, [], [], fs);
which returns the estimate of the power spectral density in P
and the corresponding frequencies (in Hz) in f
. From this you can generate a plot similar to the one generated by periodogram
without outputs by using
semilogy(f, P)
i.e. plotting P
over f
with a logarithmic scale for the vertical axis.