To plot half the spectrum in Hz for the given data x
, we first need to obtain the frequency axis for the spectrum. Since the data is sampled at 1 MHz, the frequency resolution of the spectrum will be 1/N
, where N
is the length of the data.
To obtain the frequency axis, we can use the fft
function in MATLAB, along with the Fs
parameter set to 1 MHz. We can then take the first half of the resulting frequency vector and plot it against the magnitude of the one-sided spectrum.
Here's the code to accomplish this:
main.m307 chars19 lines
This will plot the magnitude of the one-sided spectrum up to the Nyquist frequency (500 kHz), which is half the sampling frequency. Note that the data is not preprocessed in any way (e.g., windowing) so the resulting spectrum may have spectral leakage and other artifacts.
gistlibby LogSnag