MATLAB: Mscohere function

coheremscohere

I'm using mscohere to calculate the coherence between two signals x, y. using the following formula: mscohere(x,y,window,overlap,nfft,sampling frequency)
1- I have the following questions: nfft doesn't permit to specify frequencies of interest i.e 1:1:50 Hz. Is there anyway to specify the frequencies of interest. When i use a frequency vector i receive an error message. 2- When i try to use the same function to analyze the coherence among 54 different signals (54 X 54 / 2 ) times. The processing time is considerably slow. Are there any tips or suggestions to make it faster. 3- Any suggestions for the ideal overlap and window duration ?
Thanks,

Best Answer

Hi Raf, You can't specify the frequencies of interest as an input argument, but you can easily extract the mean-square coherence values for the frequencies you want. This of course implies that you have chosen your input parameters to ensure that the spacing between DFT bins is sufficient.
t = 0:0.001:1-0.001;
x = cos(2*pi*10*t)+0.25*sin(2*pi*40*t)+randn(size(t));
y = cos(2*pi*10*t-pi/4)+0.15*sin(2*pi*40*t-pi/2)+randn(size(t));
[Cxy,F] = mscohere(x,y,250,200,250,1000);
plot(F,Cxy)
In the above, I've chosen a segment length of 250, that gives me a frequency resolution of Fs/250 or 4 Hz. You can see this by looking at
diff(F)
If you really want a resolution of 1 Hz, then you have to choose your window length accordingly.
The overlap is trickier to give specific rules for. The larger the overlap, the more computation, but the more averaged the result (less bias)