Sns Lab 7 19-Ee-0
Sns Lab 7 19-Ee-0
SUBMITED TO
Engr. Hammad Haider
SUBMITED BY
Muhammad Uzair Shafique
(I) If >>x=cos(2*pi*2000*t)+1/2*sin(2*pi*4000*(t-pi/4))
+1/4*cos(2*pi*8000*t);
Take time t = 0: 1/Fs: 1-1/Fs; where Fs = 44.1kHz.
a) Listen to this signal using audioplayer (built in func. in
MATLAB)
MATLAB CODE:
%uzair Shafique
%19-EE-18
clc;
clear all;
%%Time specifications:
Fs = 44100; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.25; % seconds
t = (0:dt:1-dt)'; % seconds
% hertz
x1=cos(2*pi*2000*t);
x2=1/2*sin(2*pi*4000*(t-pi/4));
x3=1/4*cos(2*pi*8000*t);
x=x1+x2+x3;
p=audioplayer(x,Fs);
play(p);
plot(t,x);
xlabel('time (in seconds)');
zoom xon;
OUTPUT:
19-EE-18
b) Now use resample func. to implement x with Fs = 48kHz. Listen to
this again and compare it with previous. Also use subplot to plot both
signals. Give comments about their comparison.
MATLAB CODE:
%uzair Shafique
%19-EE-18
clc;
clear all;
%%Time specifications:
Fs = 44100; % samples per second
dt = 1/Fs; % seconds per sample
StopTime = 0.25; % seconds
t = (0:dt:1-dt)'; % seconds
% hertz
x1=cos(2*pi*2000*t);
x2=1/2*sin(2*pi*4000*(t-pi/4));
x3=1/4*cos(2*pi*8000*t);
x=x1+x2+x3;
p=audioplayer(x,Fs);
play(p);
%%Time specifications:
Fs1 = 48000; % samples per second
dt = 1/Fs1; % seconds per sample
StopTime = 0.25; % seconds
t1 = (0:dt:1-dt)'; % seconds
% hertz
x11=cos(2*pi*2000*t1);
x22=1/2*sin(2*pi*4000*(t1-pi/4));
x33=1/4*cos(2*pi*8000*t1);
y=x11+x22+x33;
p=audioplayer(y,Fs1);
play(p);
% Plot the signal versus time:
figure;
subplot(2,1,1);
plot(t,x);
subplot(2,1,2);
plot(t1,y);
xlabel('time (in seconds)');
zoom xon;
OUTPUT:
19-EE-18
MATLAB CODE:
clc;
clear all;
[x,Fs]=audioread('myrecording.M4A') ;
p=audioplayer(x,Fs);
play(p);
plot(x);
OUTPUT:
19-EE-18
Lab Task 2:
(i) Now listen to signal audioplayer(0.5*x, Fs) & audioplayer(2*x, Fs) in task 1(ii).
Again listen to same signal but with audioplayer(x, 2*Fs) & audioplayer(x, 0.5*Fs)
Comment on the different voices listen till now including this and last task 1(ii)
WITH (0.5*x,Fs)
MATLAB CODE:
%uzair Shafique
%19-EE-18
[x,Fs]=audioread('myrecording.M4A');
p=audioplayer(0.5*x,Fs);
play(p);
plot(x);
suptitle('19-EE-18');
OUTPUT:
19-EE-18
WITH (2*x,Fs)
MATLAB CODE:
%uzair Shafique
%19-EE-18
[x,Fs]=audioread('myrecording.M4A');
p=audioplayer(2*x,Fs);
play(p);
plot(x);
suptitle('19-EE-18');
OUTPUT:
19-EE-18
WITH (x,0.5*Fs)
MATLAB CODE:
%uzair Shafique
%19-EE-18
[x,Fs]=audioread('myrecording.M4A') ;
p=audioplayer(x,0.5*Fs);
play(p);
plot(x)
suptitle('19-EE-18');
OUTPUT:
19-EE-18
WITH (x,2*Fs)
MATLAB CODE:
%uzair Shafique
%19-EE-18
[x,Fs]=audioread('myrecording.M4A') ;
p=audioplayer(x,2*Fs);
play(p);
plot(x)
suptitle('19-EE-18');
OUTPUT:
19-EE-18
COMMENT
%When we develop 0.5*x, it speed down the signal.
%When we develop 2*x, it speed up the signal
%When we develop 0.5*Fs, frequency become low , voice become grind and time
duration also reduced
%When we develop 0.5*Fs, frequency become high, voice become shrill and time
duration also reduced
ii) Apply time shifting property to the audio signal imported in task 1
part (ii) to apply an “echo” as given in manual. Listen it to observe echo.
Scale both signal(x) and Fs to this echo signal as above in task 2 part i
and see the difference b/w these two. Comment on it.
MATLAB CODE:
%uzair Shafique
%19-EE-18
[x,Fs]=audioread('myrecording.M4A') ;
delay=0.5;
alpha=0.7;
D=delay*Fs;
y=zeros(size(x));
y(1:D)=x(1:D);
for n=D+1:length(x);
y(n)=x(n)+alpha*x(n-D); %Y[n] = x[n] + a* x[n-d] where d is delay in
time
end
q=audioplayer(y,Fs);
play(q);
subplot(2,1,1);
plot(x);
subplot(2,1,2);
plot(y);
xlabel('time (in seconds)');
zoom xon;
OUTPUT:
19-EE-18
LAB TASK 3:
i) creates a 5X5 matrix of random integers in the range from 1 to the
number of colors(take different values of r from 1 to 64 to see colors)
and display it by using image command
MATLAB CODE:
%uzair Shafique
%19-EE-18
clc;
clear all
C = [0 2 4 6 8;10 12 14 16 18;20 22 24 26 28;30 32 34 36 38;40 42 44 46 48];
image(C);
OUTPUT:
19-EE-18