Académique Documents
Professionnel Documents
Culture Documents
LAB 02
“Generating Discrete Time Signal, Performing Various Operations and
Convolution of discrete time signals”
Previous Lab:
In pervious labs students were introduced to matlab environment in depth, the process of help
about any function was explained in details, how to use apps, how to use plots, how to use similink,
how to publish a document, how to work in script file how to use comment in code for creating
sections.
Objective:
Prepared by Dr. Muhammad Bilal Qureshi ECE Dept CUI, ATD Page 1
Digital Signal Processing 2019
𝟑 𝜋 𝟕
𝑨 = 𝟏𝟐 + 𝒆𝒋 𝟐 + 𝟒 ∗
𝟐 𝟑 ∗ 𝟒√𝟒
𝜋 9
𝑩 = 𝒔𝒊𝒏 + 7 + ∗ 17
2 2
2. Write the MATLAB code for plotting the following basic sequences.
Note (There should be only one plot for each part, use subplot command if there are
multiple plots in a single part).
a) 𝒙[𝒏] = 𝜹[𝒏]
b) 𝒙[𝒏] = 𝒖[𝒏]
−𝟏 𝟐
c) 𝒙𝟏 [𝒏] = [ 𝟐 , 𝟏, 𝟒 , 𝟎, 𝟏, −𝟑, −𝟐], 𝒙𝟐 [𝒏] = [𝟎, 𝟏, 𝟒, 𝟑, −𝟏, −𝟐, −𝟑]
𝟑 𝝅
d) 𝒙𝟏 [𝒏] = 𝟐 𝐜𝐨𝐬 (𝝎𝒏 + 𝟐 ), 𝒇 = 𝟎. 𝟐𝟔𝒉𝒛, −𝟐𝟎 ≤ 𝒏 ≤ 𝟐𝟎
𝒙𝟐 [𝒏] = 𝟐 𝐜𝐨𝐬(𝝎𝒏 + 𝝅), 𝒇 = 𝟎. 𝟏𝟒𝒉𝒛, −𝟐𝟎 ≤ 𝒏 ≤ 𝟐𝟎
3. Check the syntax of writing functions in matlab’s help, then write the below mentioned
expression in matlab function to generate unit step sequence.
𝒔𝒊𝒈𝒏(𝒏 + 𝒆𝒑𝒔) + 𝟏
𝑢[𝑛] =
𝟐
4. Generate the following sequences using the command of ones and zeros without using
multiple statements.
Prepared by Dr. Muhammad Bilal Qureshi ECE Dept CUI, ATD Page 2
Digital Signal Processing 2019
𝟏 − 𝟐𝟎 ≤ 𝒏 ≤ −𝟏𝟎
−𝟏𝟐 − 𝟗 ≤ 𝒏 ≤ −𝟔
𝒙[𝒏] = 𝟑 − 𝟓 ≤ 𝒏 ≤ −𝟐
𝟏𝟎 𝒏 = −𝟏
{−𝟕. 𝟓 𝟎 ≤ 𝒏 ≤ 𝟐𝟎}
i) Ideal Delay
ii) Moving Average for any range
iii) Forward difference
iv) Backward difference
6. Write a matlab code to compute the sum of 𝒉[𝒏] = 𝟒𝒏 (𝒖[𝒏] − 𝒖[𝟏𝟎𝟎]) without using the
geometric series formula first and then verify the result with the help of formula.
7. Write a MATLAB code for plotting output y[n] of an LTI system for the following input and
impulse response: using convn with ‘same’ length and then repeat all for ‘full’ length
parameter. (Check the help of convn to see the difference between same and full length
convolution).
i) 𝒙[𝒏] = 𝒖[𝒏] 𝒉[𝒏] = 𝒂𝒏 𝒖[𝒏] − 𝟏𝟓 ≤ 𝒏 ≤ 𝟏𝟓 𝒘𝒉𝒆𝒓𝒆 𝒂 = 𝟎. 𝟕
𝒏
ii) 𝒙[𝒏] = −𝟎. 𝟕𝟓𝒖[𝒏] 𝒉[𝒏] = 𝒂 𝒖[−𝒏 − 𝟐] − 𝟏𝟓 ≤ 𝒏 ≤ 𝟏𝟓 𝒘𝒉𝒆𝒓𝒆 𝒂 = 𝟎. 𝟏𝟓
𝒏
iii) 𝒙[𝒏] = 𝟑𝒖[𝒏] − 𝟑𝒖[𝒏 − 𝟒] − 𝟏𝟎 ≤ 𝒏 ≤ 𝟏𝟎 𝒉[𝒏] = 𝟑 𝒖[𝒏] − 𝟒 < 𝒏 < 𝟒
For the generation of unit steps for above sequences use the generic function of unit step.
Each figure should contain the input sequence plot x[n], the impulse response plot h[n], same
length convolution plot y[n] and full length convolution plot y[n] respectively.
8. Write the generic matlab codes for the expansion and compression of following sequences.
i) 𝒙𝟏 [𝒏] = {−𝟐. 𝟓 𝟐 𝟏 𝟕 𝟑 𝟎. 𝟓 − 𝟓} Expand it with M=2 and Compress it with L=2
First plot the input sequence then plot the expanded version and after that the compressed
version and repeat the same for ii) part.
Prepared by Dr. Muhammad Bilal Qureshi ECE Dept CUI, ATD Page 3