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.
 
 See pwelch for syntax.

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 % See pwelch for syntax.
0009 
0010 if numel(x)==0; error('!'); end
0011 
0012 N=numel(x);
0013 ncols=N/size(x,1);
0014 x=reshape(x,size(x,1),ncols);
0015 
0016 [pxx,f]=pwelch(x(:,1),varargin{:});
0017 
0018 for k=1:ncols
0019     [a,b]=pwelch(x(:,k),varargin{:});
0020     pxx=pxx+a;
0021 end
0022 pxx=pxx/ncols;
0023 
0024 
0025 if nargout == 0;
0026     plot(f,abs(pxx));
0027     set(gca,'yscale','log');
0028     xlim([f(1) f(end)]);
0029     xlabel('Hz'); ylabel('power density', 'interpreter', 'tex');
0030     varargout={};
0031 else
0032     varargout={pxx,f};
0033 end

Generated on Sat 29-Apr-2023 17:15:46 by m2html © 2005