Home > NoiseTools > nt_spect_plot2.m

nt_spect_plot2

PURPOSE ^

nt_spect_plot2 - plot power spectrum

SYNOPSIS ^

function varargout=nt_spect_plot2(x,varargin)

DESCRIPTION ^

nt_spect_plot2 - plot power spectrum

  The power spectral densities of all columns are calculated.  
  The result is either plotted as an image or returned.
 
  See nt_spect_plot, and pwelch for syntax.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function varargout=nt_spect_plot2(x,varargin)
0002 %nt_spect_plot2 - plot power spectrum
0003 %
0004 %  The power spectral densities of all columns are calculated.
0005 %  The result is either plotted as an image or returned.
0006 %
0007 %  See nt_spect_plot, and pwelch for syntax.
0008 
0009 if ndims(x)>2;
0010     [m,n,o]=size(x);
0011     x=reshape(x,[m,n*o]);
0012     [pxx,f]=nt_spect_plot2(x,varargin{:});
0013     pxx=reshape(pxx,[size(pxx,1),n,o]);
0014     pxx=mean(pxx,3);
0015 else
0016 
0017 % ndims(x)==2
0018 
0019     [m,n]=size(x);
0020     [a,f]=pwelch(x(:,1),varargin{:});
0021     pxx=zeros(size(a,1),n);
0022     for k=1:n
0023         [a,f]=pwelch(x(:,k),varargin{:});
0024         pxx(:,k)=a;
0025     end
0026 end
0027 
0028 if nargout == 0; % plot
0029     
0030     % hack to get nice frequency axis
0031     [X,f]=nt_spect_plot(x(:,1,1), varargin{:}); % to get scaling factor
0032     scaling_factor=size(X,1)/max(f);
0033     nt_spect_plot(x(:,1,1), varargin{:}); % to get x axis labels
0034     xtick=get(gca,'xtick'); xticklabel=get(gca,'xticklabel');  
0035     if 0
0036         pxx=nt_normcol(pxx);
0037     else
0038         pxx=bsxfun(@times,pxx,1./max(pxx));
0039     end
0040     nt_imagescc(pxx'.^0.25);
0041     set(gca,'xtick',xtick*scaling_factor,'xticklabel',xticklabel);
0042     xlabel('Hz'); ylabel('channel');
0043     
0044 else
0045     varargout={pxx,f};
0046 end

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