필터 지우기
필터 지우기

Pwelch only returns a single value?

조회 수: 4 (최근 30일)
Shayma Al Ali
Shayma Al Ali 2022년 2월 25일
답변: Shushant 2023년 9월 25일
I am trying to use the pwelch method in order to calculate the coherence magnitude squared between two signals with confidence intervals. However, the pwelch function only returns a single value. What am I doing wrong?
I also attached the variables I use in my code.
My code:
%calculate pwelch
fs=1/i_ph1.spacing_l;
[pwelch_1,f1,pxx1]=pwelch(i_ph1.l,hanning(length(i_ph1.l)),(length(i_ph1.l))/2,fs,'ConfidenceLevel',0.95);
[pwelch_2,f2,pxx2]=pwelch(i_ph2.l,hanning(length(i_ph2.l)),(length(i_ph2.l))/2,fs,'ConfidenceLevel',0.95);
[pwelch_3,f3,pxx3]=pwelch(i_ph3.l,hanning(length(i_ph3.l)),(length(i_ph3.l))/2,fs,'ConfidenceLevel',0.95);
[pwelch_12,f12,pxx12]=pwelch(xcorr(i_ph1.l,i_ph2.l),hanning(length(i_ph1.l)),(length(i_ph1.l))/2,fs,'ConfidenceLevel',0.95);
[pwelch_23,f23,pxx23]=pwelch(xcorr(i_ph2.l,i_ph3.l),hanning(length(i_ph2.l)),(length(i_ph2.l))/2,fs,'ConfidenceLevel',0.95);
[pwelch_31,f13,pxx13]=pwelch(xcorr(i_ph3.l,i_ph1.l),hanning(length(i_ph3.l)),(length(i_ph3.l))/2,fs,'ConfidenceLevel',0.95);
%calculate CMS
%Pxy^2/Pxx*Pyy
CMS12=(pwelch_12).^2./(pwelch_1.*pwelch_2);
CMS23=(pwelch_23).^2./(pwelch_2.*pwelch_3);
CMS13=(pwelch_31).^2./(pwelch_3.*pwelch_1);
%calculate CMS of conf intervals
CMS_c13=(pxx12).^2./(pxx1.*pxx2);
CMS_c23=(pxx23).^2./(pxx2.*pxx3);
CMS_c13=(pxx13).^2./(pxx1.*pxx3);
  댓글 수: 1
Mathieu NOE
Mathieu NOE 2022년 3월 8일
hello
have you tried mscohere ?
help mscohere
mscohere Magnitude Squared Coherence Estimate.
Cxy = mscohere(X,Y) estimates the magnitude squared coherence estimate
of the system with input X and output Y using Welch's averaged,
modified periodogram method. Coherence is a function of frequency with
values between 0 and 1 that indicate how well the input X corresponds
to the output Y at each frequency. The magnitude squared coherence,
Cxy, is given by Cxy = (abs(Pxy).^2)./(Pxx.*Pyy) where Pxx and Pyy are
the power spectral density (PSD) estimate of X and Y, respectively; and
Pxy is the Cross-PSD (CPSD) estimate of X and Y. See "help pwelch" and
"help cpsd" for complete details.

댓글을 달려면 로그인하십시오.

답변 (1개)

Shushant
Shushant 2023년 9월 25일
Hi Shayma Al Ali,
I understand that you are using the "pwelch" function to calculate the coherence magnitude squared between two signals with confidence intervals. But the function is only returning a single value. This is because the "pwelch" function is expecting "fs" to be the fifth argument.
To solve this issue, specify the fourth argument as empty "[]". Refer to the following code snippet for the modified function call:
[pwelch_1,f1,pxx1]=pwelch(i_ph1.l,hanning(length(i_ph1.l)),(length(i_ph1.l))/2,[],fs,'ConfidenceLevel',0.95);
Refer to the following documentation for information on why the fourth argument should be empty-
I hope this helped in solving the issue you were facing.
Thank you,
Shushant

카테고리

Help CenterFile Exchange에서 Signal Generation and Preprocessing에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by