Signal Lab Assignment 4
Signal Lab Assignment 4
ABBOTTABAD CAMPUS
Registration No FA23-BEE-057
Submitted To USMAN ALI
Submission Date 5/29/2025
Section EEE-4A
Marks :-
A P C
Total Marks
Obtain Marks
L.4. Transformation of Independent
Variables with application to Sound Signal
OBJECTIVE:
This Lab will enable you to understand the concept of Linear transformations of
independent variables already covered in the Theory lecture more clearly. You will apply
these transformations directly to sound signals and see how each transformation changes
a sound signal
BACKGROUND:
In the lab, you were introduced to fundamental signal generation techniques in MATLAB,
along with methods for reading and writing data in various formats, and essential plotting
techniques. The post-lab tasks from earlier sessions are foundational and play a critical role
in understanding the remaining labs in this course. If you have any doubts, it is
recommended to review those materials. You are expected to independently carry out any
assigned tasks. This lab focuses on enhancing your understanding of linear transformations
of independent variables, as discussed in the theory lectures. You will apply these
transformations directly to audio signals and observe how each one affects the sound.
Time Shifting: Moves a signal left (advance) or right (delay) along the time axis. It's
represented as x(t±t0), where t0 is the shift amount.
Time Scaling: Compresses (∣a∣>1) or expands (∣a∣<1) a signal horizontally along the
time axis. It's represented as x(at), where a is the scaling factor.
Time Reversal: Flips a signal horizontally (mirrors it) across the vertical axis (t=0). It's
represented as x(−t).
❖ Post-Lab tasks:
Q1. You used several built-in functions in the In-lab task 2 for signal shifting, scaling and
inversion. You are required to code a system which takes the independent variable
transformations to be performed on an audio signal from the user and then transforms them
using function defined by you.
This needs to be done without using any built-in command to achieve the transformation
directly. For example in order to achieve a compressor, where we simply need to delete
samples, you may use a line signal(a:a:end) = [], and achieve the same task which we did
using downsample() function.
You need to code your own functions which achieve the same functionality as that of the
built-in functions. Submit the code for functions as well as the main file along with plots of
a sound signal. Note|: The sound signal should be different than the one used for In-Lab
tasks.
Ans:
• Steps to Implement:
1. Signal Input Handling: Load an audio signal from a different source than used in the
In-lab tasks.
2. Transformation Functions: Define custom functions for shifting, scaling, and
inversion.
3. Expansion without upsample: Create your own function to duplicate samples
instead of using built-in methods.
4. Plotting and Sound Playback: Visualize the results and confirm functionality via
playback.
clc close all
clear all
x = [1 2 3 4 5 6 7 8 9 10]; shift = input('Enter the shift value:
'); scale = input('Enter the scale value: '); invert =
input('Invert the signal? (1 for yes, 0 for no): '); if shift ~= 0 x
= [x(shift+1:end) zeros(1, abs(shift))];
end if scale
~= 1 x = x *
scale;
end
if invert == 1
x = -x; end
figure;
subplot(2, 1,
1); plot([1 2 3
4 5 6 7 8 9
10]);
title('Original
signal');
xlabel('Sampl
e');
ylabel('Amplitude'); subplot(2, 1,
2); plot(x);
title('Transformed
signal');
xlabel('Sample'); ylabel('Amplitude');
Original signal
10
0
1 2 3 4 5 6 7 8 9 10
Sample
Transformed signal
0
-20
-40
-60
-80
1 2 3 4 5 6 7 8 9 10
Sample
Q2. What do the following MATLAB function do, Explain each with the inputs and an
example.
heaviside(), flipud(), fliplr, rot90, downsample(), upsample(), audiowrite(), audioread()
Answer:
Heaviside Function The Heaviside function, also known as the unit step function, is a
discontinuous function that returns 0 for negative inputs, 1 for positive inputs, and 0.5 for
zero inputs.
CODE:
clc close
all clear all
x=-
5:0.1:5;
y = heaviside(x); plot(x, y);
xlabel('x');
ylabel('Heaviside(x)'); title('Heaviside
Function');
Heaviside Function
1
0.9
0.8
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
-5 -4 -3 -2 -1 0 1 2 3 4 5
x
Flipud Function The flipud function flips a matrix or array upside down, i.e., it reverses
the order of the rows.
A = [1 2 3; 4 5 6; 7 8 9];
B = flipud(A);
disp(B);
Fliplr Function The fliplr function flips a matrix or array left to right, i.e., it
reverses the order of the columns.
Clc
close
all
clear
all
A = [1 2 3; 4 5 6; 7 8 9];
B = fliplr(A);
disp(B);
clc
close
all
clear
all
A = [1 2 3; 4 5 6; 7 8 9];
B = rot90(A); disp(B);
Downsample Function
The downsample function reduces the sampling rate of a signal by discarding samples.
x = 0:0.01:10; y =
downsample(x,1);
plot(x, y);
xlabel('x');
ylabel('Downsampled x'); title('Downsample Function');
Downsample Function
10
0
0 1 2 3 4 5 6 7 8 9 10
x
Upsample Function The upsample function increases the sampling rate of a signal by
inserting zeros between the samples.
x = 0:0.01:10;
y = upsample(x, 2); plot(x, y);
xlabel('x');
ylabel('Upsampled x');
title('Upsample Function');