Home > NoiseTools > nt_narrowband_scan.m

nt_narrowband_scan

PURPOSE ^

A=nt_narrowband_scan(x,freqs,sr,Q,plotflag) - scan for narrowband components using DSS

SYNOPSIS ^

function A=nt_narrowband_scan(x,freqs,sr,Q,plotflag,yulewalk_order)

DESCRIPTION ^

A=nt_narrowband_scan(x,freqs,sr,Q,plotflag) - scan for narrowband components using DSS

  A: cell array of DSS matrices

  x: data (time*channels or time*channels*trials)
  freqs: Hz, array of bias frequencies
  sr: Hz, sampling rate
  Q: quality factors of scanning filter (default: [8 4])
  plotflag: if true plot (default: 1)
  yulewalk_order: if present apply inverse filtering with this order

 If no output arguments, plots spectra of first DSS components for each
 bias

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function A=nt_narrowband_scan(x,freqs,sr,Q,plotflag,yulewalk_order)
0002 %A=nt_narrowband_scan(x,freqs,sr,Q,plotflag) - scan for narrowband components using DSS
0003 %
0004 %  A: cell array of DSS matrices
0005 %
0006 %  x: data (time*channels or time*channels*trials)
0007 %  freqs: Hz, array of bias frequencies
0008 %  sr: Hz, sampling rate
0009 %  Q: quality factors of scanning filter (default: [8 4])
0010 %  plotflag: if true plot (default: 1)
0011 %  yulewalk_order: if present apply inverse filtering with this order
0012 %
0013 % If no output arguments, plots spectra of first DSS components for each
0014 % bias
0015 %
0016 
0017 if nargin<6; yulewalk_order=[]; end
0018 if nargin<5; plotflag=[]; end
0019 if nargin<4||isempty(Q); Q=[8 4]; end
0020 if nargin<3; error('!'); end
0021 
0022 freqs=freqs(:);
0023 
0024 if ~isempty(yulewalk_order)
0025     error('use nt_yulewalk_whiten() to whiten data before this function'); 
0026 end
0027 
0028 
0029 current_figure=get(0,'CurrentFigure');
0030 A={};
0031 for iFreqs=1:numel(freqs)
0032     freq=freqs(iFreqs);
0033     [b,a]=nt_filter_peak(freq/(sr/2),Q(1));
0034     [c0,c1]=nt_bias_filter(x,b,a);
0035     if numel(Q)==2
0036         [b,a]=nt_filter_peak(freq/(sr/2),Q(2));
0037         [~,c0]=nt_bias_filter(x,b,a);
0038     end
0039     [todss,pwr0,pwr1]=nt_dss0(c0,c1);
0040     
0041     if 1; figure(100); clf; plot(pwr1./pwr0,'.-'); title([num2str(freq), 'Hz bias']); ylabel('score');  drawnow;end
0042     
0043     A{iFreqs}=todss;
0044 end
0045 
0046 
0047 if ~nargout || ~isempty(plotflag)
0048     if isempty(current_figure);
0049         figure; 
0050     else
0051         figure(current_figure);
0052     end
0053     AA=zeros(size(x,2),numel(freqs));
0054     for iFreqs=1:numel(freqs)
0055         AA(:,iFreqs)=A{iFreqs}(:,1);
0056     end
0057     x=nt_mmat(x,AA);
0058     nfft=2.^nextpow2(size(x,1)+1)/2;
0059     MAX_NFFT=1024;  
0060     nfft=min(nfft,MAX_NFFT);
0061     nt_spect_plot2(nt_normcol(x),nfft,[],[],sr);
0062     K=round(numel(freqs)/6);
0063     set(gca,'ytick',1:K:numel(freqs), 'yticklabel',num2str(freqs(1:K:end), '%.3g')); ylabel('Hz');
0064     set(gca,'xgrid','on','xminortick','on');
0065     drawnow;
0066     clear A;
0067 end
0068

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