MATLAB: Coherence of two signals

coherencedigital signal processingeeg

I have two channel eeg data having length 1×8064 each. Sampling frequency of the data s 128 samples /sec. When I was applying "mscohere" command for magnitude square coherence then it gave 1025×1 matrix of values between 0 to 1. I am confused that how it gives 1025×1 value. According to help it divides both x and y in 8 equal length then it is 1008 samples . please any one who know the concept behind this help me .

Best Answer

The coherence is a function of frequency, and in general it will not have the same number of elements as the original (split up) time domain signals.
If you have two signals:
>> x = rand(8064,1);
>> y = rand(8064,1);
Then if you call MSCOHERE with no specified input arguments,
>> C = mscohere(x,y);
this is the process that gives C 1025 elements:
Step 1. It splits x and y into 8 segments that overlap 50%.
Segment 1: x(1:1792)
Segment 2: x(897:2688)
Segment 3: x(1793:3584)
.
.
.
Segment 8: x(6273:8064)
You can see that because of the overlap, each segment is actually 8064/7 = 1792 samples long, not 8064/8 = 1008.
Step 2. It finds the next highest power of 2 as the length to use for the FFT. The next highest power of two after 1792 is 2048.
Step 3. When you take the FFT, the result is symmetric about the Nyquist frequency, so you really only need to keep half the result. This means, although the FFT length is 2048, the Nyquist frequency occurs at 2048/2+1, which is 1025. And so it is the coherence at these first 1025 frequency values that it is returning.