How to plot the coherence function?

24 views (last 30 days)
For my two signals, x and y, I have calculated the auto- and cross-spectral density functions from the fft. So my spectral densities are Sx, Sy and Sxy.
I want to find the coherence-function, but when I just enter the formula for the coherence function directly i a get a problem with the matrix dimensions.
coh=abs(Sxy)/(Sx*Sy)
Iam sure there is a much more elegant way to do it? any suggestions? I want the unit of the frequency axis to be in rad/s.
Andre

Accepted Answer

Wayne King
Wayne King on 4 Jun 2013
If you have the Signal Processing Toolbox, use mscohere()
n = 0:599;
x = cos(pi/4*n)+randn(size(n));
y = 1/2*sin(pi/4*n)+randn(size(n));
[Cxy,W] = mscohere(x,y,160,120,160);
plot(W,Cxy)
  3 Comments
Wayne King
Wayne King on 4 Jun 2013
Edited: Wayne King on 4 Jun 2013
It's in radians/sample. If you want it in radians per second, then put in the sampling frequency as an input to mscohere() and then multiple each element of the frequency vector by 2*pi
Fs = 1000;
t = 0:0.001:1-0.001;
x = cos(2*pi*100*t)+randn(size(t));
y = sin(2*pi*100*t)+randn(size(t));
[Cxy,F] = mscohere(x,y,200,150,200,Fs);
plot(F.*(2*pi),Cxy);
xlabel('Radians/Second')
Csanad Levente Balogh
Csanad Levente Balogh on 26 Nov 2020
Hi. Dou you have a solution for if you don't have the Signal Processing Toolbox?

Sign in to comment.

More Answers (0)

Categories

Find more on Measurements and Feature Extraction in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!