Assume you have a matrix X
with size MxN
where M
is the number of frequency points and N
the number of spectra to average. You can plot the average spectra in Matlab using the following code:
main.m158 chars10 lines
The mean
function is used to compute the average spectra across the second dimension of the matrix X
, which corresponds to the multiple spectra. The resulting vector Y
has size Mx1
and contains the average spectra.
Then, we plot the vector Y
using the plot
function. The title
, xlabel
, and ylabel
functions are used to add labels to the plot.
You can also specify the frequency range of the spectra by providing a vector of M
frequency points. For example:
main.m188 chars10 lines
Here, we use the linspace
function to create a vector of M
linearly-spaced frequency points between 0 and 1000 Hz. We then plot the spectra Y
against the frequency vector f
, and add labels to the plot as before.
gistlibby LogSnag