You are on page 1of 13

Department of Electrical Engineering

EE-232 Signals and Systems

Faculty Member: Sir Qazi Waqas Dated: 14th September,2023

Section: B Semester: 5th Semester

Lab 3 : Signal Transformations

PLO5/ PLO8/ PLO9/ CLO5


CLO3 CLO4

Modern Ethics and Individual


Tool Usage Safety and Team
Reg. No Work
Name

15 Marks 5 Marks 5 Marks

Muhammad Ahmad Nazir 370307

Zunaira Aziz 367583

Eaman Safdar 388110

EE-232 Signals and Systems Page 1


Lab3: Signal Transformations

Objectives
This Lab experiment has been designed to introduce students to signal transformations using
MATLAB

 How to perform time shifting


 How to perform time compression/expansion
 Even and Odd Signals

Lab Instructions
 The students should perform and demonstrate each lab task separately for step-wise
evaluation(please ensure that course instructor/lab engineer hasverified each step after
ascertaining its functional verification)
 Only those tasks that completed during the allocated lab time will be credited to the students.
Students are however encouraged to practice on their own in spare time for enhancing their
skills.

Lab Report Instructions


All questions should be answered precisely to get maximum credit. Lab report must ensure following
items:
 MATLAB codes
 Results (graphs/tables) duly commented and discussed
 Discussion on answers

EE-232 Signals and Systems Page 2


3.0 Pre-Lab Tasks
Use of Matlabto Flip, compress and expand an audio sequence in time:
i) Load the audio file titled “song.wav” using MATLAB. Play the audio file.
ii) Flip the audio sequence and play it back again. (Hint: The operation is time reversal).

Screenshot:

We used the flipud function in this to reverse the audio signal

iii) Next perform time compression on the flipped signal by a factor of 2. What does the
audio sequence sound like?
Screenshot:

We simply multiplied the sampling rate by a factor of 2.

iv) Perform time expansion by a factor of 2. What does the flipped audio sequence sound
like?
Hints: You may use the commands ‘fliplr’ ‘flipud’ for flipping the signal. Also the same can be achieved
using a for loop.

Screenshot:

EE-232 Signals and Systems Page 3


We simply divided the sampling rate by a factor of 2.

3.1 Basic trasformation of signals

a) Transformations of the Time Index for Discrete time signals:


i) Define a Matlab vector n,such that -3 ≤n < 7, representing time/sample indices of a
Discrete Time Signal x[n] such that :

Enter the Matlab command(s) through which you defined this vector

ii) Make a generalized function that can shift the signal x[n]by delaying or advancing it by
a specified amount.
*HINT (You can make use of ‘find’ command in Matlab).
The inputs to the function should be the data and shift while output should be the
shifted signal. Please make sure that the indices accompanying the shifted signal are
correct.

Screenshot:

We simply used the circumshift operator which is an in-built function in


MATLAB.

Output:

b) Use of Matlab command zeros and ones:

EE-232 Signals and Systems Page 4


iii) Implement the following function in Matlab. Your function should take k and n as input
from user.

u [ k−n ] =¿0 , k< n ¿


1 , k ≥n

Attach a screenshot of the figure generated by your function for the input values of n = 4. Also
copy

Screenshot:

Output:

c) Even and odd part of a signal:


iv) Every signal x[n] is sum of its even part and odd part. Given the signal x[n] find its even and
odd part.

EE-232 Signals and Systems Page 5


1 1
x e [ n ]= [x [ n ] + x [−n]], x o [ n ] = [ x [ n ] −x [−n]]
2 2

Write a function that will produce three figures. The first figure shall show the signal x[n] given above.
The second figure shall show the signal xe[n]. The third figure shall show the signal xo[n].

You should copy the contents of the function into this report and also copy the figures into this report.

Screenshot:

EE-232 Signals and Systems Page 6


EE-232 Signals and Systems Page 7
Output:

We were given a signal and then we decomposed that signal into its even
and odd signals by simply using the formulas we studied in the class.

EE-232 Signals and Systems Page 8


d) Image Transformation:
v) Load the file ‘image.jpg’ in Matlab. See the image. You should see a fighter throwing a
punch. Assuming that each row is a separate signal perform time reversal of each row.
Now see the image. The fighter is now throwing a punch with which hand?
Use the following commands:
For loading the image: img=imread(‘filename.extension’);
For seeing the image: imagesc(img);
For finding the dimensions of the image: [height width channels]=size(img);
To acess each channel separately try this output(:,:,1)=input(:,:,1). This means that we
are copying rows, columns of the Blue Channel to be copied from input to output.

Screenshot:

EE-232 Signals and Systems Page 9


Output:

Now the other opponent is throwing the punch with his left hand.

For upside image:

EE-232 Signals and Systems Page 10


Output:

3.2 Additional Tasks for Fun: Audio Signal based tasks:


i) Given an audio file and the functions developed above perform a mathematical
operation that will introduce echo in the song.

EE-232 Signals and Systems Page 11


To hear the echo louder, just increase the gain factor.

ii) Assume that you want to develop a system that loads a song and gives you control to
forward or rewind the song. For this you should load the song. The total time of the
song can be calculated by dividing the Total No of Samples / Sampling Frequency. Next
for each second, load the duration of song, play it, check if the user wants to forward or
rewind the song by pressing ‘r’ or ‘f’ (getkeywait(seconds)) and modify the samples
being used to play the song.

Screenshot:

EE-232 Signals and Systems Page 12


We developed a system that loads a song and give us control to forward or
rewind the song.

Conclusion:

In this lab, we performed time shifting and time compression operations as well. We
found out even and odd signals. This lab was all about dealing with audio signals.

EE-232 Signals and Systems Page 13

You might also like