%% Example 3.4 % Here is the signal consisting of 4 cycles of sine followed by a step function % with added random noise. %% s10 = [sin([1:512]*8*pi/512) ones(1,256) ones(1,256)/2]+0.1*randn(1,1024); %% plot(s10) xticks([0 256 512 768 1024]) xticklabels({'0','256','512','768','1024'}) axis([0 1024 -1.5 1.5]) title('random signal with noise') %% % I use the command % *haarwave* from Computer Exploration 3.7.4 to compute the three-scale % Haar transform. %% T = haarwave(s10,3); %% % Here is the one-scale transform. plot(T(1,:)) xticks([0 256 512 768 1024]) xticklabels({'0','256','512','768','1024'}) axis([0 1024 -1.5 1.5]) title('one-scale Haar transform of signal') annotation('doublearrow',[0.13 0.52], [0.52 0.52]); annotation('doublearrow',[0.52 0.905],[0.52 0.52]); annotation('textbox',[0.32 0.42 0.11 0.06],... 'String',{'trend s_9'},'LineStyle','none'); annotation('textbox',[0.65 0.38 0.16 0.10],... 'String',{'detail d_9'},'LineStyle','none'); %% % Here is the two-scale transform. plot(T(2,1:512)) xticks([0 128 256 384 512]) xticklabels({'0','128','256','384','512'}) axis([0 512 -1.5 1.5]) title('two-scale Haar transform of signal') annotation('doublearrow',[0.13 0.52], [0.52 0.52]); annotation('doublearrow',[0.52 0.905],[0.52 0.52]); annotation('textbox',[0.32 0.42 0.11 0.06],... 'String',{'trend s_8'},'LineStyle','none'); annotation('textbox',[0.65 0.38 0.16 0.10],... 'String',{'detail d_8'},'LineStyle','none'); %% % Here is the three-scale transform. plot(T(3,1:256)) xticks([0 64 128 192 256]) xticklabels({'0','64', '128','192','256'}) axis([0 256 -1.5 1.5]) title('two-scale Haar transform of signal') annotation('doublearrow',[0.13 0.52], [0.52 0.52]); annotation('doublearrow',[0.52 0.905],[0.52 0.52]); annotation('textbox',[0.32 0.42 0.11 0.06],... 'String',{'trend s_7'},'LineStyle','none'); annotation('textbox',[0.65 0.38 0.16 0.10],... 'String',{'detail d_7'},'LineStyle','none');