Lab3 PDF
Lab3 PDF
Section:_____C________________________ Semester:___5th
____________
Objectives
This Lab experiment has been designed to introduce students to signal transformations using
MATLAB
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.
You will need to provide plots of the original, flipped, compressed and expanded audio signals.
iii)
sound(ud,Fs/2);
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 factor while output should be the
shifted signal. Please make sure that the indices accompanying the shifted signal are
correct.
Attach a screenshot of the figure generated by your function for the input values of n = 4. Also copy
the function code to your report.
CODE:
1
𝑥𝑒 [𝑛] = [𝑥[𝑛] + 𝑥[−𝑛]]
2
1
𝑥𝑜 [𝑛] = [𝑥[𝑛] − 𝑥[−𝑛]]
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 code and the figures into the report.
subplot(311);stem(x)
title("original discrete signal")
subplot(312);stem(odd)
title("odd sequence")
subplot(313);stem(even)
title("even sequence")
end
d) Image Transformation:
v) Load the file ‘image.jpg’ in Matlab. Display the image. Assuming that each row is a
separate signal perform time reversal of each row. Now display the image again.
Use the following commands:
▪ For loading the image: img=imread(‘filename.extension’);
▪ For displaying the image: imagesc(img);
▪ For finding the dimensions of the image: [height width channels]=size(img);
▪ To access each channel separately, try this: output(:,:,1)=input(:,:,1). This means
that we are copying rows and columns of the blue channel from input to output.
CODE;
img = imread('ynwa.jpg');
%imagesc(img);
[height,width,channels] = size(img)
output(:,:,:) = img(:,:,:);
for c = 1:channels
for row = 1:height
output(row,:,c) = fliplr(img(row,:,c));
end
end
figure
imagesc(output);
title('Time reversed image');
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.
CONCLUSION:
We learned how to plot and code scripts for even and odd functions. We learned how to handle audio
and image files and do operations like time shift and channel selection on them.
We learned how to transform images. We also made functions implementing time shift on discrete
signals