Home > NoiseTools > nt_fixsign.m

# nt_fixsign

## PURPOSE

y=nt_fixsign(x) - flip signs to maximize inter-component correlation

## SYNOPSIS

function x=nt_fixsign(x)

## DESCRIPTION

    y=nt_fixsign(x) - flip signs to maximize inter-component correlation

## CROSS-REFERENCE INFORMATION

This function calls:

- nt_fixsign y=nt_fixsign(x) - flip signs to maximize inter-component correlation
- nt_fold y=fold(x,epochsize) - fold 2D to 3D
- nt_pca [z,idx]=nt_pca(x,shifts,nkeep,threshold,w) - time-shift pca
- nt_unfold y=nt_fold(x) - unfold 3D to 2D

This function is called by:

- nt_fixsign y=nt_fixsign(x) - flip signs to maximize inter-component correlation

## SOURCE CODE

    0001 function x=nt_fixsign(x)
    0002 %y=nt_fixsign(x) - flip signs to maximize inter-component correlation
    0003
    0004 if ndims(x)<3;
    0005     y=nt_pca(x);
    0006     y=y(:,1)'*x; % correlation with PC
    0007     x=x*sign(diag(y));
    0008 else
    0009     [m,n,o]=size(x);
    0010     if 0
    0011         % can't remember the logic of this...
    0012         for k=1:n
    0013             x(:,k,:)=reshape(nt_fixsign(squeeze(x(:,k,:))), [m,1,o]);
    0014         end
    0015     else
    0016         x=nt_fold(nt_fixsign(nt_unfold(x)),m);
    0017     end
    0018 end
    0019
    0020 % flip whold matrix so highest peak is positive
    0021 if abs(max(x(:)))<abs(min(x(:)))
    0022     x=-x;
    0023 end