Home > NoiseTools > nt_dss0.m

# nt_dss0

## PURPOSE

[todss,pwr1,pwr2]=nt_dss0(c0,c1,keep1,keep2) - dss from covariance

## SYNOPSIS

function [todss,pwr0,pwr1]=nt_dss0(c0,c1,keep1,keep2)

## DESCRIPTION

    [todss,pwr1,pwr2]=nt_dss0(c0,c1,keep1,keep2) - dss from covariance

     todss: matrix to convert data to normalized DSS components
     pwr0: power per component (baseline)
     pwr1: power per component (biased)

     c0: baseline covariance
     c1: biased covariance
     keep1: number of PCs to retain (default: all)
     keep2: ignore PCs smaller than keep2 (default: 10.^-9)

     NoiseTools

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_greetings nt_greetings - display message the first time the toolbox is used
- nt_pcarot [topcs,eigenvalues]=pcarot(cov,nkeep,threshold,N) - PCA matrix from covariance

This function is called by:

- nt_bias_cluster [c0,c1,A,todss,pwr0,pwr1]=nt_bias_cluster(x,dsr,flags) - cluster covariance
- nt_cca_aad [D,E,R]=nt_cca_match_aad(xA,xB,y,ssize) - calculate metrics for match-mismatch task
- nt_cca_mm [D,E,R]=nt_cca_match_mm3(x,y,ssize) - calculate metrics for match-mismatch task
- nt_cluster_jd [IDX,todss,SCORE,COVS]=nt_cluster_jd(x,dsr,smooth,flags,init,verbose) - cluster with joint diagonalization
- nt_dprime [d,e]=nt_dprime(x,y,jd_flag) - calculate d' (discriminability) of two distributions
- nt_dprime_old [d,err_rate,perm]=nt_dprime(x,y,jd_flag) - calculate d' (discriminability) of two distributions
- nt_dss1 [todss,pwr0,pwr1]=nt_dss1(x,w,keep1,keep2) - evoked-biased DSS denoising
- nt_narrowband_scan A=nt_narrowband_scan(x,freqs,sr,Q,plotflag) - scan for narrowband components using DSS
- nt_qca0 [tosquares,quads,D]=nt_qca0(x,npcs,nsmooth,nquads) - maximize induced power using quadratic component analysis
- nt_qca02 [tosquare,quad,tosquare2,quad2,D]=nt_qca02(x,npcs,nsmooth) - maximize induced power using quadratic component analysis
- nt_split_jd [idx,score_vector,todss]=nt_split_dss(x,thresh,depth) - segmentation based on joint diagonalization
- nt_zapline [y,yy]=nt_zapline(x,fline,nremove,p,plotflag) - remove power line artifact

## SOURCE CODE

    0001 function [todss,pwr0,pwr1]=nt_dss0(c0,c1,keep1,keep2)
    0002 %[todss,pwr1,pwr2]=nt_dss0(c0,c1,keep1,keep2) - dss from covariance
    0003 %
    0004 % todss: matrix to convert data to normalized DSS components
    0005 % pwr0: power per component (baseline)
    0006 % pwr1: power per component (biased)
    0007 %
    0008 % c0: baseline covariance
    0009 % c1: biased covariance
    0010 % keep1: number of PCs to retain (default: all)
    0011 % keep2: ignore PCs smaller than keep2 (default: 10.^-9)
    0012 %
    0013 % NoiseTools
    0014 nt_greetings;
    0015
    0016 if nargin<4||isempty(keep2); keep2=10.^-9; end
    0017 if nargin<3; keep1=[]; end
    0018 if nargin<2; error('needs at least two arguments'); end
    0019
    0020 if size(c0)~=size(c1); error('C0 and C1 should have same size'); end
    0021 if size(c0,1)~=size(c0,2); error('C0 should be square'); end
    0022
    0023 if any(find(isnan(c0)))
    0024     error('NaN in c0');
    0025 end
    0026 if any(find(isnan(c1)))
    0027     error('NaN in c1');
    0028 end
    0029 if any(find(isinf(c0)))
    0030     error('INF in c0');
    0031 end
    0032 if any(find(isinf(c1)))
    0033     error('INF in c1');
    0034 end
    0035 % PCA and whitening matrix from the unbiased covariance
    0036 [topcs1,evs1]=nt_pcarot(c0,keep1,keep2);
    0037 evs1=abs(evs1);
    0038
    0039 % truncate PCA series if needed
    0040 if ~isempty(keep1); topcs1=topcs1(:,1:keep1); evs1=evs1(1:keep1); end
    0041 if ~isempty(keep2); idx=find(evs1/max(evs1)>keep2); topcs1=topcs1(:,idx); evs1=evs1(idx);  end
    0042
    0043 % apply PCA and whitening to the biased covariance
    0044 N=diag(sqrt(1./(evs1)));
    0045 c2=N'*topcs1'*c1*topcs1*N;
    0046
    0047 % matrix to convert PCA-whitened data to DSS
    0048 [topcs2,evs2]=nt_pcarot(c2,keep1,keep2);
    0049
    0050 % DSS matrix (raw data to normalized DSS)
    0051 todss=topcs1*N*topcs2;
    0052 N2=diag(todss'*c0*todss);
    0053 todss=todss*diag(1./sqrt(N2)); % adjust so that components are normalized
    0054
    0055
    0056 % power per DSS component
    0057 pwr0=sqrt(sum((c0'*todss).^2)); % unbiased
    0058 pwr1=sqrt(sum((c1'*todss).^2)); % biased
    0059
    0060
    0061