12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- %%CROSS-CORRELATION
- cross=zeros(chNO,chNO);
- delay=zeros(chNO,chNO);
- CorrLength = (2*size(A,2))-1
- meancorr=zeros(chNO,CorrLength);
- % ALL THE CHANNELS
- for channel=1:chNO
-
- Correlations=zeros(59,CorrLength);
-
- y1=A(channel,:);
-
- j=0;
- valmax1=zeros(1,chNO-channel);
- lag1=zeros(1,chNO-channel);
- valmax2=zeros(1,chNO-channel);
- lag2=zeros(1,chNO-channel);
- for i=(channel+1):chNO
- j=j+1;
-
- y2=A(i,:);
-
-
- [xcf,lags,bounds]=crosscorr(y1,y2,(size(A,2)-1));
-
- Correlations(i,1:CorrLength)=xcf;%calculating cross-correlations' mean for each channel
-
- maxDelayforCorr = 0;% max delay for max correlation in seconds
- zeroLagindex = find(lags==0);
- winSizeforDelay = (maxDelayforCorr/(WS/fs));
-
- valmax1(1,j)=max(xcf(zeroLagindex-winSizeforDelay:...
- zeroLagindex+winSizeforDelay));
- index=find(xcf==valmax1(j));
- if isempty(index)
- lag1(1,j)=NaN;
- else
- lag1(1,j)=lags(index);
- end
- [xcf,lags,bounds]=crosscorr(y2,y1,(size(A,2)-1));
-
- maxDelayforCorr = 0;% max delay for max correlation in seconds
- zeroLagindex = find(lags==0);
- winSizeforDelay = (maxDelayforCorr/(WS/fs));
-
- valmax2(1,j)=max(xcf(zeroLagindex-winSizeforDelay:...
- zeroLagindex+winSizeforDelay));
- index=find(xcf==valmax2(j));
- if isempty(index)
- lag2(1,j)=NaN;
- else
- lag2(1,j)=lags(index);
- end
- end
- cross((channel+1):chNO,channel)=valmax1;
- delay((channel+1):chNO,channel)=lag1;
- cross(channel,(channel+1):chNO)=valmax2;
- delay(channel,(channel+1):chNO)=lag2;
- meancorr(channel,1:CorrLength)=mean(Correlations);
-
-
- end
- %%
- cross_selection_correlated_channels()
|