Hi everyone,
I m having some problems trying to get the multiple coherence
of a 3 input single output system.
The method I use is the following and is described in one of the papers in my
field.
Initially you create a 3X3 matrix for the input (P,C,O) auto and cross
spectra:
Gi = [GPP GPC GPO
GCP GCC GCO
GOP GOC GOO]
Then you create a 3x1 matrix for the input/measured output cross-spectra
Go = [GPV
GCV
GOV]
Then you get the matrix for partial transfer functios
H = [HPV
HCV
HOV]
by solving this equation: Gi = H * Go
Finally you get the model output autospectrum by solving this equation
gyy=HT *Gi* H (HT is the transposed H matrix)
and thus you get multiple coherence as C=GYY/GVV
This is the code I ve written in matlab so far:
P=In1-mean(In1); %remove DC components
C=In2-mean(In2);
O=In3-mean(In3);
V=Out-mean(Out);
%Input Autospectra
[GPP,F]=cpsd(P,P,W,Ov,N,fs); %W=Window legnth , Ov=Overlap , N=nfft and
fs=sampling frequency
[GPC,F]=cpsd(P,C,W,Ov,N,fs);
[GPO,F]=cpsd(P,O,W,Ov,N,fs);
[GCP,F]=cpsd(C,P,W,Ov,N,fs);
[GCC,F]=cpsd(C,C,W,Ov,N,fs);
[GCO,F]=cpsd(C,O,W,Ov,N,fs);
[GOP,F]=cpsd(O,P,W,Ov,N,fs);
[GOC,F]=cpsd(O,C,W,Ov,N,fs);
[GOO,F]=cpsd(O,O,W,Ov,N,fs);
%Input output cross-spectra
[GPV,F]=cpsd(P,V,W,Ov,N,fs);
[GCV,F]=cpsd(C,V,W,Ov,N,fs);
[GOV,F]=cpsd(O,V,W,Ov,N,fs);
%Output autospectrum
[GVV,F]=cpsd(V,V,W,Ov,N,fs);
m=(W/2)+1; % The total number of samples in the cross-spectra vectors, for a
window W
% is half the number of the window, plus one.
k=round(m/5);
for n=1:length(m);
Gi=[GPP(n) GPC(n) GPO(n); GCP(n) GCC(n) GCO(n); GOP(n) GOC(n) GOO(n)];
Go=[GPV(n); GCV(n); GOV(n)];
H=Gi\Go;
gyy=(H' * Gi) * H;
mcoh=gyy./GVV;
end
However when I plot mcoh , it is flipped from right to left, and sometimes
exceeds 1.
Can anyone help on what I m doing wrong?