简体   繁体   中英

Imaginary part of coherence matlab

I want to calculate IMC according to below instructions

如何计算连贯性的虚部

I wrote below code in matlab, but the result is not what I was expecting. Is that code a valid implementation of the above instructions? Could someone help me with a better code?

 function [ imag_coherence] = imcoh( x,y )
 xy=xcorr(fft(x),fft(y));
 xx=xcorr(fft(x));
 yy=xcorr(fft(y));
 imag_coherence=imag(xy./sqrt(xx.*yy));
 end

xcorr actually computes the cross-correlation between the computed spectrums (a sums contributions over all frequencies), not the expectation of the point-wise multiplication (ie for a given fixed frequency) of those spectrums. The latter being what the coherency definition you provided uses.

Assuming the processes producing x and y are ergodic , the expectations can be estimated by computing the average over many blocks of data. With that in mind, an implementation of the coherency as described in your definition could look like:

function [ result ] = coherency( x,y,N )
  % divide data in N equal length blocks for averaging later on
  L  = floor(length(x)/N);
  xt = reshape(x(1:L*N), L, N);
  yt = reshape(y(1:L*N), L, N);

  % transform to frequency domain
  Xf = fft(xt,L,1);
  Yf = fft(yt,L,1);

  % estimate expectations by taking the average over N blocks
  xy = sum(Xf .* conj(Yf), 2)/N;
  xx = sum(Xf .* conj(Xf), 2)/N;
  yy = sum(Yf .* conj(Yf), 2)/N;

  % combine terms to get final result
  result=xy./sqrt(xx.*yy);
end

If you only want the imaginary part, then it's a simple matter of computing imag(coherency(x,y,N)) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM