Lab 04
Lab 04
clear all
clc
n=-200:200;
h=zeros(1,401);
h(1,[201 202 203 204 205 206])=1/6;
subplot(431);
stem(n,h);
title('time domain h[n]');
x=fft(h);
x1=fftshift(x);
f1=linspace(-pi/2,pi/2,401);
subplot(432);
plot(f1,abs(x1));
title('f-domain of h[n]');
%shifting by pi/2;
m1=2*cos((pi/2)*n);
z1=h.*m1;
n2=fft(z1);
n3=fftshift(n2);
fr3=linspace(-2,2,401);
subplot(4,3,3);
plot(fr3,abs(n3));
title('shifting by pi/2');
%shifting by pi;
m2=cos(pi*n);
z2=h.*m2;
x1=fft(z2);
x2=fftshift(x1);
f3=linspace(-pi,pi,401);
subplot(434);
plot(f3,abs(x2));
title('shifting by pi');
[y,Fs]=audioread('ali.mp3');
y=y(:,1);
N=length(y); %N is the number of samples
slength = N/Fs;%slength is the length of the sound file in seconds
t = linspace(0, N/Fs, N);
subplot(435);
plot(t,y);
title('time domain of audio');
w=fft(y);
w1=fftshift(w);
f1=(Fs/2)*linspace(-pi,pi,length(y));
subplot(436);
plot(f1,abs(w1));
title('f-domain of audio');
x=length(h)+length(y)-1;
n1=linspace(-4,5,x);
conv1=conv(h,y);
subplot(437);
plot(n1,conv1);
title('T- domain Convolution of audio and filter');
f2=(Fs/2)*linspace(-1,1,length(conv1));
y5=fft(conv1);
z5=fftshift(y5);
subplot(4,3,7);
plot(f2,abs(z5));
title('F-domain conv of h[n] and audio');
x=length(h)+length(y)-1;
x3=length(m1)+length(y)-1;
n3=linspace(-4,5,x3);
conv2=conv(m1,y);
subplot(4,3,8);
plot(n3,conv2);
title('t-dmain conv of audio and m1');
f3=(Fs/2)*linspace(-1,1,length(conv2));
y6=fft(conv2);
z6=fftshift(y6);
subplot(4,3,9);
plot(f3,abs(z6));
title('fourier transform of conv2');
x4=length(m2)+length(y)-1;
n4=linspace(-4,5,x4);
conv3=conv(m2,y);
subplot(4,3,10);
plot(n4,conv3);
title('T-Domain conv of audio and m2');
f4=Fs/2*linspace(-1,1,length(conv3));
y7=fft(conv3);
y8=fftshift(y7);
subplot(4,3,11);
plot(f4,abs(y8));
title('F-domain conv of audio and m2');