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

EENG 479: Digital Signal Processing: Student Name: ID

This document contains the lab manual for Digital Signal Processing Lab 1. It includes instructions for generating different discrete signals using Matlab, including complex exponential sequences, real exponential sequences, and discrete cosine signals. It also provides code examples for signal smoothing using a moving average filter, illustrating convolution, and generating note examples. The conclusion states that the lab helped the student learn how to generate different discrete signals, implement moving filters, and perform convolution in Matlab.

Uploaded by

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

EENG 479: Digital Signal Processing: Student Name: ID

This document contains the lab manual for Digital Signal Processing Lab 1. It includes instructions for generating different discrete signals using Matlab, including complex exponential sequences, real exponential sequences, and discrete cosine signals. It also provides code examples for signal smoothing using a moving average filter, illustrating convolution, and generating note examples. The conclusion states that the lab helped the student learn how to generate different discrete signals, implement moving filters, and perform convolution in Matlab.

Uploaded by

Ebrahim
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

UNIVERSITY OF BAHRAIN

COLLEGE OF ENGINEERING
DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING

EENG 479: Digital Signal Processing


Lab 1

Student Name:
ID:
Aim:
-Generate different discrete signals by using “Matlab”

Generation of the ensemble average

R = 50;
m = 0:R-1;
s = 2*m.*(0.9.^m);
% Generate the uncorrupted signal
d = rand(R,1)-0.5;
% Generate the random noise
x1= s+d';
figure(1)
stem(m,d)
xlabel('Time index n');
ylabel('Amplitude');
title('Noise');
figure(2)
stem(m,x1)
xlabel('Time index n');
ylabel('Amplitude');
title('Signal with Noise');

for n = 1:50;

d = rand(R,1)-0.5;
x = s + d';
x1 = x1 + x;
end
x1 = x1/50;
figure(3)
stem(m,x1);
xlabel('Time index n');
ylabel('Amplitude');
title('Ensemble average');
Generation complex Exponential Sequence

a= input('Type in real exponent = ');


b = input('Type in imaginary exponent = ');
c = a + b*i;
K = input('Type in the gain constant = ');
N = input ('Type in length of sequence = ');
n = 1:N;
x = K*exp(c*n); %Generate the sequence
figure(1)
stem(n,real(x)); %Plot the real part
xlabel('Time index n');
ylabel('Amplitude');
title('Real part');
disp('PRESS RETURN for imaginary part');
figure(2)
stem(n,imag(x));
%Plot the imaginary part
xlabel('Time index n');ylabel('Amplitude');
title('Imaginary part');

Matlab values entered :

Type in real exponent = 100

Type in imaginary exponent = 10

Type in the gain constant = 20

Type in length of sequence = 8


Generation of real exponential sequence

a = input('Type in argument = ');


K = input('Type in the gain constant = ');
N = input ('Type in length of sequence = ');
n = 0:N;
x = K*a.^n;
stem(n,x);
xlabel('Time index n');ylabel('Amplitude');
title(['\alpha = ',num2str(a)]);

Matlab values Entered:

Type in argument = 5

Type in the gain constant = 10

Type in length of sequence = 8


Signal Smoothing by a Moving-Average Filter
R = 50;
d = rand(R,1)-0.5;
m = 0:1:R-1;
s = 2*m.*(0.9.^m);
x = s + d';
figure(1)
plot(m,d,'r-',m,s,'b--',m,x,'g:')

xlabel('Time index n'); ylabel('Amplitude')


legend('d[n]','s[n]','x[n]');
pause
M = input('Number of input samples = ');
b = ones(M,1)/M;
y = filter(b,1,x);
figure(2)
plot(m,s,'r-',m,y,'b--');
legend('s[n]','y[n]');
xlabel ('Time index n');
ylabel('Amplitude')

signal

M=1 M=4
Illustration of Convolution

a = input('Type in the first sequence = ');


b = input('Type in the second sequence = ');
c = conv(a, b);
M = length(c)-1;
n = 0:1:M;
disp('output sequence =');
disp(c)
stem(n,c)
xlabel('Time index n'); ylabel('Amplitude');

Type in the first sequence = [-2 0 1 -1 3]

Type in the second sequence = [1 2 0 -1]

output sequence =

-2 -4 1 3 1 5 1 -3
Filter
[y1,sf]=filter(1,[1,1,-6],8*ones(1,8),[-7,6]);
stem(y1)
hold on;
n=0:7;
y2=-1.8*(-3).^n+4.8*(2).^n-2;
stem(y2,'r*')
M2.9

x = input('Type in the reference sequence = ');


y = input('Type in the second sequence = ');
n1 = length(y)-1; n2 = length(x)-1;
s = conv(x,fliplr(y));
k = (-n1):n2';
stem(k,s);
xlabel('index'); ylabel('Amplitude');
v = axis;
axis([-n1 n2 v(3:end)]);

Type in the reference sequence = [-4 5 1 -2 -3 0 2]


Type in the second sequence = [6 -3 -1 0 8 7 -2]
Results:

Type in the reference sequence = [-4 5 1 -2 -3 0 2]


Type in the second sequence = [3 2 2 -1 0 -2 5]
Type in the reference sequence = [-4 5 1 -2 -3 0 2]
Type in the second sequence = [-4 5 1 -2 -3 0 2]

Type in the reference sequence = [6 -3 -1 0 8 7 -2]


Type in the second sequence = [6 -3 -1 0 8 7 -2]

Type in the reference sequence = [3 2 2 -1 0 -2 5]


Type in the second sequence = [3 2 2 -1 0 -2 5]
generating discrete cos signal

n=0:1:40;
w=[0 0.1 0.2 0.8 0.9 1 1.1 1.2];
for i=1:8
x=1.5*(cos(w(i)*pi*n))
figure(i)
stem(n,x)
grid
end

W=0pi W=0.1pi

W=0.2pi W=0.8pi
W=0.9pi W=1pi

W=1.1pi W=1.2pi
Note examples
1-Complex eponential sequence
n=0:40;
y=exp((-1/12+j*pi/6)*n);
subplot(2,1,1)
stem(n,real(y))
subplot(2,1,2)
stem(n,imag(y))

2-real eponential sequence


n=0:30;
x=0.2*(1.2).^n;
y=20*(0.9).^n;
subplot(2,1,1)
stem(n,x)
ylabel('Amplitude');
title('alpha=1.2');
subplot(2,1,2)
stem(n,y)
ylabel('Amplitude');
title('alpha=0.9');

Conclusion: the lab was very helpful and now I able


to Generate different discrete signals, do moving
filter code and do convolution using matlab.

You might also like