How to plot the coherence function?
24 views (last 30 days)
Show older comments
Andre
on 4 Jun 2013
Commented: Csanad Levente Balogh
on 26 Nov 2020
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
0 Comments
Accepted Answer
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
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
on 26 Nov 2020
Hi. Dou you have a solution for if you don't have the Signal Processing Toolbox?
More Answers (0)
See Also
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!