- "emd" : https://www.mathworks.com/help/signal/ref/emd.html?s_tid=doc_srchtitle
- "fft" : https://www.mathworks.com/help/releases/R2025a/matlab/ref/fft.html?s_tid=doc_srchtitle#d126e528545
- "matchpairs" : https://www.mathworks.com/help/matlab/ref/matchpairs.html?s_tid=srchtitle_support_results_1_matchpairs
Compare same frequency components of two signals
3 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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.
0 Commenti
Risposte (1)
TED MOSBY
il 19 Giu 2025
Modificato: TED MOSBY
il 20 Giu 2025
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 Commenti
Christine Tobler
il 20 Giu 2025
matchpairs is part of core MATLAB, not the optimization toolbox. It's also not used in the code shown here?
Vedere anche
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!