bug in cwt function
11 views (last 30 days)
I am using cwt function with 'morl' wavelet. Here is the syntax I am using:
[cwtwavex,freqsx]=cwt(x, scales, 'morl' , 'absglb', dt)
But it seems that there is a bug in the function, because when I choose an impulse function as the input (x), and plot the output in different scales, which should be essentially the wavelets shape, but the output on the last scale is mainly a morlet function modulated with another function!... Here is the code I wrote: clear all;
xlen=1000; Fs=2e4; % sampling frequency
dt=1/Fs; a0 = 2^(1/32); scales = 2*a0.^(0:6*32);
wavex=x; [cwtwavex,freqsx]=cwt(x, scales, 'morl' , 'absglb', dt);
%% figure(1); plot(x);
figure (2); plot(cwtwavex(1,:), 'r') ylabel('cwtx1');
figure (3); plot(cwtwavex(193,:), 'b') ylabel('cwtx193');
But as you see, the shape of the wavelet output on the last scale (193) and also the mesh figure are very strange ( many fluctuations) which would stem from the wrong shape of the morlet wavelet at S(193) (last scale)!!
This problem does not exist when 'sym2' is used! Please help.
Also, it seems that there are lots of limitation when using morlet wavelet with cwt function: it doesn't take 'morl' easily with regular syntax. Please advise.
Thank you very much.
Wayne King on 14 Jun 2018
Hi Ziba, First of all, I would encourage you to use the new CWT interface as opposed to the legacy interface you are using here. With the new CWT interface, you can use the 'amor' for the analytic Morlet.
As pertains to your current question, I'm not sure what you are expecting. Let's use a delta function so when we obtain the CWT, we essentially get back the wavelet at each scale (subject to a reversal).
Fs=2e4; % sampling frequency
a0 = 2^(1/32);
scales = 2*a0.^(0:6*32);
x = zeros(1e3,1);
x(500) = 1;
Let's know check the frequency at the 193-th element of the scale vector
So that is 126 Hz. Now get the wavelet corresponding to that scale.
psi = cwtwavex(193,:);
Let's get the power spectrum, we expect the peak frequency to be around 127.
[Pxx,F] = periodgram(psi,,2048,2e4);
[~,idx] = max(Pxx);
If we take a much smaller scale, we expect that the wavelets have a higher center frequency.