0% found this document useful (0 votes)
11 views17 pages

Experiment No.5: Roll No. 52 Batch: T4

The document contains multiple experiments related to digital signal processing, including Inverse Discrete Fourier Transform (IDFT), FIR filters, and IIR filters. It provides MATLAB code for implementing these concepts, showcasing the magnitude and phase of signals, as well as the design of various filter types. Key outputs include filter characteristics and responses based on user-defined parameters.

Uploaded by

powarradha599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views17 pages

Experiment No.5: Roll No. 52 Batch: T4

The document contains multiple experiments related to digital signal processing, including Inverse Discrete Fourier Transform (IDFT), FIR filters, and IIR filters. It provides MATLAB code for implementing these concepts, showcasing the magnitude and phase of signals, as well as the design of various filter types. Key outputs include filter characteristics and responses based on user-defined parameters.

Uploaded by

powarradha599
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Experiment No.

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;

% low pass filter


b=fir1(n,wc);
[h,o]=freqz(b,1,256);
m=20*log10(abs(h));
subplot(2,2,1);
plot(o/pi,m);
xlabel('normalised frequency in Hz');
ylabel('gain in db');
title('low pass filter');
grid on;

% high pass filter


b=fir1(n, wc, 'high');
[h,o]=freqz(b, 1,256);
m=20*log10(abs (h));
subplot(2,2,2);
plot(o/pi,m);
xlabel('normalised frequency in Hz');
ylabel('gain in db');
title('high pass filter');
grid on;

% band pass filter


b=fir1(n,[wp, ws]);
[h,o]=freqz(b,1,256);
m=20*log10(abs (h));
subplot(2,2,3);
plot(o/pi,m);
xlabel('normalised frequency in Hz');
ylabel('gain in db');
title('band pass filter');
grid on:

% band reject filter


b=fir1(n,[wp.ws],'stop');
[h,o]=freqz(b, 1,256);
m=20*log10(abs (h));
subplot(2,2,2);
plot(o/pi,m);
xlabel('normalised frequency in Hz');
ylabel('gain in db');
title('band reject filter');
grid on;
output:

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

enter the length for window=


15
1.rectangular window
2.hanning window
3.hamming window
4.blackman window
5.kaiser window
enter your choice=
3
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
enter the length for window=
15
1.rectangular window
2.hanning window
3.hamming window
4.blackman window
5.kaiser window
enter your choice=
4
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
Experiment No.10
Roll no. 52
Batch: T4

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

enter the stopband ripple in db=

40

enter the sampling freq in Hz=

150
The order of filter n=

You might also like