In: Electrical Engineering
clc
clear all
fs=2000; %sampling frequency
Ts=1/fs; %sampling time
dt=0:Ts:10-Ts; %time duration of signal
fm=1; %message signal frequency
vin=1*sin(2*pi*fm*dt); %message signal
plot(dt,vin)
%below is message signal plot
%now adding 100hz noise frequency signal in orginal
signal
fn=100;
vincorrpt=vin+1*sin(2*pi*fn*dt); %corrupted or noisy message
signal
figure
plot(dt,vincorrpt)
%plot of noisy corrupted signal with 100hz noise
%Now we are trying to see both signal and frequency component in frequency domain
%find length of signal
nfft=length(vin);
nfft2=2.^nextpow2(nfft);
fy=fft(vin,nfft2); %frequency domain transformation of signal
fy=fy(1:nfft2/2); %it takes out one side band from two side
bands
xfft=fs.*(0:nfft2/2-1)/nfft2;
figure
plot(xfft,abs(fy/max(fy)));
%below we get plot of meggase signal in frequency domain
%kindly observe the 1 hz frequency component
nfft=length(vincorrpt);
nfft2=2.^nextpow2(nfft);
fy=fft(vincorrpt,nfft2); %frequency domain transformation of
signal
fy=fy(1:nfft2/2); %it takes out one side band from two side
bands
xfft=fs.*(0:nfft2/2-1)/nfft2;
figure
plot(xfft,abs(fy/max(fy)));
%Now observe below frequency spectrum shows two frequency components one at 1hz and one at 100 hz
%Now our aim is
retrive our original signal of 1 hz frequrncy so we will design low
pass filter of order 32
cut_off=90/fs/2; %normaalize cut off frequency
order=32;
h=fir1(order,cut_off);
con=conv(vincorrpt,h);
figure
plot(con);
%below is our filtered signal it has improved from currputed but not quite so to improve further increase order or %filter at 45
order=45;
h=fir1(order,cut_off);
con=conv(vincorrpt,h);
figure
plot(con);
Note: closely observe the above filtered figure which is close to our orginal signal Hence it is clear as we increase number of order or stages of filtering the smothens of signal improves....You can try to increase more order and see good luck