Home > NoiseTools > nt_spect_plot.m

nt_spect_plot

PURPOSE ^

nt_spect_plot - plot power spectrum

SYNOPSIS ^

function varargout=nt_spect_plot(x,varargin)

DESCRIPTION ^

nt_spect_plot - plot power spectrum

  The power spectral densities of all columns (pages, etc.) are calculated
  and added.  The result is divided by the number of columns and either
  plotted or returned.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout=nt_spect_plot(x,varargin)
0002 %nt_spect_plot - plot power spectrum
0003 %
0004 %  The power spectral densities of all columns (pages, etc.) are calculated
0005 %  and added.  The result is divided by the number of columns and either
0006 %  plotted or returned.
0007 
0008 if numel(x)==0; error('!'); end
0009 
0010 N=numel(x);
0011 ncols=N/size(x,1);
0012 x=reshape(x,size(x,1),ncols);
0013 
0014 [pxx,f]=pwelch(x(:,1),varargin{:});
0015 
0016 for k=1:ncols
0017     [a,b]=pwelch(x(:,k),varargin{:});
0018     pxx=pxx+a;
0019 end
0020 pxx=pxx/ncols;
0021 
0022 
0023 if nargout == 0;
0024     plot(f,abs(pxx).^0.5);
0025     set(gca,'yscale','log');
0026     xlim([f(1) f(end)]);
0027     xlabel('Hz'); ylabel('Hz^{-0.5}');
0028     varargout={};
0029 else
0030     varargout={pxx,f};
0031 end

Generated on Mon 10-Nov-2014 14:40:42 by m2html © 2005