Compare same frequency components of two signals

조회 수: 3 (최근 30일)
www
www 2019년 9월 30일
편집: TED MOSBY 2025년 6월 20일
Hello,
I have two signals and I want to split each one of them in same number of components. After that, I want to find the components with the (almost) same frequency and compare their plots.
Any idea how could I find same frequency components of the signals?
Thanks.

답변 (1개)

TED MOSBY
TED MOSBY 2025년 6월 19일
편집: TED MOSBY 2025년 6월 20일
Hi,
To compare same frequency components of two signals, you can follow the 3 steps below:
1. Decompose each signal into the same number K of narrow-band components:
MATLAB's function "emd" returns intrinsic mode functions "imf" and residual signal "residual" corresponding to the empirical mode decomposition. You can use "emd" to decompose and simplify complicated signals into a finite number of intrinsic mode functions:
K = 6; % how many modes you want
[imf1,~] = emd(x1,'MaxNumIMF',K); % x1 : first signal
[imf2,~] = emd(x2,'MaxNumIMF',K); % x2 : second signal
2. Extract a representative frequency for each component:
Dominant frequency = peak of the power-spectral density (PSD) of that component:
function f = dominantFreq(sig, fs)
%% Return the dominant frequency (peak of one‑sided PSD) in Hz
nfft = 2^nextpow2(numel(sig));
xdft = fft(sig, nfft);
psd = abs(xdft(1:nfft/2+1)).^2;
fvec = (0:nfft/2)' * fs / nfft;
[~, idx] = max(psd);
f = fvec(idx);
end
3. Pair components with “almost the same” frequency:
"pairs" tells you which IMF in "x1" matches which IMF in "x2". If you want an automatic global matching, MATLAB’s "matchpairs" can find the optimal one-to-one assignment that minimises total frequency error:
tol = 0.05; % 5 % relative tolerance
pairs = []; % rows: [idxSignal1 idxSignal2]
for k = 1:K
[d, j] = min( abs(dom2 - dom1(k))./dom1(k) ); % relative diff
if d < tol
pairs = [pairs; k j];
end
end
You can now go ahead and plot the matched pairs.
Below is the documentation of MATLAB functions used above:
Hope this helps!
  댓글 수: 2
Christine Tobler
Christine Tobler 2025년 6월 20일
matchpairs is part of core MATLAB, not the optimization toolbox. It's also not used in the code shown here?
TED MOSBY
TED MOSBY 2025년 6월 20일
편집: TED MOSBY 2025년 6월 20일

Yeah i just gave matchpairs as another option, and yes I mistook it for that toolbox, have edited the answer!

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

카테고리

Help CenterFile Exchange에서 MATLAB에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by