Algorithm notes:
1)
clear all;
clc;
close all;
x=0.01:0.01:10;
y1=linspace(0,0,120);%120
y2=0:-0.004:-0.5;%126?
y3=linspace(-0.5,-0.5,128);%128?
y4=-0.5:0.004:0.5;%251?
y5=linspace(0.5,0.5,128);%128?
y6=0.5:-0.004:0;%126?
y7=linspace(0,0,121);%121
y=[y1,y2,y3,y4,y5,y6,y7];
figure(1)
plot(x,y)
2)
clear all;
clc;
close all;
StepData = xlsread('D:\MATLAB\DATASET OF MATLAB\wavelet transform\
[Link]');
ys=StepData (1,:);
Ls=length(ys);
ys_g= resample(ys, 1000, Ls);
figure(1)
subplot(3,1,1);
plot(ys_g,'r')
title('????');%?????‘????’
xlabel('??s'); %x????‘??s’
N=5; %?????
f=zeros(5,1000);%f represents the low frequency band, divided into
five layers. Zeros represents a matrix of all zeros, with 5 rows and
1000 columns
h=zeros(5,1000); %h represents the high frequency band divided into
five layers
[c,l]=wavedec(ys_g,N,'db3'); % Decompose the signal with one-
dimensional N-scale using y3, and return the wavelet coefficients of
each layer, haar represents the Haar wavelet, which is the selected
wavelet basis function
% Return value on the left: C is each coefficient after
wavelet decomposition, L is the number of corresponding wavelet
coefficients
for i=1:5 %i takes 1 to 5 respectively to do the following loop
operation
f(i,:)=wrcoef('a',c,l,'db3',i); % All elements of the i-th row of
matrix f
h(i,:)=wrcoef('d',c,l,'db3',i); %wrcoef is a one-dimensional
multi-level decomposition and reconstruction signal function, using
the c and l values obtained just after decomposition to reconstruct
the original signal, that is, the return value on the left;
% 'a' or'd' stands for "low frequency approximation" or "high
frequency details", C and L are the values obtained just after
decomposition, and "haar" means consistent with the wavelet basis
function during decomposition, and the last number i is where the
part is located series;
end
x=0:0.01:9.99;
subplot(3,2,3); %????????3×2??????3?????????
plot(x,f(5,:)); %x??????5??????????????????
xlabel('??s'); %x????‘??s’
ylabel('a5'); %y????‘a5’
grid on; %?????(grid off??????)
subplot(3,2,4);%????????3×2??????4?????????
plot(x,h(5,:)); %x??????5??????????????????
xlabel('??s'); %x????‘??s’
ylabel('d5'); %y????‘d5’
grid on; %?????
subplot(3,2,5);%????????3×2??????5?????????
plot(x,f(4,:)); %x??????5??????????????????????f5????f4??
xlabel('??s'); %x????‘??s’
ylabel('a4'); %y????‘a4’
grid on; %?????
subplot(3,2,6);%????????3×2??????6?????????
plot(x,h(4,:)); %x??????4??????????????????????h5????h4??
xlabel('??s'); %x????‘??s’
ylabel('d4'); %y????‘d4’
grid on;
figure(2) %????2?
subplot(3,2,1); %????????3×2??????1?????????
plot(x,f(3,:)); %x??????3??????????????????
xlabel('??s'); %x????‘??s’
ylabel('a3'); %y????‘a3’
grid on; %?????
subplot(3,2,2); %????????3×2??????2?????????
plot(x,h(3,:)); %x??????3??????????????????
xlabel('??s'); %x????‘??s’
ylabel('d3'); %y????‘d3’
grid on; %?????
subplot(3,2,3); %????????3×2??????3?????????
plot(x,f(2,:)); %x??????2??????????????????
xlabel('??s'); %x????‘??s’
ylabel('a2'); %y????‘a2’
grid on; %?????
3)
%% Resample Linear Sequence
% Resample a simple linear sequence at 3/2 the original rate of 10
Hz. Plot
% the original and resampled signals on the same figure.
% Copyright 2015 The MathWorks, Inc.
%%
fs = 10;
t1 = 0:1/fs:1;
x = t1;
y = resample(x,3,2);
t2 = (0:(length(y)-1))*2/(3*fs);
plot(t1,x,'*',t2,y,'o')
xlabel('Time (s)')
ylabel('Signal')
legend('Original','Resampled', ...
'Location','NorthWest')
%%
% When filtering, |resample| assumes that the input sequence, |x|, is
zero
% before and after the samples it is given. Large deviations from
zero at
% the endpoints of |x| can result in unexpected values for |y|.
%
% Show these deviations by resampling a triangular sequence and a
% vertically shifted version of the sequence with nonzero endpoints.
x = [1:10 9:-1:1;
10:-1:1 2:10]';
y = resample(x,3,2);
subplot(2,1,1)
plot(1:19,x(:,1),'*',(0:28)*2/3 + 1,y(:,1),'o')
title('Edge Effects Not Noticeable')
legend('Original','Resampled', ...
'Location','South')
subplot(2,1,2)
plot(1:19,x(:,2),'*',(0:28)*2/3 + 1,y(:,2),'o')
title('Edge Effects Noticeable')
legend('Original','Resampled', ...
'Location','North')
4)
clear all;
clc;
close all;
StepData = xlsread('D:\MATLAB\DATASET OF MATLAB\wavelet transform\
[Link]');
ys=StepData (1,:);
Ls=length(ys);Length of largest array dimension
ys_g= resample(ys, 1000, Ls); resample treats each column of x as an
independent channel. resample applies an antialiasing FIR lowpass
filter to x and compensates for the delay introduced by the filter.
figure(1)
subplot(3,1,1);
plot(ys_g,'r')
title('????');% The sub-picture is titled ‘Original Signal’
xlabel('??s'); %x The axis is labeled ‘time s’
N=5; % Represents five levels
f=zeros(5,1000); %f represents the low frequency band, divided
into five layers. Zeros represents the generation of a matrix of all
0s, with 5 rows and 1000 columns
h=zeros(5,1000); %h represents the high frequency band divided
into five layers
[c,l]=wavedec(ys_g,N,'db3');
for i=1:5 %i takes 1 to 6 respectively to do the following loop
operation
f(i,:)=wrcoef('a',c,l,'db3',i); % All elements in the i-th row of
matrix f,'a' or'd' stand for "low frequency approximation" or "high
frequency details"
h(i,:)=wrcoef('d',c,l,'db3',i); %wrcoef is a one-dimensional
multi-level decomposition and reconstruction signal function, using
the c and l values just decomposed to reconstruct the original
signal, that is, the return value on the left?
%'a' or'd' stands for "low frequency approximation" or "high
frequency details", C and L are the values obtained just after
decomposition, and "haar" means that they are consistent with the
wavelet basis function during decomposition, and the last number i is
where the part is The number of levels;
end
x=0:0.01:9.99;
subplot(3,2,3); % Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(5,:)); %x is the abscissa, and the low frequency band of
the reconstructed signal of the 5th layer is the ordinate, and the
graph is drawn;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('a5'); %y axis is labeled ‘a5’
grid on; % Show grid lines (grid off means hidden grid
lines)
subplot(3,2,4); % Divide the current figure into a 3×2 grid, and
create an axis at the fourth position?
plot(x,h(5,:)); %x is the abscissa, and the high frequency band of
the reconstructed signal of the 5th layer is the ordinate, and draw
the picture;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('d5'); %y axis is labeled ‘d5’
grid on; % Show grid lines
subplot(3,2,5); % Divide the current figure into a 3×2 grid, and
create an axis at the fifth position.
plot(x,f(4,:)); %x is the abscissa, the low frequency band of the
reconstructed signal of the 5th layer is the ordinate, and the
picture is drawn; (it was originally f5, I changed it to f4)
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('a4'); %y axis is labeled ‘a4’
grid on; % Show grid lines
subplot(3,2,6); % Divide the current figure into a 3×2 grid, and
create an axis at the sixth position.
plot(x,h(4,:)); %x is the abscissa, the high frequency band of the
reconstructed signal of the 4th layer is the ordinate, and the
picture is drawn; (it was originally h5, I changed it to h4)
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('d4'); %y axis is labeled ‘d4’
grid on;
figure(2) % Create figure 2;
subplot(3,2,1); % Divide the current figure into a 3×2 grid, and
create an axis at the first position?
plot(x,f(3,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the third layer is used as the
ordinate, and the graph is drawn;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('a3'); %y axis is labeled ‘a3’
grid on; % Show grid lines
subplot(3,2,2); % Divide the current figure into a 3×2 grid, and
create an axis at the second position?
plot(x,h(3,:)); %x is the abscissa, and the high frequency band of
the reconstructed signal of the 3rd layer is the ordinate, and draw
the picture;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('d3'); %y axis is labeled ‘d3’
grid on; % Show grid lines
subplot(3,2,3); % Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(2,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the second layer is used as the
ordinate, and the graph is drawn;xlabel('??s'); %x axis is marked as
‘time s’
ylabel('a2'); %y axis is marked as ‘a2’
grid on; % Show grid lines
5)
clear all;
clc;
close all;
StepData = xlsread('D:\MATLAB\DATASET OF MATLAB\wavelet transform\
yb\2022.[Link].04.r73(1).csv');
ys=StepData (1,:);
Ls=length(ys);
ys_g= resample(ys,1000, Ls);
figure(1)
subplot(3,1,1);
plot(ys_g,'r')
title('original signal');
xlabel('time s'); %'time s '
N=5; %Represents five levels
f=zeros(5,1000); %f represents the low frequency band, divided
into five layers. Zeros represents the generation of a matrix of all
0s, with 5 rows and 1000 columns
h=zeros(5,1000); %
[c,l]=wavedec(ys_g,N,'db3');% Decompose the signal with one-
dimensional N-scale using y3, and return the wavelet coefficients of
each layer, haar represents the Haar wavelet, which is the selected
wavelet basis function
% Return value on the left: C is each coefficient after
wavelet decomposition, L is the number of corresponding wavelet
coefficients;
for i=1:5 % %i takes 1 to 5 respectively to do the following loop
operation
f(i,:)=wrcoef('a',c,l,'db3',i);%% All elements of the i-th row of
matrix f"
h(i,:)=wrcoef('d',c,l,'db3',i);% %wrcoef is a one-dimensional
multi-level decomposition and reconstruction signal function, using
the c and l values obtained just after decomposition to reconstruct
the original signal, that is, the return value on the left;
% 'a' or'd' stands for "low frequency approximation" or "high
frequency details", C and L are the values obtained just after
decomposition, and "haar" means consistent with the wavelet basis
function during decomposition, and the last number i is where the
part is located series;
end
x=0:0.01:9.99;
subplot(3,2,3); %% Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(5,:)); %%x is the abscissa, and the low frequency band of
the reconstructed signal of the 5th layer is the ordinate, and the
graph is drawn;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('a5'); %y axis is labeled ‘a5’
grid on; % Show grid lines (grid off means hidden grid
lines)
subplot(3,2,4);% Divide the current figure into a 3×2 grid, and
create an axis at the fourth position?
plot(x,h(5,:)); %x is the abscissa, and the high frequency band of
the reconstructed signal of the 5th layer is the ordinate, and draw
the picture;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('d5'); %y axis is labeled ‘d5’
grid on; % show grid lines
subplot(3,2,5); % Divide the current figure into a 3×2 grid, and
create an axis at the fifth position.
plot(x,f(4,:)); %x is the abscissa, the low frequency band of the
reconstructed signal of the 5th layer is the ordinate, and the
picture is drawn; (it was originally f5, I changed it to f4)
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('a4'); % %y axis is labeled ‘a4’
grid on; % Show grid lines
subplot(3,2,6);% Divide the current figure into a 3×2 grid, and
create an axis at the sixth position.
plot(x,h(4,:)); %x is the abscissa, the high frequency band of the
reconstructed signal of the 4th layer is the ordinate, and the
picture is drawn; (it was originally h5, I changed it to h4)
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('d4'); %y axis is labeled ‘d4’
grid on; %show gridlines
figure(2) %Create figure 2;
subplot(3,2,1); % Divide the current figure into a 3×2 grid, and
create an axis at the first position?
plot(x,f(3,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the third layer is used as the
ordinate, and the graph is drawn;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('a3'); %y axis is labeled ‘a3’
grid on; %show grid line
subplot(3,2,2); % Divide the current figure into a 3×2 grid, and
create an axis at the second position?
plot(x,h(3,:)); %x is the abscissa, and the high frequency band of
the reconstructed signal of the 3rd layer is the ordinate, and draw
the picture;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('d3'); %y axis is labeled ‘d3’
grid on; %show gridline
subplot(3,2,3); % Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(2,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the second layer is used as the
ordinate, and the graph is drawn
xlabel('??s'); % x axis is marked as ‘time s’
ylabel('a2'); % %y axis is marked as ‘a2’
grid on; %show grid lines
6)
clear all;
clc;
close all;
load [Link] %Open the [Link] data set y3
x=0:0.01:9.99; % Takes x as a geometric sequence between 0 and
9.99 as the time
N=6; % Represents five levels
f=zeros(6,1000); %f represents the low frequency band, divided
into five layers. Zeros represents a matrix of all zeros, with 5 rows
and 1000 columns
h=zeros(6,1000); %h represents the high frequency band divided
into five layers
[c,l]=wavedec(y3,N,'haar');
% Decompose the signal with one-dimensional N-scale
using y3, and return the wavelet coefficients of each layer, haar
represents the Haar wavelet, which is the selected wavelet basis
function
% Return value on the left: C is each coefficient after
wavelet decomposition, L is the number of corresponding wavelet
coefficients;
for i=1:6 %i takes 1 to 5 respectively to do the following loop
operation
f(i,:)=wrcoef('a',c,l,'haar',i); % All elements of the i-th
row of matrix f
h(i,:)=wrcoef('d',c,l,'haar',i); %wrcoef is a one-dimensional
multi-level decomposition and reconstruction signal function, using
the c and l values ????obtained just after decomposition to
reconstruct the original signal, that is, the return value on the
left;
% 'a' or'd' stands for "low frequency approximation" or "high
frequency details", C and L are the values ??obtained just after
decomposition, and "haar" means consistent with the wavelet basis
function during decomposition, and the last number i is where the
part is located series;
end
figure(1) %Create figure 1;?
subplot(3,2,1); % Divide the current figure into a 3×2 grid, and
create an axis at the first position. Number the sub-picture position
by line number.
% The first subgraph is the first column of
the first row, the second subgraph is the second column of the first
row, and so on.
% If the specified location already has an
axes, this command will set the axes as the current axes?
plot(x,y3,'r'); % In the sub-picture window, draw a function
image where x is the abscissa, y3 is the ordinate, and ‘r’ represents
the use of a red line
title('????'); % The sub-picture title is ‘Original Signal’
xlabel('??s'); %x axis is marked as ‘time s’
subplot(3,2,3); % Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(5,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the 5th layer is used as the
ordinate, and the graph is drawn;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('a5'); %y axis is labeled ‘a5’
grid on; % Show grid lines (grid off means hidden grid
lines)
subplot(3,2,4); % Divide the current figure into a 3×2 grid, and
create an axis at the fourth position.
plot(x,h(5,:)); %x is used as the abscissa, and the high
frequency band of the reconstructed signal of the 5th layer is used
as the ordinate, and the graph is drawn;
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('d5'); %y axis is labeled ‘d5’
grid on; % Show grid lines
subplot(3,2,5); % Divide the current figure into a 3×2 grid, and
create an axis at the fifth position?
plot(x,f(4,:)); %x is the abscissa, the low frequency band of the
reconstructed signal of the 5th layer is the ordinate, and the
picture is drawn; (Originally it was f5, I changed it to f4??
xlabel('??s'); %x axis is marked as ‘time s’
ylabel('a4'); %y axis is marked as ‘a4’
grid on; % Show grid lines
subplot(3,2,6);%????????3×2??????6?????????
plot(x,h(4,:)); %x??????4??????????????????????h5????h4??
xlabel('??s'); %x????‘??s’
ylabel('d4'); %y????‘d4’
grid on; %?????
figure(2) %????2?
subplot(3,2,1); %????????3×2??????1?????????
plot(x,f(3,:)); %x??????3??????????????????
xlabel('??s'); %x????‘??s’
ylabel('a3'); %y????‘a3’
grid on; %?????
subplot(3,2,2); %????????3×2??????2?????????
plot(x,h(3,:)); %x??????3??????????????????
xlabel('??s'); %x????‘??s’
7)
clear all;
clc;
close all;
StepData = xlsread('D:\MATLAB\DATASET OF MATLAB\wavelet transform\
yb\2022.[Link].04.r73(1).csv');
ys=StepData (3,:);
Ls=length(ys);
ys_g= resample(ys,1000, Ls);
figure(1)
subplot(3,1,1);
plot(ys_g,'r')
title('original signal');
xlabel('time s'); %'time s '
N=5; %Represents five levels
f=zeros(5,1000); %f represents the low frequency band, divided
into five layers. Zeros represents the generation of a matrix of all
0s, with 5 rows and 1000 columns
h=zeros(5,1000); %
[c,l]=wavedec(ys_g,N,'haar');% Decompose the signal with one-
dimensional N-scale using y3, and return the wavelet coefficients of
each layer, haar represents the Haar wavelet, which is the selected
wavelet basis function
% Return value on the left: C is each coefficient after
wavelet decomposition, L is the number of corresponding wavelet
coefficients;
for i=1:5 % %i takes 1 to 5 respectively to do the following loop
operation
f(i,:)=wrcoef('a',c,l,'haar',i);%% All elements of the i-th row
of matrix f"
h(i,:)=wrcoef('d',c,l,'haar',i);% %wrcoef is a one-dimensional
multi-level decomposition and reconstruction signal function, using
the c and l values obtained just after decomposition to reconstruct
the original signal, that is, the return value on the left;
% 'a' or'd' stands for "low frequency approximation" or "high
frequency details", C and L are the values obtained just after
decomposition, and "haar" means consistent with the wavelet basis
function during decomposition, and the last number i is where the
part is located series;
end
x=0:0.01:9.99;
subplot(3,2,3); %% Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(5,:)); %%x is the abscissa, and the low frequency band of
the reconstructed signal of the 5th layer is the ordinate, and the
graph is drawn;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('a5'); %y axis is labeled ‘a5’
grid on; % Show grid lines (grid off means hidden grid
lines)
subplot(3,2,4);% Divide the current figure into a 3×2 grid, and
create an axis at the fourth position?
plot(x,h(5,:)); %x is the abscissa, and the high frequency band of
the reconstructed signal of the 5th layer is the ordinate, and draw
the picture;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('d5'); %y axis is labeled ‘d5’
grid on; % Show grid lines
subplot(3,2,5); % Divide the current figure into a 3×2 grid, and
create an axis at the fifth position.
plot(x,f(4,:)); %x is the abscissa, the low frequency band of the
reconstructed signal of the 5th layer is the ordinate, and the
picture is drawn; (it was originally f5, I changed it to f4)
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('a4'); % %y axis is labeled ‘a4’
grid on; % Show grid lines
subplot(3,2,6);% Divide the current figure into a 3×2 grid, and
create an axis at the sixth position.
plot(x,h(4,:)); %x is the abscissa, the high frequency band of the
reconstructed signal of the 4th layer is the ordinate, and the
picture is drawn; (it was originally h5, I changed it to h4)
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('d4'); %y axis is labeled ‘d4’
grid on; %show gridlines
figure(2) %Create figure 2;
subplot(3,2,1); % Divide the current figure into a 3×2 grid, and
create an axis at the first position?
plot(x,f(3,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the third layer is used as the
ordinate, and the graph is drawn;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('a3'); %y axis is labeled ‘a3’
grid on; %show grid line
subplot(3,2,2); % Divide the current figure into a 3×2 grid, and
create an axis at the second position?
plot(x,h(3,:)); %x is the abscissa, and the high frequency band of
the reconstructed signal of the 3rd layer is the ordinate, and draw
the picture;
xlabel('time s'); %x axis is marked as ‘time s’
ylabel('d3'); %y axis is labeled ‘d3’
grid on; %show gridline
subplot(3,2,3); % Divide the current figure into a 3×2 grid, and
create an axis at the third position?
plot(x,f(2,:)); %x is used as the abscissa, and the low frequency
band of the reconstructed signal of the second layer is used as the
ordinate, and the graph is drawn
xlabel('time s'); % x axis is marked as ‘time s’
ylabel('a2'); % %y axis is marked as ‘a2’
grid on; %show grid lines