Lab 2
Lab 2
Lab 2
Objectives:
• To learn how to generate some basic discrete-time signals in MATLAB and perform
elementary operations on them.
• To learn the application of some basic MATLAB commands [cos, exp, imag, real, plot, grid,
axis, stem, legend] and how to apply them in simple digital signal processing problems
Introduction
Digital signal processing is concerned with the processing of a discrete-time signal, called
the input signal, to develop another discrete-time signal, called the output signal, with more
desirable properties. In certain applications, it may be necessary to extract some key properties of
the original signal using specific digital signal processing algorithms. It is also possible to investigate
the properties of a discrete-time system by observing the output signals for specific input signals.
GENERATION OF UNIT IMPULSE SEQUENCE
We know the properties of unit impulse, it has an Amplitude of 1 at point 0 and it’s zero
everywhere else.
1- Declare the overall length of the workspace
2- Write down the commands for unit impulse
clf;
close all;
clear all;
% GENERATION OF UNIT IMPULSE
% u = [1 zeros(1,N-1)] >>N:6
n = -10:20;
u = [zeros(1,10) 1 zeros(1,20)];
subplot(3,1,1);
stem(n,u,'k');
grid on;
title('Unit Impulse');
axis([-10 20 0 1.2]);
clf;
close all;
clear all;
% Delay it by M=2 units => ud=[zeros(1,M) 1 zeros(1,N-M-1)]
ud = [zeros(1,20) 1 zeros(1,10)];
subplot(3,1,2);
stem(n,ud,'r');
grid on;
title('Unit Impulse');
axis([-10 20 0 1.2]);
in the two programs above, we have used the command stem which is used to plot a
function in discrete-time domain and the command axis which is used to Set axis limits
and aspect ratios.
▪ ADVANCEINING the sequence by 10 units:
n=-10:20;
ua=[zeros(1,5) 1 zeros(1,25)];
subplot(3,1,3);
stem(ua,'r');
grid on;
title('Unit Impulse ADVANCED);
axis([-10 30 0 1.2]);
Unit step is a sequence which has an amplitude of 1 for 0 and any value greater
than 0.
1- Declare the overall length
2- Type down the unit step codes.
clf;
n = -10:20;
s = [zeros(1,10) 1 ones(1,10)];
subplot(2,1,1);
stem(n,s,'b');
grid on;
title('Unit_STEP');
axis([-10 20 0 1.2]);
- Delaying the sequence by 10 units:
n = -10:20;
sd = [zeros(1,20) 1 ones(1,10)]
subplot(2,1,2);
stem(n,sd,'k');
title('Delayed Unit STEP');
axis([-10 20 0 1.2]);
n = -10:20;
sd = [zeros(1,0) 1 ones(1,30)]
subplot(3,1,3);
stem(n,sd,'r');
title('ADVANCED Unit STEP');
axis([-10 20 0 1.2]);
There are two types of exponential sequences, Real Exponential sequence, and Complex
Exponential sequence .
𝑋 = 𝐾 × 𝑎. ^𝑛
The required codes for generation of the real exponential sequence is as following:
clc;
clear all;
close all;
n = 0:35;
a = 0.9;
k = 2;
x = k*a.^+n;
stem(n,x);
xlabel('Time Index n');
ylabel('Amplitude');
title('Real Exponential Sequence')
a = 1.1 a=2
a = -0.9
a = -1.3
clc;
clear all;
close all;
c = -(1/12)+(pi/6)*i;
k = 2;
n = 0:40;
x = k*exp(c*n);
subplot(2,1,1);
stem(n,real(x));
xlabel('Time index n');
ylabel('Amplitude');
title('Real part');
subplot(2,1,2);
stem(n,imag(x));
xlabel('Time index n');
ylabel('Amplitude');
title('imaginary part');