Experiment No.5: Roll No. 52 Batch: T4
Experiment No.5: Roll No. 52 Batch: T4
5
Roll no. 52
Batch: T4
DFT
clc;
close all;
clear all;
N=input('enter the sequence N=');
Xk=input('enter x(k) =');
n=0:1:N-1;
L=length(Xk);
if (N<L)
error('N must be >= L' );
end;
x1=[Xk zeros(1, (N - L))] ;
for m=0:1:N-1
for k=0:1:N-1
Wn=exp((-1i*2*pi*m*n )/N);
x2(m+1,n+1)=Wn;
end;
XK='x1*x2/N';
end;
mag=abs(Xk);
subplot (2,1,1);
stem(n,mag, 'filled');
xlabel('TIME');
ylabel('AMPLITUDE');
title('MAGNITUDE OF IDFT');
grid on;
phase=angle(Xk);
subplot(2,1,2);
stem(n, phase, 'filled');
xlabel('TIME');
ylabel('AMPLITUDE');
title('PHASE OF IDFT')
grid on;
disp('magnitude of x(n) =' ) ;
disp(mag);
disp('phase of x(n) =' );
disp (phase);
Output
enter the sequence N=
4
enter x(k) =
[2 3 4 5]
magnitude of x(n) =
2 3 4 5
IDFT
clc;
close all;
clear all;
N=input('enter the sequence N=');
Xk=input('enter x(k) =');
n=0:1:N-1;
L=length(Xk);
if (N<L)
error('N must be >= L' );
end;
x1=[Xk zeros(1, (N - L))] ;
for m=0:1:N-1
for k=0:1:N-1
Wn=exp((-1i*2*pi*m*n )/N);
x2(m+1,n+1)=Wn;
end;
XK='x1*x2';
end;
mag=abs(Xk);
subplot (2,1,1);
stem(n,mag, 'filled');
xlabel('TIME');
ylabel('AMPLITUDE');
title('MAGNITUDE OF IDFT');
grid on;
phase=angle(Xk);
subplot(2,1,2);
stem(n, phase, 'filled');
xlabel('TIME');
ylabel('AMPLITUDE');
title('PHASE OF IDFT')
grid on;
disp('magnitude of x(n) =' ) ;
disp(mag);
disp('phase of x(n) =' );
disp (phase);
enter x(k) =
[1 2 3 4]
magnitude of x(n) =
1 2 3 4
phase of x(n) =
0 0 0 0
Experiment No.6
Roll no. 52
Batch: T4
FIR Filter
clc;
close all;
clear all;
% n=input(['enter the order of filter=");
% wc=input(']enter the cut off coefficient=');
% wp=input('enter the passband coefficients');
% ws=input('enter the stopband coefficient');
n=40;
wc=0.4;
wp=0.2;
ws=0.6;
Experiment No.8
Roll no. 52
Batch: T4
FIR Filter using Window
clc;
close all;
clear all;
S= input('enter the length for window=');
disp('1.rectangular window');
disp('2.hanning window');
disp('3.hamming window');
disp('4.blackman window');
disp('5.kaiser window');
choice=input('enter your choice=');
n= 1;
disp('output samples for window are as follows=');
switch(choice)
case(1)
b=rectwin(N);
freqz(b,a)
title('rectangular window');
case(2)
b=hann(N);
freqz (b,a)
title('hanning window');
case(3)
b=hamming(N);
freqz(b,a)
title('hamming window');
case(4)
b=blackman(N);
freqz(b,a)
title('blackman window');
case(5)
b=kaiser(N);
freqz(b,a)
title('kaiser window');
end
output
enter the length for window=
15
1.rectangular window
2.hanning window
3.hamming window
4.blackman window
5.kaiser window
enter your choice=
1
output samples for window are as follows=
1
1
1
1
1
1
1
1
1
1
1
1
1
1 1
enter the length for window=
15
1.rectangular window
2.hanning window
3.hamming window
4.blackman window
5.kaiser window
enter your choice=
1
output samples for window are as follows=
b=
0.0495
0.1883
0.3883
0.6113
0.8117
0.9505
1.0000
0,9505
0.8117
0.6113
0.3883
0.1883
0.0495
IIR Filter
clc;
close all;
clear all;
w=-input('enter the passband freq in rad/sec=');
Ap=input('enter the passband ripple in db=');
ws=input('enter the stopband freq in rad/sec=');
As=input('enter the stopband ripple in db=');
fs=input('enter the sampling freq in Hz=');
[n,wn]=buttord (wp, we, Ap, As,'s');
disp('The order of filter n=');
disp(n);
[num,den]=butter(n,wn, 's');
[b,a]=bilinear(num,den,fs);
freqz(b,a,512,fs);
grid on;
title('IIR Filter');
xlabel('freq (Hz)-->');
ylabel('gain (db)-->');
output:
enter the stopband freq in rad/sec=
40
40
150
The order of filter n=