0% found this document useful (0 votes)
32 views

DSP Lab 3

This document summarizes Digital Signal Processing Lab #03 on moving average filters and convolution. The objectives are to plot an exponential, generate and plot sequences with noise, apply a moving average filter to smooth noise, and convolve two sequences. Tasks involve plotting an exponential, adding noise to a generated sequence and smoothing it with a filter, and convolving two user-input sequences and plotting the output. MATLAB code and results are shown for each task.

Uploaded by

HunZilah ShEikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
32 views

DSP Lab 3

This document summarizes Digital Signal Processing Lab #03 on moving average filters and convolution. The objectives are to plot an exponential, generate and plot sequences with noise, apply a moving average filter to smooth noise, and convolve two sequences. Tasks involve plotting an exponential, adding noise to a generated sequence and smoothing it with a filter, and convolving two user-input sequences and plotting the output. MATLAB code and results are shown for each task.

Uploaded by

HunZilah ShEikh
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Digital Signal Processing

LAB # 03
MOVING AVERAGE FILTER AND CONVOLUTION

Name: Muhammad Hunzilah Ahmad


Session: BSEE 2018-2022(Electronics)

Instructors: Dr. Sufi Tabassum Gul


Engr. Javeria Ayub
Engr. Ayesha Ashraf

Department of Electrical Engineering


Pakistan Institute of Engineering and Applied Sciences
Nilore, Islamabad
3.1 Objectives

• To plot a discrete time real exponential.


• To generate and plot a discrete sequence and discrete random noise.
• To smooth a noisy sequence by the application of a moving average filter.
• To convolve two discrete time sequences and plot the output sequence.
3.2 Equipment
• Computer / laptop
• MATLAB software
3.3 Useful Matlab functions
• rand, filter, conv, disp
• subplot, input,stem

3.4 Tasks
1. Plot a discrete time real exponential x(n) = 𝑲𝜶𝒏 with K=5 and α= 0.9.

MATLAB Code
n = 0:100;
k = 5;
a = 0.9;
x = k*a.^n;
stem (n,x)
title ('x[n] = ka^n')
xlabel ('n')
ylabel ('Amplitude')

Result:

Figure 1 Task1 plot of function x[n] = ka^n


2. Generate a discrete sequence s(n) = 𝟐𝒏𝜶(𝟎. 𝟗)𝒏 and discrete random noise and then
added noise to s(n). Plot the original sequence, noise and corrupted sequence.
MATLAB Code
a = 0.9;
n = 0:100;
%------original sequence--------
s = 2.*n.*a.*(0.9.^n);

subplot (3,1,1)
stem(n,s)
title('Original sequence')
xlabel ('n')
ylabel('Amplitude')
%------discrete randone noise---
noise = rand (1, length (n));

subplot (3, 1,2)


stem(n,noise)
title('Noise Signal')
xlabel('n')
ylabel('Amplitude')
%-------corrupted signal--------
y = s + noise ;
subplot (3, 1,3)
stem (n, y)
title('Corrupted Signal')
xlabel('n')
ylabel('Amplitude')

Figure 2 Task2 plot of given original sequence, noise and corrupted sequence
3. Apply a moving average filter on a noisy sequence to smoothen a corrupted
sequence.
The Corrupted sequence used is obtained from task 2

%------smoothen signal----------
w = 10;
b= (1/w) *ones (1,w);
a = 1;
smooth = filter (b, a, y);

subplot (3,1,3)
stem (n, smooth)
title( 'Smoothened Signal')
xlabel('n')
ylabel('Amplitude')

Figure 3 Task3 plot of given original sequence, corrupted sequence and smoothen signal
4. Convolve two discrete time sequences x1(n) and x2(n) using conv() command and plot
the output sequence
MATLAB Code

%--------input sequence x1[n] ----------


n = input('Enter length of sequence');
for i=1:n
x1(i) = input('Enter the element');
end
subplot(3,1,1)
stem(x1)
title ('Sequence x1[n]')
xlabel('n')
ylabel('Amplitude')

%--------input sequence x2[n] ----------


n = input('Enter length of sequence');
for i=1:n
x2(i) = input('Enter the element');
end
subplot(3,1,2)
stem(x2)
title ('Sequence x2[n]')
xlabel('n')
ylabel('Amplitude')

%----convolution of x1[n] and x2[n]---


y = conv(x1,x2);
subplot(3,1,3)
stem(y)
title ('convolution of x1[n] and x2[n]')
xlabel('n')
ylabel('Amplitude')
Sequence 1 is input as x1[n] = [10 8 6 5 4 3 2 1]
Sequence 2 is input as x2[n] = [1 1 1 1 1 0 0 0 ]

Figure 4 Task3 plot of convolution of 2 sequences

You might also like