DSPRelated.com
Forums

Coherence matlab

Started by assa...@hotmail.com October 6, 2010
Hi all,

I would appreciate your help with the following problem.

I am trying to use matlab for coherence calculation accordign to the mathematical definitions and without using the available coher functions.

The two signals are defined as follows:
==================
% Original signal
% ==============
NP00; % Number of samples
t=1:1:N;
a=0.5+0.5*sin(2*pi*0.6*t*10^-3); % Base signal

% White noise signals with mean 0 and standard deviation 1
% ========================================================
e_one=randn(1,5000);
e_two=randn(1,5000);

for i=1:N
s_one(i)=e_one(i)+a(i)*e_two(i);
s_two(i)=e_two(i)+a(i)*e_one(i);
end

==============================
METHOD 1 - follows the mathematical definition step by step:

Xt(s1);
Yt(s2);

Pxx=X.*conj(X);
Pyy=Y.*conj(Y);
Pxy=X.*conj(Y);

Ks(Pxy.*Pxy)./(Pxx.*Pyy);

==============================
METHOD 2 - uses the cpsd function:

[Pxx,freq]=cpsd(X,X,filter_length,n_overlap,nfft,fs);
[Pxy,freq]=cpsd(X,Y,filter_length,n_overlap,nfft,fs);
[Pyy,freq]=cpsd(Y,Y,filter_length,n_overlap,nfft,fs);

coh=Pxy.*conj(Pxy)./(Pxx.*Pyy);

==============================
METHOD 3 - uses the cpsd function but without calculating FFT:

[Pxx,freq]=cpsd(s1,s1,filter_length,n_overlap,nfft,fs);
[Pxy,freq]=cpsd(s1,s2,filter_length,n_overlap,nfft,fs);
[Pyy,freq]=cpsd(s2,s2,filter_length,n_overlap,nfft,fs);

=================================I have 2 questions:

1. Why does method 1 gives a constant result of '1'?

2. What is the correct method between method 2 and 3?
Thanks a lot,

Assaf