0% found this document useful (0 votes)
4 views9 pages

Signal Lab Assignment 4

The lab assignment focuses on understanding linear transformations of independent variables applied to sound signals using MATLAB. Students are required to implement custom functions for signal shifting, scaling, and inversion without using built-in commands, and to visualize the results. Additionally, the assignment includes explanations of various MATLAB functions related to signal processing.

Uploaded by

dybwalker00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views9 pages

Signal Lab Assignment 4

The lab assignment focuses on understanding linear transformations of independent variables applied to sound signals using MATLAB. Students are required to implement custom functions for signal shifting, scaling, and inversion without using built-in commands, and to visualize the results. Additionally, the assignment includes explanations of various MATLAB functions related to signal processing.

Uploaded by

dybwalker00
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

COMSATS UNIVERSITY ISLAMABAD-

ABBOTTABAD CAMPUS

Department of Electrical & Computer Engineering

“Signal And System”

Lab Assignment No:- _1


Name ALI NAWAZ

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.

Transformation Mathematical Explanation


Representation
Time shift 𝑥(𝑡) → 𝑥(𝑡 − 𝑡0 ) Signal is displaced or
shifted either right (𝑡0 > 0)
𝑥[𝑛] → 𝑥[𝑛 − 𝑛0 ] ∀ 𝑛 ∈ Z
or left (𝑡0 < 0), relative to
the original signal e.g.,
introduce delay in an audio
file
Time scaling 𝑥(𝑡) → 𝑎𝑥(𝑡) ∀ 𝑎 > 0 Signal is compressed (𝑎 >
1) or expanded (0 < 𝑎 < 1),
𝑥[𝑛] → 𝑥[𝑎𝑛] ∀ 𝑎 > 0, 𝑛 ∈
e.g., playing and audio file
Z
with 3x or 0.5x speed.
Time reversal 𝑥(𝑡) → 𝑥(−𝑡) Independent variable is
replaced with its negative,
𝑥[𝑛] → 𝑥[−𝑛] ∀ 𝑛 ∈ Z
e.g., playing an audio
backwards

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);

Rot90 Function The rot90 function rotates a matrix or array by 90 degrees


counterclockwise.

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');

Audiowrite Function The audiowrite function writes audio data to a file.

clc close all


clear all
load
handel.mat
filename = 'handel.wav'; audiowrite(filename, y, Fs);
clear y Fs
Audioread Function The audioread function reads audio data from a file.

clc close all


clear all
[y, Fs] = audioread('ali.wav');

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy