Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views18 pages

System Level Report-1

The document outlines a project focused on analyzing and implementing basic signal processing operations on an audio signal using MATLAB. Various operations such as time shifting, time scaling, amplitude scaling, and audio reversing are explored, with user interaction for selecting operations. The project demonstrates how these manipulations can significantly alter audio characteristics, providing practical insights into signal processing concepts.
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)
22 views18 pages

System Level Report-1

The document outlines a project focused on analyzing and implementing basic signal processing operations on an audio signal using MATLAB. Various operations such as time shifting, time scaling, amplitude scaling, and audio reversing are explored, with user interaction for selecting operations. The project demonstrates how these manipulations can significantly alter audio characteristics, providing practical insights into signal processing concepts.
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/ 18

SIGNAL PROCESSING - I (23ECE183)

System Level Design – I

Analysis and Implementation of Signal

Operations on an Audio Signal

Submitted by -
Sai Haasini Ravinuthala
(BL.EN.U4ECE24151)

Department of Electronics and Communication Engineering


Amrita School of Engineering, Amrita Vishwa Vidyapeetham,
Bengaluru -560035

Page 1 | 18
Aim:
To perform and analyze basic signal processing operations—such as time shifting, time scaling,
amplitude scaling, etc.—on an audio file and study their effects on the audio signal's
characteristics.

MATLAB Code:
Main Code (Code for User Input)
clc
clear
close all

[x, Fs] = audioread('nsync1.mp3');


t = 0 : 1/Fs : (length(x)-1)/Fs;
x_flat = reshape(x, [1, 3299328]);
x_new = x_flat(:, 1:1649664);

plot(t, x_new)
title("Original audio")
xlabel('t')
ylabel('audio')
sound(x_new, Fs)
disp('Performing signal operations:')

a = 0;
while a == 10
disp('Please select one of the following:')
disp('Please choose 1 to change tempo (time scaling)')
disp('Please choose 2 to increase/decrease volume (amplitude scaling)')
disp('Please choose 3 to delay the audio (time shifting)')
Page 2 | 18
disp('Please choose 4 to perform reversing audio')
disp('Please choose 5 to perform addition of audios')
disp('Please choose 6 to change tempo and pitch (frequency scaling)')
disp('Please choose 7 to perform time shifting and scaling together')
disp('Please choose 8 to subtract two signals')
disp('Please choose 9 to multiply two signals')
disp('Please choose 10 to STOP')

a = input('Enter your choice: ');


switch a
case 1
scalingFactor = input('Enter the scaling factor: ')
y = time_scaling(x_new, scalingFactor);
t1 = 0:1/Fs:(length(y)-1)/Fs;
plot(t1, y)
title("Time scaling")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 2
scalingFactor = input('Enter the scaling factor: ')
y = amplitude_scaling(x_new, scalingFactor);
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Amplitude scaling")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 3

Page 3 | 18
delayFactor = input('Enter the delay factor: ')
x_shift = shifting(x_new, delayFactor);
t_shift = 0:1/Fs:(length(x_shift)-1)/Fs;
plot(t_shift, x_shift)
title("Time delay")
xlabel('t')
ylabel('audio')
sound(x_shift, Fs)
case 4
y = audioreverse(x_new)
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Audio reversing")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 5
y = addition(x_new, audioreverse(x_new))
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Addition of audios")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 6
scalingFactor = input('Enter the scaling factor')
sound(x_new, scalingFactor*Fs)
case 7
scalingFactor = input('Enter the scaling factor')

Page 4 | 18
shiftingFactor = input('Enter the shifting factor')
y = shifting_scaling(shiftingFactor, scalingFactor, x_new)
plot(t1, y)
title(Shifting and Scaling Simultaneously)
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 8
y = subtraction(x_new, audioreverse(x_new))
sound(y, Fs)
title('Subtraction of audios')
xlabel('t')
ylabel('audio')
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
case 9
y = multiplication(x_new)
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Multiplication of audios")
xlabel('t')
ylabel('audio')
sound(y, Fs)

end
end

Functions:
% Time Scaling

Page 5 | 18
function x = time_scaling(vector, scalingFactor)
x = stretchAudio(vector', scalingFactor);
end

% Amplitude Scaling
function x = amplitude_scaling(vector, scalingFactor)
x = vector.*scalingFactor;
end
% Addition of Signals
function x_add = addition(x, x_new)
x_add = x+x_new;
end

% Reversing the Audio


function x = audioreverse(vector)
x=fliplr(vector);
end

% Time Shifting
function x_shift = shifting(x_new, t0)
Fs = 44100;
N = round(Fs*t0);
x_shift = [zeros(1,N),x_new];
end

% Shifting and Scaling


function x = shifting_scaling(t0, scalingFactor, x_new)
Fs = 44100;
N = round(Fs*t0);

Page 6 | 18
x = stretchAudio([zeros(1,N),x_new]', scalingFactor);
end

% Multiplication of Signals
function x_m = multiplication(x_new)
x_m = x_new.*audioreverse(x_new);
end
Analysis:
The chosen audio signal is "nsync1.mp3" which is assigned to variable ‘x’.
Analysis for the main code:
[x, Fs] = audioread('nsync1.mp3')
t = 0 : 1/Fs : (length(x)-1)/Fs;
x_flat = reshape(x, [1, 3299328]);
x_new = x_flat(:, 1:1649664);
plot(t, x_new)
title("Original audio")
xlabel('t')
ylabel('audio')
sound(x_new,Fs)
●​ The code reads an audio file named "nsync1.mp3" and converts its content into a
one-dimensional array representing the audio samples. It then extracts the first half of
these samples, assigning them to a new variable called ‘x_new’. Finally, ‘x_new’ is
plotted corresponding to the time vector, which defines the duration of the extracted
audio signal, and played at the back.

a = 0;
while a == 10
disp('Please select one of the following:')
disp('Please choose 1 to change tempo (time scaling)')
disp('Please choose 2 to increase/decrease volume (amplitude scaling)')
disp('Please choose 3 to delay the audio (time shifting)')
Page 7 | 18
disp('Please choose 4 to perform reversing audio')
disp('Please choose 5 to perform addition of audios')
disp('Please choose 6 to change tempo and pitch (frequency scaling)')
disp('Please choose 7 to perform time shifting and scaling together')
disp('Please choose 8 to subtract two signals')
disp('Please choose 9 to multiply two signals')
disp('Please choose 10 to STOP')
●​ Displays the options for the user to perform the various signal operations (time scaling,
amplitude scaling, time shifting, reversing the audio, addition, shifting and scaling
together, frequency scaling and multiplication of signals) on the audio signal. It also gives
the user an option to stop the program and exit the loop.

a = input('Enter your choice: ');


●​ The user is prompted to input a choice number to carry out their preferred signal
operation on the audio signal.
switch a
case 1
scalingFactor = input('Enter the scaling factor: ')
y = time_scaling(x_new, scalingFactor);
t1 = 0:1/Fs:(length(y)-1)/Fs;
plot(t1, y)
title("Time scaling")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 2
scalingFactor = input('Enter the scaling factor: ')
y = amplitude_scaling(x_new, scalingFactor);
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)

Page 8 | 18
title("Amplitude scaling")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 3
delayFactor = input('Enter the delay factor: ')
x_shift = shifting(x_new, delayFactor);
t_shift = 0:1/Fs:(length(x_shift)-1)/Fs;
plot(t_shift, x_shift)
title("Time delay")
xlabel('t')
ylabel('audio')
sound(x_shift, Fs)
case 4
y = audioreverse(x_new)
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Audio reversing")
xlabel('t')
ylabel('audio')
sound(y, Fs)
case 5
y = addition(x_new, audioreverse(x_new))
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Addition of audios")
xlabel('t')
ylabel('audio')
sound(y, Fs)

Page 9 | 18
case 6
scalingFactor = input('Enter the scaling factor')
sound(x_new, scalingFactor*Fs)
case 7
scalingFactor = input('Enter the scaling factor')
shiftingFactor = input('Enter the shifting factor')
y = shifting_scaling(shiftingFactor, scalingFactor, x_new)
sound(y, Fs)
case 8
y = subtraction(x_new, audioreverse(x_new))
sound(y, Fs)
title('Subtraction of audios')
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
case 9
y = multiplication(x_new)
t1 = 0 : 1/Fs : (length(y)-1)/Fs
plot(t1, y)
title("Multiplication of audios")
xlabel('t')
ylabel('audio')
sound(y, Fs)
end
end
The switch statement executes different audio processing operations based on user input a:
●​ Case 1 – Time Scaling:​
Calls the function ‘time_scaling(vector, scalingFactor)’ and then displays a plot of the
modified audio and plays it back.

Page 10 | 18
●​ Case 2 – Amplitude Scaling:​
Calls the function ‘amplitude_scaling(vector, scalingFactor)’ and then plots and plays the
resultant audio.
●​ Case 3 – Time Shifting:​
Calls the function ‘shifting(x_new, t0)’ and then plots and plays the shifted signal.
●​ Case 4 – Audio Reversing:​
Calls the function ‘audioreverse(vector)’ and then plots and plays the reversed audio
signal.
●​ Case 5 – Addition:
Calls the function ‘addition(x, x_new)’, then plots the output signal and plays the
resultant audio.
●​ Case 6 – Playback Speed Change:​
Changes the playback speed by modifying the sampling rate (scaling Fs), i.e., the
frequency is scaled by a scaling factor entered by the user.
●​ Case 7 – Shifting and Scaling:
●​ Calls the function ‘shifting_scaling(shiftingFactor, scalingFactor, x_new)’, then displays
a plot of the shifted and scaled audio and plays it back.
Case 8 – Subtraction:
Calls the function ‘subtraction(x_new, audioreverse(x_new))’ , then plots the output
signal and plays the resultant audio.
●​ Case 9 – Multiplication:​
Calls the function ‘multiplication(x_new)’, then plots and plays the result.

Analysis of the defined functions:

%Time Scaling
function x = time_scaling(vector, scalingFactor)
x = stretchAudio(vector', scalingFactor);
end
●​ The function ‘time_scaling(vector, scalingFactor)’ adjusts audio playback speed based on
a user-provided scaling factor, either compressing or stretching it.
%Amplitude Scaling

Page 11 | 18
function x = amplitude_scaling(vector, scalingFactor)
x = vector.*scalingFactor;
end
●​ The function ‘amplitude_scaling(vector, scalingFactor)’ adjusts the volume of the audio
by multiplying with a scaling factor entered by the user.
%Addition of Signals
function x_add = addition(x, x_new)
x_add = x+x_new;
end
●​ The function ‘addition(x, x_new)’ adds the original and reversed audio signals.
% Subtraction of Signals
function x_sub = subtraction(x, x_new)
x_sub = x-x_new;
end
●​ The function ‘subtraction(x, x_new)’ subtracts the original and reversed audio signals.
%Reversing the Audio
function x = audioreverse(vector)
x=fliplr(vector);
end
●​ The function ‘audioreverse(vector)’ reverses the audio signal in time, i.e. plays it
backward. This operation can also be seen as scaling the time of the signal by a factor of
(-1) (flipping it along the y – axis).

%Time Shifting
function x_shift = shifting(x_new, t0)
Fs = 44100;
N = round(Fs*t0);
x_shift = [zeros(1,N),x_new];
end
●​ The function ‘shifting(x_new, t0)’ delays or advances the audio in time by a given delay
factor fed by the user.
Page 12 | 18
% Shifting and Scaling
function x = shifting_scaling(t0, scalingFactor, x_new)
Fs = 44100;
N = round(Fs*t0);
x = stretchAudio([zeros(1,N),x_new]', scalingFactor);
end
●​ The function ‘shifting_scaling(t0, scalingFactor, x_new)’ delays or advances the audio,
i.e. shifts it in time by a given delay factor fed by the user. It then scales the shifted audio
by a scaling factor provided by the user.
%Multiplication of Signals
function x_m = multiplication(x_new)
x_m = x_new.*audioreverse(x_new);
end
●​ The function ‘multiplication(x_new)’ multiplies the original and reversed audio signals.

Page 13 | 18
Output (Plots):
Original Audio:

Time Scaling:
Scaling factor – 2

Page 14 | 18
Amplitude
Scaling:
Scaling factor – 5
units

Time Shifting:
Delay factor – 10 seconds

Page 15 | 18
Shifting and Scaling:
Delay factor – 10 seconds
Scaling factor – 2 units

Audio Reversing:
Scaling factor

Page 16 | 18
Signal Addition:

Signal Subtraction:

Page 17 | 18
Multiplication of Signals:

Conclusion:
This project has demonstrated fundamental signal processing operations on an actual audio
signal, such as time scaling, amplitude scaling, time shifting, reversing, and extraction of even
and odd components.
Each transformation highlighted how basic manipulations can significantly alter the perception
and characteristics of audio. Through interactive MATLAB implementation, the project provided
practical insights into the behavior of signals under different operations, reinforcing theoretical
concepts with hands-on experimentation.

Page 18 | 18

You might also like