Engineering Assignment Sample
Engineering Assignment Sample
Ele3107-signal processing
Assignment 1
Submitted by
?????????
????????
1
Contents
Question1 3
Question2-Part a 4
Question2-Part b 6
Question3 7
Question4 8
2
Question 1
Part a
Quantizing is done by dividing by 2|𝑘| where k is number of bits to be removed from the sample.
This can be done by bitshift function in Matlab every time by one bit to the right, and doing this for 15
times.
Part b
We calculate the RMS of original audio and for each quantized version of it, and SNR is the division of
RMS of original audio by the RMS of noisy audio.
Matlab code
%% Q1 part a
closeall;
clear;clc;
fs = 8000;
tmax = 2;
nbits = 16;
nchan = 1;
Recorder = audiorecorder(fs, nbits, nchan);
record(Recorder);
pause(tmax);
stop(Recorder);
3
yi = getaudiodata(Recorder,'int16');
outData(:,1) = yi; % original one before quantizing
%playSound(yi,fs);
for i = 2 : nbits
outData(:,i) = bitshift(yi, -1);
yi = outData(:,i);
%playSound(yi,fs); % you should put break point at this line to listen for
every quantized record
end
Q2
Part a
4
Varying delay and attenuation factor results in:
- Sometimes it causes specific part of the audio file to be repeated continuously until audio ends
while the audio file is played normally
- Sometimes it causes echoed voices to interact with each other because delay frequency is less
than nyqiust rate
- Sometimes voice is clearer than others depending on chosen values
Matlab code
%% Q2 part a
closeall;
clear;clc;
5
Part b
The difference between both lies in the period of delay in which the output y is zero so nothing is
actually added to the output in this period
However when using x with the delay, then by default it will affect the output because their values
won’t be all zeros.
Matlab code
%% Q2 part b
%close all;
figure
clear;clc;
6
for i = D + 1 : 1 : xlen;
y(i) = x(i) + a*x(i-D);
end;
sound(y, fs); %play the echo signal
subplot(2,1,2);
plot(y)
xlabel('echoed')
Q3
Part a
Omega: how frequent the wave oscillates and come back to specific point again
fs: sampling frequency, represents steps in frequency domain at which function value is calculated
𝜋
0 𝜔 10
True frequency = 2∗𝜋 = 2∗𝜋
= 0.05 𝐻𝑧
Part b
Fs = 8000;
n = 0:1/Fs:4;
x = 1.2*sin(pi*n/10);
subplot(2,1,1);
plot (n,x,'.')
ylim([-2 2])
v = wgn(length(n),1,0);
y = x' + (0.2 * v);
subplot(2,1,2);
plot (n,y,'.')
ylim([-2 2])
Q4
1 1 𝑐 + 𝑏 ∗ 𝑒 𝑗𝜔
2 = ∗
1 − (𝑝 + 𝑝∗ ) ∗ 𝑒 −𝑗𝜔 + 𝑝 ∗ 𝑝∗ 𝑒 −𝜔 𝑐 − 𝑏 ∗ 𝑒 −𝑗𝜔 𝑐 + 𝑏 ∗ 𝑒 𝑗𝜔
𝑐 + 𝑏(cos(𝜔) + 𝑗𝑏𝑠𝑖𝑛(𝜔)
=
𝑐 2 − 𝑏2
𝑐 + 𝑏𝑐𝑜𝑠(𝜔)
𝐴 = 𝑅𝑒(𝐻(𝜔)) =
𝑐 2 − 𝑏2
𝑗𝑏𝑠𝑖𝑛(𝜔)
𝐵 = 𝐼𝑚(𝐻(𝜔)) =
𝑐 2 − 𝑏2
Where
2
𝑐 = 1 + 𝑝 ∗ 𝑝∗ 𝑒 −𝜔 && 𝑏 = 𝑝 + 𝑝∗
|𝐻(𝜔)| = √𝐴2 + 𝐵2
𝐵
∠H(ω) = tan−1
𝐴
8
Matlab code
%% Q4 part a
closeall;
clear; clc;
r = 0.95;
w = pi/10;
p = r * exp(1i*w);
pp = r * exp(-1i*w);
Fs = 8000;
n = 0:1/Fs:4;
x = 1.2*sin(pi*n/10);
y = filter(B,A,x);
subplot(2,1,1);
plot (n,x,'.')
subplot(2,1,2);
plot (n,y,'.')
%% Q4 part b
closeall;
clear; clc;
r = 0.95;
w = pi/10;
p = r * exp(1i*w);
pp = r * exp(-1i*w);
Fs = 8000;
n = 0:1/Fs:4;
x = 1.2*sin(pi*n/10);
y = filter(B,A,x);
freqz(B,A);
figure
subplot(2,1,1);
plot (n,x,'.')
subplot(2,1,2);
plot (n,y,'.')
9
10