www.gusucode.com > wavelet 源码程序 matlab案例代码 > wavelet/OutputIntervalsAndThresholdsExample.m

    %% Output Intervals and Thresholds
% Create a signal sampled at 1 kHz. The signal consists of a series of 
% bumps of various widths.
t = [0.1 0.13 0.15 0.23 0.25 0.40 0.44 0.65 0.76 0.78 0.81];
h = [4  -5  3  -4 5  -4.2  2.1  4.3  -3.1  5.1  -4.2];
h  = abs(h);
len = 1000;
w  = 0.01*[0.5 0.5 0.6 1 1 3 1 1 0.5 0.8 0.5];
tt = linspace(0,1,len);  x = zeros(1,len);
for j=1:11
  x = x + ( h(j) ./ (1+ ((tt-t(j))/w(j)).^4));
end
plot(tt,x);
title('Original Signal');
hold on;
%%
% Add white Gaussian noise with different variances to two disjoint 
% segments of the signal. Add zero-mean white Gaussian noise with variance 
% equal to 2 to the signal segment from 0 to 0.3 seconds. Add zero-mean 
% white Gaussian noise with unit variance to the signal segment from 0.3 
% seconds to 1 second. Set the random number generator to the default 
% settings for reproducible results.
rng default;
nv1 = sqrt(2).*randn(size(tt)).*(tt<=0.3);
nv2 = randn(size(tt)).*(tt>0.3);
xx = x+nv1+nv2;
plot(tt,xx);
title('Noisy Signal');
%%
% Apply interval-dependent denoising using the Daubechies' least-
% asymmetric wavelet with 4 vanishing moments down to level 5. 
% Automatically choose the number of intervals and output the result.
[sigden,coefs,thrParamsOut] = cmddenoise(xx,'sym4',5);
thrParamsOut{1}
%%
% |cmdnoise| identifies one variance change point in the 1st level detail 
% coefficients defining two intervals. The first interval contains samples
% 1 to 293. The second interval contains samples 293 to 1000. This is close
% to the true variance change point, which occurs at sample 299.