www.gusucode.com > MATLAB——小波变换源码程序 > MATLAB——小波变换源码程序/daub10Transform/daub10Transform.m

    % it shows the plot of input signal as well as the transformed parts of the
% signal i.e. first trend and first fluctuation
function daub10Transform(f)
clc
% Sample Signal %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% t=0:0.0001:1;
% f=20*(t.^2).*(1-t).^4.*cos(12*t.*pi); 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%coeff of scaling function
al1=0.22641898/sqrt(2);
al2=0.85394354/sqrt(2);
al3=1.02432694/sqrt(2);
al4=0.19576696/sqrt(2);
al5=-0.34365671/sqrt(2);
al6=-0.04560113/sqrt(2);
al7=0.10970265/sqrt(2);
al8=-0.00882680/sqrt(2);
al9=-0.01779187/sqrt(2);
al10=0.0047174/sqrt(2);
%%coeff of wavelet function
be1=al10;
be2=-al9;
be3=al8;
be4=-al7;
be5=al6;
be6=-al5;
be7=al4;
be8=-al3;
be9=al2;
be10=-al1;

fv1=[al1 al2 al3 al4 al5 al6 al7 al8 al9 al10]; %scaling function
fw1=[be1 be2 be3 be4 be5 be6 be7 be8 be9 be10]; %wavelet function
% making the input even in length %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
if mod(length(f),2)~=0
    f=[f 0];
end
%wavelet transform %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Aa=[];
Da=[];
n=length(f);
for i=1:n/2-4;
   a11 = fv1(1)*f(2*i-1) + fv1(2)*f(2*i) + fv1(3)*f(2*i+1) + fv1(4)*f(2*i+2) + fv1(5)*f(2*i+3) + fv1(6)*f(2*i+4) + fv1(7)*f(2*i+5) + fv1(8)*f(2*i+6) + fv1(9)*f(2*i+7) + fv1(10)*f(2*i+8);
   Aa=[Aa a11];
   d11 = fw1(1)*f(2*i-1) + fw1(2)*f(2*i) + fw1(3)*f(2*i+1) + fw1(4)*f(2*i+2) + fw1(5)*f(2*i+3) + fw1(6)*f(2*i+4) + fw1(7)*f(2*i+5) + fw1(8)*f(2*i+6) + fw1(9)*f(2*i+7) + fw1(10)*f(2*i+8);
   Da=[Da d11];
end 
   n4=n/2-3;
   a15=fv1(9)*f(1) + fv1(10)*f(2) + fv1(1)*f(2*n4-1) + fv1(2)*f(2*n4) + fv1(3)*f(2*n4+1) + fv1(4)*f(2*n4+2) + fv1(5)*f(2*n4+3) + fv1(6)*f(2*n4+4) + fv1(7)*f(2*n4+5) + fv1(8)*f(2*n4+6);
   d15=fw1(9)*f(1) + fw1(10)*f(2) + fw1(1)*f(2*n4-1) + fw1(2)*f(2*n4) + fw1(3)*f(2*n4+1) + fw1(4)*f(2*n4+2) + fw1(5)*f(2*n4+3) + fw1(6)*f(2*n4+4) + fw1(7)*f(2*n4+5) + fw1(8)*f(2*n4+6);

   n3=n/2-2;
   a14=fv1(7)*f(1) + fv1(8)*f(2) + fv1(9)*f(3) + fv1(10)*f(4) + fv1(1)*f(2*n3-1) + fv1(2)*f(2*n3) + fv1(3)*f(2*n3+1) + fv1(4)*f(2*n3+2) + fv1(5)*f(2*n3+3) + fv1(6)*f(2*n3+4);
   d14=fw1(7)*f(1) + fw1(8)*f(2) + fw1(9)*f(3) + fw1(10)*f(4) + fw1(1)*f(2*n3-1) + fw1(2)*f(2*n3) + fw1(3)*f(2*n3+1) + fw1(4)*f(2*n3+2) + fw1(5)*f(2*n3+3) + fw1(6)*f(2*n3+4);
   
   n1=n/2-1;
   a13=fv1(5)*f(1) + fv1(6)*f(2) + fv1(7)*f(3) + fv1(8)*f(4) + fv1(9)*f(5) + fv1(10)*f(6) + fv1(1)*f(2*n1-1) + fv1(2)*f(2*n1) + fv1(3)*f(2*n1+1) + fv1(4)*f(2*n1+2);
   d13=fw1(5)*f(1) + fw1(6)*f(2) + fw1(7)*f(3) + fw1(8)*f(4) + fw1(9)*f(5) + fw1(10)*f(6) + fw1(1)*f(2*n1-1) + fw1(2)*f(2*n1) + fw1(3)*f(2*n1+1) + fw1(4)*f(2*n1+2);
   
   n2=n/2;
   a12 = fv1(1)*f(2*n2-1) + fv1(2)*f(2*n2) + fv1(3)*f(1) + fv1(4)*f(2) + fv1(5)*f(3) + fv1(6)*f(4) + fv1(7)*f(5) + fv1(8)*f(6) + fv1(9)*f(7) + fv1(10)*f(8);
   d12 = fw1(1)*f(2*n2-1) + fw1(2)*f(2*n2) + fw1(3)*f(1) + fw1(4)*f(2) + fw1(5)*f(3) + fw1(6)*f(5) + fw1(7)*f(5) + fw1(8)*f(6) + fw1(9)*f(7) + fw1(10)*f(8);
   
   a1=[Aa a15 a14 a13 a12];
   d1=[Da d15 d14 d13 d12];

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%plots
figure(1)
subplot(3,2,[1 2])
plot(f)
title('Original Signal') %plot of the original signal
ylabel('Amplitude')
xlabel('Time')
axis tight

subplot(3,2,3)
plot(a1)
title('First Trend') %plot of first trend after haar wavelet transform
ylabel('Amplitude')
xlabel('Time')
axis tight

subplot(3,2,4)
plot(d1)
title('First Fluctuation') %plot of first fluctuation after haar wavelet transform
ylabel('Amplitude')
xlabel('Time')
axis tight

subplot(3,2,[5 6])
plot([a1 d1])
title('Transformed Signal') %plot of the final signal obtained after the transformation
xlabel('Amplitude')
ylabel('Time')
axis tight

end