Why are continuous wavelet transform (cwt) and short-time Fourier transform (stft) functions giving such different results here?

I am performing time-frequency analysis on two signals and the result is confusing to me. The signals are seen in this figure:
I am mostly interested in the large peaks at the end of both signals. The peak-to-peak magnitude of x1 is about 50, while for x2 it is about 40. I would expect time-frequency analysis to reflect this observation.
When I perform the continuous wavelet transform for each signal, I find that the peak magnitude for x1 is 2.5 times larger than for x2, as seen in these figures. I have done this calculation with different parameters for the cwt and tried padding the signal, but this does not change. For the figures shown below, the code is simply calling the cwt() function with no other arguments:
Because this result seemed strange to me, I decided to check what the short-time Fourier transform would produce. The figures below show the result when you call stft() with no other input arguments
As you can see, both results have a similar pea magnitude of ~62 dB.
Any help understanding why this is the case would be appreciated. I attached the data for the variables x1 and x2.

Answers (1)

hello
I don'thave access to the toolbox that you are using but I am using another cwt code I probably found on the Fex (attached if you are interested)
now I can see a difference of magnitude of 6.87 dB between x1 and x2 spectra dB levels (max are respectively 28.25 and 21.38 dB), so converted back to linear factor it's about 2.2 , not very far from the 2.5 you're looking for
the sampling rate is unknown so I put Fs = 1 Hz by default
load('x1x2.mat')
%% x1
Fs = 1;
t1 = (0:numel(x1)-1)/Fs;
[y1,f1,coi1] = cwt(x1,Fs);
% reduction of the dB scale : only display max to min = max - Range_dB
Range_dB = 40; % dB scale
out1_dB = 20*log10(abs(y1));
max(out1_dB,[],'all')
ind = find(out1_dB< max(out1_dB,[],'all')-Range_dB);
out1_dB(ind) = NaN;
%% x2
Fs = 1;
t2 = (0:numel(x2)-1)/Fs;
[y2,f2,coi2] = cwt(x2,Fs);
% reduction of the dB scale : only display max to min = max - Range_dB
out2_dB = 20*log10(abs(y2));
max(out2_dB,[],'all')
ind = find(out2_dB< max(out2_dB,[],'all')-Range_dB);
out2_dB(ind) = NaN;
subplot(1,2,1),imagesc(t1,f1,out1_dB);
title('X1');
xlabel('Time (samples)')
ylabel('Frequency (Hz)')
colormap('jet')
colorbar('vert')
caxis([-10 30]);
set(gca,'YDir','normal');
hold on
plot(t1,coi1,'k','linewidth',3);
subplot(1,2,2),imagesc(t2,f2,out2_dB);
title('X2');
xlabel('Time (samples)')
ylabel('Frequency (Hz)')
colormap('jet')
colorbar('vert')
caxis([-10 30]);
set(gca,'YDir','normal');
hold on
plot(t2,coi2,'k','linewidth',3);

1 Comment

hello again
do you mind accepting my answer (if it has fullfiled your expectations ) ? tx

Sign in to comment.

Products

Release

R2021b

Asked:

on 7 Oct 2023

Commented:

on 11 Dec 2023

Community Treasure Hunt

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

Start Hunting!