Compare same frequency components of two signals

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.

Answers (1)

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 Comments

matchpairs is part of core MATLAB, not the optimization toolbox. It's also not used in the code shown here?

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

Sign in to comment.

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

www
on 30 Sep 2019

Edited:

on 20 Jun 2025

Community Treasure Hunt

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

Start Hunting!