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.

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 if ndims(x)>2;
0008     [m,n,o]=size(x);
0009     x=reshape(x,[m,n*o]);
0010     [pxx,f]=nt_spect_plot2(x,varargin{:});
0011     pxx=reshape(pxx,[size(pxx,1),n,o]);
0012     pxx=mean(pxx,3);
0013 else
0014 
0015 % ndims(x)==2
0016 
0017     [m,n]=size(x);
0018     [a,f]=pwelch(x(:,1),varargin{:});
0019     pxx=zeros(size(a,1),n);
0020     for k=1:n
0021         [a,f]=pwelch(x(:,k),varargin{:});
0022         pxx(:,k)=a;
0023     end
0024 end
0025 
0026 if nargout == 0; % plot
0027     
0028     % hack to get nice frequency axis
0029     [X,f]=nt_spect_plot(x(:,1,1), varargin{:}); % to get scaling factor
0030     scaling_factor=size(X,1)/max(f);
0031     nt_spect_plot(x(:,1,1), varargin{:}); % to get x axis labels
0032     xtick=get(gca,'xtick'); xticklabel=get(gca,'xticklabel');  
0033     if 0
0034         pxx=nt_normcol(pxx);
0035     else
0036         pxx=bsxfun(@times,pxx,1./max(pxx));
0037     end
0038     imagesc(pxx'.^0.25);
0039     set(gca,'xtick',xtick*scaling_factor,'xticklabel',xticklabel);
0040     xlabel('Hz'); ylabel('channel');
0041     
0042 else
0043     varargout={pxx,f};
0044 end

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