www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/CWTAndInverseCWTExample.m
%% Continuous Wavelet Transform and Inverse Continuous Wavelet Transform % This example shows how to use the continuous wavelet transform (CWT) % and inverse CWT. %% CWT of Sine Waves and Impulses % Create and plot a signal consisting of two disjoint sine waves with % frequencies of 100 and 50 Hz punctuated by two impulses. The sampling % frequency is 1 kHz and the total signal duration is one second. The % 100-Hz sine wave occurs over the first 250 milliseconds of the data. The % 50-Hz sinusoid occurs over the last 500 milliseconds. The impulses occur % at 650 and 750 milliseconds. The signal also has $N(0,0.1{^2})$ additive % white Gaussian noise. The impulse at 650 milliseconds is visible, but the % impulse at 750 milliseconds is not clearly evident in the time-domain % data. Fs = 1000; t = 0:1/Fs:1-1/Fs; x = zeros(size(t)); x([625,750]) = 2.5; x = x+ cos(2*pi*100*t).*(t<0.25)+cos(2*pi*50*t).*(t>=0.5)+... 0.1*randn(size(t)); plot(t.*1000,x) grid on; xlabel('msec'); ylabel('Amplitude'); %% % Obtain and plot the CWT using the default analytic Morse wavelet. [cfs,f] = cwt(x,1000); contour(t.*1000,f,abs(cfs)); xlabel('msec'); ylabel('Hz'); grid on; %% % The CWT moduli correctly show the supports of the disjoint sinusoids % and the locations of the impulses at 650 and 750 milliseconds. In the % CWT moduli, the impulse at 750 milliseconds is clearly visible. This is % especially true if you plot just the finest-scale wavelet coefficients. plot(t.*1000,abs(cfs(1,:))) grid on title('Fine-Scale Wavelet Coefficient Moduli') xlabel('msec') %% Frequency-Localized Inverse CWT % Using the inverse CWT you can construct frequency-localized % approximations to events in your time series. Use the inverse CWT to % obtain an approximation to the 100-Hz sinusoid in the previous example. xrec = icwt(cfs,f,[90 110]); plot(t,x); hold on; plot(t,xrec,'r'); legend('Original Signal','Inverse CWT Approximation',... 'Location','NorthEast'); grid on; %% % If you zoom in on the plot, you see the 100-Hz component is well % approximated but the 50-Hz component has been removed.