Digital Signal Processing Lab1
Digital Signal Processing Lab1
Lab 1
Page |0
Task 1:
Write a MATLAB program to generate the following sequences and plot them using the
function stem.
MATLAB Code:
a) Unit Sample Sequence s[n]
%Plot the unit sample sequence
I = [zeros(1,5) 1 zeros(1,5)]
t = -5 : 1 : 5;
stem (t,I)
I = [zeros(1,5) 1 ones(1,5)]
t = -5 : 1 : 5;
stem (t,I)
Results:
a) Unit Sample Sequence s[n]
Page |1
b) Unit Step Sequence u[n]
Task 2:
Using the function sawtooth and square, write a MATLAB program to generate sawtooth
wave and square wave. The input parameters specified by the user are the desired length L of
the sequence, peak value A, and period N. Also, duty cycle for square wave. Using this
program, generate the first 100 samples of the sequences with sampling rate of 20 kHz, peak
value 7, period of 13 and 60% duty cycle for square wave.
Page |2
MATLAB Code:
a) Sawtooth wave
desired_length = input (' Enter desired_length =')
Peak_value = input (' Enter Peak_value =')
period = input (' Enter period =')
frequency = 1/period;
sampling_rate = input (' Enter sampling rate ');
t = 0: 1/sampling_rate :desired_length;
x = Peak_value * sawtooth(2*pi*frequency*t);
plot (t,x)
b) Square wave
desired_length = input (' Enter desired_length =')
Peak_value = input (' Enter Peak_value =')
period = input (' Enter period =')
Duty_cycle = input(' Enter Duty_cycle =')
frequency = 1/period;
sampling_rate = input (' Enter sampling rate ');
t = 0: 1/sampling_rate :desired_length;
x = Peak_value * square (2*pi*frequency*t, Duty_cycle );
plot (t,x)
Results:
a) Sawtooth wave
Page |3
a) Square wave
Task 3:
Write a program to generate and plot the complex exponential equation
𝜋⁄ )𝑛
2.5 𝑒 (−0.4+𝑗 5 for 0 ≤ n ≤ 100.
Show real and imaginary plots.
MATLAB Code:
% Generation of a complex exponential equation
n=0: 0.5 :100;
power = -0.4+(pi/5)*i;
x=2.5* exp(power*n);
subplot(2,1,1)
stem(n,real(x));
title('Real part');
xlabel('Time ');
ylabel('Real Part');
subplot(2,1,2)
stem(n,imag(x));
title('Imaginary part');
xlabel('Time ');
ylabel('Imaginary Part');
Page |4
Results:
Task 4:
Write a MATLAB program to generate and display five sample sequences of random
sinusoidal signal of length 31.
𝑥[𝑛] = 𝐴. 𝑐𝑜𝑠(𝜔𝑜 𝑛 + 𝜑)
Page |5
Where input data specified by the user are the desired length L, amplitude A, angular
frequency 𝜔𝑜 and the phase 𝜑, where 0 ≤ 𝜔𝑜 ≤ 𝜋 and 0 ≤ 𝜑 ≤ 2𝜋.
Generate sequences for:
Part A 𝝎𝒐 𝝋
a) 1.5 0 0
b) 1.5 0.1π 0
c) 1.5 1.2 π 0
d) 2 1.8 π 0
e) 2 1.2 π 0.1 π
f) 2 1.8 π 0.1 π
MATLAB Code:
desired_length = input (' Enter desired_length =')
Amplitude = input (' Enter Amplitude =')
angular_frequency = input (' Enter angular_frequency =')
Phase = input (' Enter Phase ');
n=0: desired_length;
x_n= Amplitude*cos(angular_frequency*n+Phase)
stem (n,x_n)
Results:
Part A 𝝎𝒐 𝝋
a) 1.5 0 0
Page |6
Part A 𝝎𝒐 𝝋
b) 1.5 0.1π 0
Part A 𝝎𝒐 𝝋
c) 1.5 1.2 π 0
Page |7
Part A 𝝎𝒐 𝝋
d) 2 1.8 π 0
Part A 𝝎𝒐 𝝋
e) 2 1.2 π 0.1 π
Page |8
Part A 𝝎𝒐 𝝋
f) 2 1.8 π 0.1 π
Conclusion:
Given tasks are done by writing MATLAB codes. Codes and figures of results are attached
under each task.
Page |9