0% found this document useful (0 votes)
18 views2 pages

Noise Programm

The document contains MATLAB code that generates a synthetic signal composed of multiple segments and adds random noise to it. It then processes the noisy signal through wavelet decomposition using the Haar wavelet, extracting low and high frequency components. Finally, the code visualizes the original and processed signals in various subplots.

Uploaded by

nayem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views2 pages

Noise Programm

The document contains MATLAB code that generates a synthetic signal composed of multiple segments and adds random noise to it. It then processes the noisy signal through wavelet decomposition using the Haar wavelet, extracting low and high frequency components. Finally, the code visualizes the original and processed signals in various subplots.

Uploaded by

nayem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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];

x=0.01:0.01:30;
y1=linspace(0,0,298);%298
y2=0:-0.0065:-0.65;%100 位
y3=linspace(-0.65,-0.65,300);%300 位
y4=-0.65:0.0065:0;%100 位
y5=linspace(0,0,1400);%1400 位
y6=0:0.0065:0.65;%100 位
y7=linspace(0.65,0.65,300);%300
y8=0.65:-0.0065:0;%100 位
y9=linspace(0,0,298);%298

y=[y1,y2,y3,y4,y5,y6,y7,y8,y9];

figure(1)
subplot(2,1,1)
plot(x,y)
L=length(y); %Calculate the length of an audio signal
noise=0.02*randn(1,L); %Generate a random noise signal of equal length (the size of the noise here
depends on the amplitude multiple of the random function)
subplot(2,1,2)
plot(x,noise)
y_z=y+noise; %Superimpose two signals into a new signal - add noise processing
figure(2)
subplot(2,1,1)
plot(x,y_z)

%N = normalize(y_z)
%Nr = normalize(y_z,'range')
%subplot(2,1,2)
%plot(Nr)

fc=var(y_z);%To find the variance of the entire signal, it is not used temporarily, it may be used when
determining the threshold
j=0;
for i=1:L;
if (y_z(i)<-0.0468);
j=j+1;
m(j)=y_z(i);
end
end
L1=length(m) ;
m1= resample(m, L, L1);%Scale normalization processing, resample is generated by resampling m by
L/L1 times m1
subplot(2,2,3)
plot(m)
subplot(2,2,4)
plot(m1)

N=7; %Representatives are divided into five layers


f=zeros(7,L1); %fRepresents the low frequency band and is divided into five layers zeros represents
the generation of an all-zero matrix, 5 rows and 1000 columns
h=zeros(7,L1); %hOn behalf of the high frequency band, it is divided into five layers
[c,l]=wavedec(m,N,'haar');%Commonly used wavelets haar、db1 4 8 15、coif1 2 3、sym1 2
%Perform one-dimensional N-scale decomposition on the signal with y3, and return the
wavelet coefficients of each layer, haar stands for 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:7 %i take 1 to 6 respectively and do the following loop operation
f(i,:)=wrcoef('a',c,l,'haar',i);%all elements of the ith row of matrix f
h(i,:)=wrcoef('d',c,l,'haar',i);%wrcoef is a one-dimensional multi-level decomposition and
reconstruction signal function, which uses the c and l values just decomposed to reconstruct the
original signal, that is, the return value on the left;
% 'a' or 'd' represents "low frequency approximation" or "high frequency detail", C and L are the
values just decomposed, 'haar' means consistent with the wavelet basis function during
decomposition, and the last number i is where the part is located series;
end

figure(3) %Create figure1;


subplot(3,2,1); %Divide the current figure into a 3-by-2 grid and create the axes at position 1.
Number subplot positions by line number。
%The first subplot is the first column of the first row, the second subplot is the second
column of the first row, and so on.
%If axes already exist at the specified location, this command makes the axes the current
axes。
plot(x,y_z,'r'); %In the subgraph window, draw a function image with x as the abscissa and y3 as the
ordinate, and 'r' represents the use of a red line
title('原始信号');%The subplot is titled 'Original Signal’
xlabel('时间 s'); %When the x-axis is marked '

You might also like