Anda di halaman 1dari 66

Digital Signal Processing

INDEX
S.NO. DATE TOPIC PAGE SIGN

Basic Signals
1.      

Frequency, Magnitude and


2.      
Phase Response.
Z-Transform.
3.      
N-Point DFT.
4.      
N-Point DFT Using Twiddle matrix.
5.      
Linear Convolution.
6.      
Circular Convolution.
7.      
Low-Pass FIR Filter.
8.      
High-Pass FIR Filter.
9.      

Combination of High-pass &


10.      
Low-pass FIR filters.
Band-pass and Band-stop FIR filters.
11.      
Analog and Digital Filters.
12.      
Radix 2 DIF FFT Algorithm.
13.      
Radix 2 DIT FFT Algorithm.
14.      
Power Spectral Density.
15.      
Remez Exchange Algorithm.
16.      
2-D Linear Convolution.
17.      

2-D Cross-correlation and


18.      
Auto-correlation.
Stability.
19.      
Bit-Reversal Algorithm.
20.      

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

SECTION I

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 1

PROGRAM:

clc
clear all
close all
n=6; %Varible%

%To Generate Unit Impulse Siganl%


x=-2:1:2;
y=[zeros(1,2),ones(1),zeros(1,2)];
subplot(2,2,1);stem(x,y);
ylabel('Amplitude---->');
xlabel('n---->');
title('Unit Impulse Signal');

%To Generate Unit Step Signal%


t=0:1:n-1;
y1=ones(1,n);
subplot(2,2,2);stem(t,y1);
ylabel('Amplitude---->');
xlabel('n---->');
title('Unit Step Signal');

%To Generate Ramp Signal%


t1=0:1:n;
subplot(2,2,3);stem(t1,t1);
ylabel('Amplitude---->');
xlabel('n---->');
title('Ramp Sequence');

%To Generate Exponentional Sequence%


y2=exp(-1*t1);
subplot(2,2,4);stem(t1,y2);
ylabel('Amplitude---->');
xlabel('n---->');
title('Exponentional Sequence');

%To Generate Sine Sequence%


pause
t2=0:0.01:pi;
y3=sin(2*pi*t2);figure(2);
subplot(2,1,1);plot(t2,y3);
ylabel('Amplitude---->');
xlabel('n---->');
title('Sine Sequence');

%To Generate Cos Sequence%


t2=0:0.01:pi;

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

y3=cos(2*pi*t2);
subplot(2,1,2);plot(t2,y3);
ylabel('Amplitude---->');
xlabel('n---->');
title('Cose Sequence');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 2

PROGRAM :

clc;
clear all;
close all;
%Frequency, Magnitude And Phase Response%
for n=1:1:257;
s(n)=3.5*sin(2*pi*(0.15)*n)+sin(2*pi*(0.4)*n)
end
x=1:257;
mag=abs(s(x));%To Calculate Magnitude%
subplot(2,1,1);plot(x,mag);
xlabel('n---->');
ylabel('Magnitude---->');
ag=phase(s(x));%To Calculate Phase%
subplot(2,1,2);stem(x,ag);
xlabel('n---->');
ylabel('Phase---->');
pause
for n=1:1:257;
s1(n)=3+5.657*cos(2*pi*(0.1)*n);
end
y=1:257;figure
mag1=abs(s1(y));
subplot(2,1,1);plot(y,mag1);
xlabel('n---->');
ylabel('Magnitude---->');
ag1=phase(s1(y));
subplot(2,1,2);plot(y,ag1);
xlabel('n---->');
ylabel('Phase---->');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 3

PROGRAM :

clc
clear all
close all

num=input('Enter The Numerator Coefficient : ');


dnum=input('Enter The Denominator Coefficient : ');
[r,p,k]=residuez(num,dnum);
zplane(r,p);grid%To Plot Poles And Zeroes

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 4

PROGRAM :

clc
clear all
close all

%To Calculate N Point DFT%


N=input('Enter The Length Of DFT := ');
for n=1:1:N
s(n)=3*(exp(-0.1*n));
s1(n)=2*((cos(2*pi*(0.15)*n))+(sin(2*pi*(0.4)*n)));
s2(n)=4*((sin(4*pi*(0.4)*n))+(cos(2*pi*(0.2)*n)));
end
x=1:1:N;
sfft=fft(s(x),N);
%y=ifft(sfft,N)
s1fft=fft(s1(x),N);
%y=ifft(s1fft,N)
s2fft=fft(s2(x),N);
%y=ifft(s2fft,N)
subplot(2,1,1);stem(s(x));xlabel('n---->');ylabel('Amplitude---->');title('Original
Signal');
subplot(2,1,2);plot(sfft);xlabel('n---->');ylabel('Amplitude---->');title('FFT Signal Of
S(n)');
pause
subplot(2,1,1);stem(s1(x));xlabel('n---->');ylabel('Amplitude--->');title('Original
Signal');
subplot(2,1,2);plot(s1fft);xlabel('n---->');ylabel('Amplitude---->');title('FFT Signal Of
S1(n)');
pause
subplot(2,1,1);stem(s2(x));xlabel('n---->');ylabel('Amplitude--->');title('Original
Signal');
subplot(2,1,2);plot(s2fft);xlabel('n---->');ylabel('Amplitude---->');title('FFT Signal Of
S2(n)');
pause
close all

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 5

PROGRAM :

%To Calculate N Point DFT using Twiddle matrix%


clear all
clc
N = input('The length of the DFT :');
s = input('The Input signal : ');
for i=0:N-1,
for j=0:N-1,
ang = 2*pi*((i*j)/N);
a(i+1,j+1)=complex(cos(ang),-sin(ang));
end
end
final = a * s;
final

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 6

PROGRAM :

clc
clear all
close all

%To Compute Linear Convolution%


x=[1 1 1 1 1];
h=[1 2 3 4 5 6 7 8];
y=conv(x,h)
figure;subplot(3,1,1);stem(x);
xlabel('n---->');
ylabel('Amplitude---->');
title('Input Sequence');
subplot(3,1,2);stem(h);
xlabel('n---->');
ylabel('Amplitude---->');
title('Impulse Response');
subplot(3,1,3);stem(y);
xlabel('n---->');
ylabel('Amplitude---->');
title('Output Sequence');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 7

PROGRAM :

clc
clear all
close all

%To Compute Circular Convolution%


x=[1 2 4];
h=[1 2];

%x=input('Enter The Value Of x: ');


%h=input('Enter The Value Of h: ');

N1=length(x);
N2=length(h);
N=max(N1,N2);
y=conv(x,h);
ly=length(y);

for i=1:1:N
if(N+i<=ly)
r(i)=y(i)+y(N+i);
else
r(i)=y(i);
end
end

disp('The result of the Circular Convolution is : ');


disp(r);

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 8

PROGRAM:

clc
clear all
close all

%To Design Lowpass FIR Filter Using Rectangular, Hamming, Kaiser Windows%
sn = 0;
f=input('Enter The Sampling Frequency Where f = 0.8 or 0.6 or 0.4 or 0.2 := ');
n=input('Enter The Order Of Filter Where n = 16 or 32 or 64 or 128 or 256 := ');
disp('1 -- For Rectangular Window 2 -- For Hamming Window 3 -- For Kaiser
Window');
windowtype=input('Enter The Type Of Window: =');

for i=1:128
sn(i) = ((4*sin(2*pi*(f)*i)) + ((4/3)*sin(2*pi*3*(f)*i))+((4/5)*sin(2*pi*5*(f)*i))+
((4/7)*sin(2*pi*7*(f)*i)));
end

switch lower(windowtype)
case {1}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=boxcar(n+1);%For Rectangular Window
b = fir1(n,wn,win); %Creating FIR LP filter with Rectangular window, returns the
filter coefficients in length N+1 vector B.
hs = filter(b,1,sn)%hs = filter(b,1,sn) %Input s(n) to the filter returns output hs

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR LP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);

% returns the frequency response vector H and the corresponding angular


frequency vector F
[H,F]=freqz(b,1,256);
%grid
plot(F,20 * log10(abs(H)));
xlabel('Normalized F (rad/sample)')

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

ylabel('Magnitude (dB)')
title('Magnitude Response')

%Plot the phse response of the filter


subplot(3,2,4)
plot(F,unwrap(angle(H))*180/pi); grid
xlabel('Normalized F (rad/sample)')
ylabel('Phase (degrees)')
title('Phase Response')

%Plot the filter


subplot(3,2,5);
plot(b);grid
xlabel('Filter using Rectangular window');
fvtool(b);
case {2}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=hamming(n+1);
b = fir1(n,wn,win); %Creating FIR LP filter with hamminng window
hs = filter(b,1,sn);

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR LP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));
grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

subplot(3,2,5);
plot(hs);grid;
xlabel('Filter using hamming window');
fvtool(b);

case{3}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

win = kaiser(n+1,2.5);
wn = 0.2 * pi; %Cutoff frequency
b = fir1(n,wn,win);
hs = filter(b,1,sn);

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR LP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));
grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter


subplot(3,2,5);
plot(hs);grid;
xlabel('Filter using Kaiser Window');
fvtool(b);

otherwise
disp('Not A Proper Window Type ');
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

RECTANGULAR WINDOW

FILTER VISUALISATION TOOL

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

HAMMING WINDOW

FILTER VISUALIZATION TOOL

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

KAISER WINDOW

FILTER VISUALIZATION TOOL

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 9

PROGRAM :

clc
clear all
close all

%To Design Highpass FIR Filter Using Blackman, Hanning, Kaiser Windows%
sn = 0;
f=input('Enter The Sampling Frequency Where f = 0.8 or 0.6 or 0.4 or 0.2 := ');
n=input('Enter The Order Of Filter Where n = 16 or 32 or 64 or 128 or 256 := ');
disp('1 -- For Blackman Window 2 -- For Hanning Window 3 -- For Kaiser
Window');
windowtype=input('Enter The Type Of Window: =');
for i=1:256
sn(i) = ((4*sin(2*pi*(f)*i)) + ((4/3)*sin(2*pi*3*(f)*i))+((4/5)*sin(2*pi*5*(f)*i))+
((4/7)*sin(2*pi*7*(f)*i)));
end

switch lower(windowtype)

case {1}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=blackman(n+1);%For Blackman Window
b = fir1(n,wn,'high',win);

%Creating FIR HP filter with Blackman window, returns the filter coefficients in
length N+1 vector B.
hs = filter(b,1,sn)%hs = filter(b,1,sn) %Input s(n) to the filter returns output hs

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR HP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);

% returns the frequency response vector H and the corresponding angular


frequency vector F
[H,F]=freqz(b,1,256);
plot(F,20 * log10(abs(H)));grid
xlabel('Normalized F (rad/sample)')

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

ylabel('Magnitude (dB)')
title('Magnitude Response')

%Plot the phase response of the filter


subplot(3,2,4)
plot(F,unwrap(angle(H))*180/pi); grid
xlabel('Normalized F (rad/sample)')
ylabel('Phase (degrees)')
title('Phase Response')

%Plot the filter


subplot(3,2,5);
plot(b);grid
xlabel('Filter using Blackman Window');
fvtool(b);

case {2}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=hanning(n+1);
b = fir1(n,wn,'high',win); %Creating FIR HP filter with hanning window
hs = filter(b,1,sn);

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR HP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

subplot(3,2,5);
plot(b);grid;
xlabel('Filter using Hanning Window');
fvtool(b);

case{3}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win = kaiser(n+1,2.5);
b = fir1(n,wn,'high',win); %Creating FIR HP filter with hanning window
hs = filter(b,1,sn);

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR HP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter


subplot(3,2,5);
plot(b);grid;
xlabel('Filter using Kaiser Window');
fvtool(b);

otherwise
disp('Not A Proper Window Type ');
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

BLACKMAN WINDOW

FILTER VISUALIZATION TOOL

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

HANNING WINDOW

FILTER VISUALIZATION TOOL

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

KAISER WINDOW

FILTER VISUALIZATION TOOL

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 10

PROGRAM :

%To Design Lowpass And Highpass FIR Filter Using Rectangular Window%
clc
clear all
close all
sn = 0;
f=input('Enter The Sampling Frequency Where f = 0.8 or 0.6 or 0.4 or 0.2 := ');
n=input('Enter The Order Of Filter Where n = 16 or 32 or 64 or 128 or 256 := ');
disp('1 -- Lowpass Filter 2 -- For Highpass');
windowtype=input('Enter Your Choice : =');
for i=1:256
sn(i) = 3.5*(sin(2*pi*(0.15)*n)+sin(2*pi*(0.4)*n));
%sn(i) = (2*(cos(2*pi*(0.15)*n)+(sin(2*pi*(0.4)*n)));
%sn(i) = 3*exp(-0.1*n);
end

switch lower(windowtype)
case {1}
disp('1 -- For Rectangular Window 2 -- For Hamming Window 3 -- For Kaiser
Window');
windowtype=input('Enter The Type Of Window: =');

switch lower(windowtype)
case {1}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);
%Create a filter and use sn as input
wn = 0.2 * pi; %Cutoff frequency
win=boxcar(n+1);%For Rectangular Window
b = fir1(n,wn,win); %Creating FIR LP filter with Rectangular window, returns
the filter coefficients in length N+1 vector B.
hs = filter(b,1,sn)%hs = filter(b,1,sn) %Input s(n) to the filter returns output hs

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR LP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
% returns the frequency response vector H and the corresponding angular
frequency vector F
[H,F]=freqz(b,1,256);
plot(F,20 * log10(abs(H))); grid;
xlabel('Normalized F (rad/sample)')

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

ylabel('Magnitude (dB)')
title('Magnitude Response')

%Plot the phse response of the filter


subplot(3,2,4)
plot(F,unwrap(angle(H))*180/pi); grid
xlabel('Normalized F (rad/sample)')
ylabel('Phase (degrees)')
title('Phase Response')

%Plot the filter


subplot(3,2,5);
plot(b);grid
xlabel('Filter using Rectangular window');
fvtool(b);
pause(2);

case {2}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=hamming(n+1);
b = fir1(n,wn,win); %Creating FIR LP filter with hamminng window
hs = filter(b,1,sn);
%Plot the output
subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR LP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));
plot(F,H);grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

%Plot the filter


subplot(3,2,5);
plot(hs);grid;
xlabel('Filter using hamming window');
fvtool(b);

case{3}
win = kaiser(n+1,2.5);
wn = 0.2 * pi; %Cutoff frequency
b = fir1(n,wn,win);

yn = filter(b,1,sn);
subplot(2,1,1);
plot(yn);grid
axis([0 100 -6 6]);
title('Output of the filter');

subplot(2,1,2);
plot(b);grid
xlabel('LP FIR using Kaiser Window ');
fvtool(b);

otherwise
disp('Not A Proper Window Type ');
end

case {2}
disp('1 -- For Blackman Window 2 -- For Hanning Window 3 -- For Kaiser
Window');
windowtype=input('Enter The Type Of Window: =');

switch lower(windowtype)
case{1}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=blackman(n+1);%For Blackman Window
b = fir1(n,wn,'high',win);

%Creating FIR HP filter with Blackman window, returns the filter coefficients
in length N+1 vector B.
hs = filter(b,1,sn)%hs = filter(b,1,sn) %Input s(n) to the filter returns output hs

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

title('Output of the FIR HP filter');


%Plot the magnitude response of the filter
subplot(3,2,3);

% returns the frequency response vector H and the corresponding angular frequency
vector F
[H,F]=freqz(b,1,256);
plot(F,20 * log10(abs(H)));grid
xlabel('Normalized F (rad/sample)')
ylabel('Magnitude (dB)')
title('Magnitude Response')

%Plot the phase response of the filter


subplot(3,2,4)
plot(F,unwrap(angle(H))*180/pi); grid
xlabel('Normalized F (rad/sample)')
ylabel('Phase (degrees)')
title('Phase Response')

%Plot the filter


subplot(3,2,5);
plot(b);grid
xlabel('Filter using Blackman Window');
fvtool(b);

case {2}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win=hanning(n+1);
b = fir1(n,wn,'high',win); %Creating FIR HP filter with hanning window hs =
filter(b,1,sn);

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR HP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter


subplot(3,2,5);
plot(b);grid;
xlabel('Filter using Hanning Window');
fvtool(b);

case{3}
subplot(3,2,1);
plot(sn);grid;
axis([0 150 -10 10]);

%Create a filter and use sn as input


wn = 0.2 * pi; %Cutoff frequency
win = kaiser(n+1,2.5);
b = fir1(n,wn,'high',win); %Creating FIR HP filter with hanning window
hs = filter(b,1,sn);

%Plot the output


subplot(3,2,2);
plot(hs);grid;
axis([0 150 -10 10]);
title('Output of the FIR HP filter');

%Plot the magnitude response of the filter


subplot(3,2,3);
[H,F] = freqz(b,1,256); % returns the frequency response vector H and the
corresponding angular frequency vector F
plot(F,20 * log10(abs(H)));grid;
xlabel('Normalized F (rad/sample)');
ylabel('Magnitude (dB)');
title('Magnitude Response');

%Plot the phase response of the filter


subplot(3,2,4);
plot(F,unwrap(angle(H))*180/pi); grid;
xlabel('Normalized F (rad/sample)');
ylabel('Phase (degrees)');
title('Phase Response');

%Plot the filter


subplot(3,2,5);
plot(b);grid;

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

xlabel('Filter using Kaiser Window');


fvtool(b);

otherwise
disp('Not A Proper Window Type ');
end
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

LOW PASS

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

HIGH PASS

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

SECTION II

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 11

PROGRAM :

clc
clear all
close all

%Band-Pass And Band-Stop Using Chebyshev Type-I Digital Filter%


format long

wp=input('Enter The PassBand Frequency := ');


rp=input('Enter The PassBand Ripple := ');
rs=input('Enter The StopBand Ripple := ');
ws=input('Enter The StopBand Frequency := ');
f=input('Enter The Sampling Frequency := ');

w1=2*wp/f;%For Digital Filter PassBand Frequency


w2=2*ws/f;%For Digital Filter StopBand Frequency
[n,x]=cheb1ord(w1,w2,rp,rs);
wn=[w1 w2];
[b,a]=cheby1(n,rp,wn,'bandpass');
w=0:0.01:pi
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);

subplot(2,1,1);
plot(om/pi,m);grid
xlabel('Normalised Frequency---->');
ylabel('Gain In dB---->');
title('Magnitude');

subplot(2,1,2);
plot(om/pi,an);grid
xlabel('Normalised Frequency---->');
ylabel('Phase In Radian---->');
title('Phase');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 12

PROGRAM :

clc;
close all;
clear all;

%To Design ButtorWorth Bandpass and Bandstop Digital IIR Filter%


format long
rp=input('Enter The Passband Ripple := ');
wp=input('Enter The Passband Frequency := ');
rs=input('Enter The Stopband Ripple := ');
ws=input('Enter The Stopband Frequency := ');
fs=input('Enter The Sampling Frequency := ');
w1=2*wp/fs;
w2=2*ws/fs;
[n]=buttord(w1,w2,rp,rs);% BUTTORD(Wp, Ws, Rp, Rs) returns the order N also
returns Wn, the Butterworth natural frequency
wn=[w1 w2];
[b,a]=butter(n,wn,'bandpass');%For BandPass %%% For BandStop Filter
[b,a]=butter(n,wn,'stop')
%[B,A] = BUTTER(N,Wn) designs an Nth order lowpass digital vectors
B (numerator) and A (denominator)
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));%For Magnitude
an=angle(h);%For Phase
subplot(2,1,1);
plot(om/pi,m);grid
ylabel('gain in db---->');
xlabel('(a) Normalised frequency');

subplot(2,1,2);
plot(om/pi,an);grid
xlabel('(b) Normalised frequency-->');
ylabel('phase in radian-->');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 13

AIM :

Write a program to implement Radix2 Decimation In Frequency (DIF) FFT algorithm.

PROGRAM :

clc
clear all
close all

% Radix 2 DIF-FFT%
N=input('Enter Length Of FFT : - ');
for i=1:N+1
if N==2^i
x=input('Input The Sequence');
z=fft(x,N);
y=bitrevorder(z);%To Shuffel The Output Sequence
disp('FFT Sequence');
disp(y);
subplot(2,1,1),stem(x);xlabel('n---->');ylabel('Amplitude----
>');title('Orignal Signal');
subplot(2,1,2),stem(z);xlabel('n---->');ylabel('Amplitude----
>');title('FFT Signal');
break
elseif N > 2^i
else
disp('Not a proper Number');
break
end
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 14

PROGRAM :

clc
clear all
close all

% Radix 2 DIT-FFT%
N=input('Enter Length Of FFT : - ');
for i=1:N+1
if N==2^i
x=input('Input The Sequence');
y=bitrevorder(x);%To Shuffel The Input Sequence
z=fft(x,N);
disp(y);
disp('FFT Sequence');
disp(z)
subplot(2,1,1),stem(x);xlabel('n---->');ylabel('Amplitude----
>');title('Orignal Signal');
subplot(2,1,2),stem(z);xlabel('n---->');ylabel('Amplitude----
>');title('FFT Signal');
break
elseif N > 2^i
else
disp('Not a proper Number');
break
end
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 15

PROGRAM :

clc
clear all
close all
Fs = 1024;
f=input('Enter The Value For Frequency f := ');
for n = 1:256
a(n) = cos(2*pi*f*n/Fs)+randn(size(n));
end

plot(a);
nfft = min(256,length(a)) ;
fs= 1024;
specgram(a,nfft,fs);%

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 16

PROGRAM :

clc
clear all
close all
n=17;
f=[0 0.3 0.4 0.6 0.7 1];
a=[0 0 1 1 0 0];
b=remez(n,f,a);
[h,w] = freqz(b,1,512);
plot(f,a,w/pi,abs(h))
legend('Ideal','remez Design');

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 17

PROGRAM :

clc
clear all
close all

x=input('The values of x : ');


h=input('The values of h : ');

%X = [1 2 ; 3 4];
%H = [5 6 ; 7 8];

y = conv2(x,h);
plot (y);

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 18 DATE: / /
PROGRAM :

clc
clear all
close all

disp('1 -> One Dimensional Sequence 2 -> Two Dimensional Sequence');


seq=input('Choose the required option : ');

switch lower(seq)
case{1}
%One-Dimensioinal Cross-Correlation And Auto-Correlation%
x=input('Enter the first One Dimensional Sequence : ');
h=input('Enter the Second One Dimensional Sequence : ');

y=xcorr2(x,h);%To Compute Cross-Correlation


disp('Cross Correlation');
disp(y);
y1=xcorr2(x);%To Compute Auto-Correlation
disp('Auto Correlation');
disp(y1);

case{2}

%Two-Dimensioinal Cross-Correlation And Auto-Correlation%


x=input('Enter the first Two Dimensional Sequence : ')
h=input('Enter the Second Two Dimensional Sequence : ')

y=xcorr2(x,h);%To Compute Cross-Correlation


disp('Cross Correlation');
disp(y);
y1=xcorr2(x);%To Compute Auto-Correlation
disp('Auto Correlation');
disp(y1);

otherwise
disp('Select a correct option.');
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT :

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 19

PROGRAM :

clc
clear all
close all

%Stability Check%
b=input('Enter the denominator coefficients of the filter : ');
k=poly2rc(b);%divides The second coefficient by First Coefficient
knew=fliplr(k);%To Flip The Matrix
s=all(abs(knew));%True if all elements of a vector are nonzero
if(s==1)
disp('Stable System');
else
disp('Non Stable System');
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

PRACTICAL NO 20

PROGRAM :

clc
clear all
close all

N=input('Enter the number in Radix 2 ');


ind1=1;
ind2=0;
s=sprintf('\t\t%s\t\t%s\t%s\t%s\t\n','[Linear Index]','[Bits]','[Bit-Reversed]','[Bit-
Reversed Index]');
disp(s);
for j=0:N,
if((2^j)==N)
for i=0:N-1,
%arr_of_bits(i+1)=str2num(dec2bin(i,j))
a=dec2bin(i,j);
%disp(a);
ind1=1;
%ind2=j;
for ind2=j:-1:1,
b(ind1)=a(ind2);
ind1=ind1+1;
end
%b;
%disp(bin2dec(b));
s=sprintf('\t\t\t\t%d\t\t\t %s\t\t %s\t\t\t\t%d \n',i,a,b,bin2dec(b));
disp(s);
end
break;
elseif(j==N)
sprintf('Not a valid number');
end
end

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

OUTPUT:

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

MATLAB FUNCTIONS USED

1. ONES -Ones array.


ONES(N) is an N-by-N matrix of ones.
ONES(M,N) or ONES([M,N]) is an M-by-N matrix of ones
ONES(M,N,P,...) or ONES([M N P ...]) is an M-by-N-by-P-by-...array of ones.
ONES(SIZE(A)) is the same size as A and all ones.

2. SUBPLOT -Create axes in tiled positions.


H = SUBPLOT(m,n,p), or SUBPLOT(mnp), breaks the Figure window into an
m-by-n matrix of small axes, selects the pth axes for the current plot, and returns
the axis handle. The axes are counted along the top row of the Figure window,
then the second row, etc.

3. XLABEL -X-axis label.


XLABEL('text') adds text beside the X-axis on the current axis.
XLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...)sets
the values of the specified properties of the XLABEL.
H = XLABEL(...) returns the handle to the text object used as the label.

4. YLABEL -Y-axis label.


YLABEL('text') adds text beside the Y-axis on the current axis.
YLABEL('text','Property1',PropertyValue1,'Property2',PropertyValue2,...) sets
the values of the specified properties of the YLABEL.
H = YLABEL(...) returns the handle to the text object used as the label.

5. STEM -Discrete sequence or "stem" plot.


STEM(Y) plots the data sequence Y as stems from the x axis terminated with
circles for the data value.
STEM(X,Y) plots the data sequence Y at the values specified in X.
STEM(...,'filled') produces a stem plot with filled markers.
STEM(...,'LINESPEC') uses the line type specified for the stems and markers.
H = STEM(...) returns a vector of line handles.

6. ABS - Computes the absolute value.


abs(X) is the absolute value of the elements of X. When
X is complex, abs(X) is the complex modulus (magnitude) of
the elements of X.

7. PHASE - Computes the phase of a complex vector.


PHI=phase(G)
G is a complex-valued row vector and PHI is returned as its
phase (in radians), with an effort made to keep it continuous
over the pi-borders.

8. COMPLEX - Construct complex result from real and imaginary parts.


C = COMPLEX (A,B) returns the complex result A + Bi, where A and B are
identically sized real N-D arrays, matrices, or scalars of the same data type.

9. ZEROS - ZEROS(N) is an N-by-N matrix of zeros.

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

ZEROS(M,N) or ZEROS([M,N]) is an M-by-N matrix of zeros.


ZEROS(M,N,P,...) or ZEROS([M N P ...]) is an M-by-N-by-P-by-...
array of zeros.

10. LENGTH - Length of vector.


LENGTH(X) returns the length of vector X. It is equivalent to MAX(SIZE(X))
for non-empty arrays and 0 for empty ones.

11. BOXCAR -Boxcar window.


W = BOXCAR(N) returns the N-point rectangular window.

12. FIR1 -FIR filter design using the window method


B = FIR1(N,Wn) designs an N'th order lowpass FIR digital filter and returns the
filter coefficients in length N+1 vector B. The cut-off frequency Wn must be
between 0 < Wn < 1.0, with 1.0 corresponding to half the sample rate. The filter
B is real and has linear phase. The normalized gain of the filter at Wn is -6 dB.

B = FIR1(N,Wn,'high') designs an N'th order highpass filter.


B = FIR1(N,Wn,'low') to design a lowpass filter.

13. PHASE -Computes the phase of a complex vector


PHI=phase(G) G is a complex-valued row vector and PHI is returned as its
phase (in radians), with an effort made to keep it continuous over the pi-borders.

14. BUTTORD Butterworth filter order selection.


[N, Wn] = BUTTORD(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Butterworth filter that loses no more than Rp dB in the passband
and has at least Rs dB of attenuation in the stopband.

15. BITREVORDER - Permute input into bit-reversed order.


Y = BITREVORDER(X) returns an array Y of the same size as X, with its first
non-singleton dimension permuted to be in bit-reversed order.

16. CHEB1ORD - Chebyshev Type I filter order selection.


[N, Wn] = CHEB1ORD(Wp, Ws, Rp, Rs) returns the order N of the lowest
order digital Chebyshev Type I filter that loses no more than Rp dB.

17. CHEBY1 - Chebyshev Type I digital and analog filter design.


[B,A] = CHEBY1(N,R,Wn) designs an Nth order lowpass digital
Chebyshev filter with R decibels of peak-to-peak ripple in the
passband. CHEBY1 returns the filter coefficients in length N+1
vectors B (numerator) and A (denominator). The cutoff frequency
Wn must be 0.0 < Wn < 1.0, with 1.0 corresponding to half the
sample rate.

18. FREQZ - Digital filter frequency response.


[H,W] = FREQZ(B,A,N) returns the N-point complex frequency response
vector H and the N-point frequency vector W in radians/sample of
the filter:
jw -jw -jmw

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

jw B(e) b(1) + b(2)e + .... + b(m+1)e


H(e) = ---- = ------------------------------------
jw -jw -jnw
A(e) a(1) + a(2)e + .... + a(n+1)e
given numerator and denominator coefficients in vectors B and A. The
frequency response is evaluated at N points equally spaced around the
upper half of the unit circle. If N isn't specified, it defaults to 512.

19. XCORR2 - Two-dimensional cross-correlation.


XCORR2(A,B) computes the cross correlation of matrices A and B.
XCORR2(A) is the autocorrelation function.

20. FLIPLR - Flip matrix in left/right direction.


FLIPLR(X) returns X with row preserved and columns flipped
in the left/right direction.

X=123 becomes 3 2 1
456 654

21. POLY2RC - Convert prediction polynomial to reflection coefficients.


K = POLY2RC(A) returns the reflection coefficients, K, based on the prediction
polynomial, A.

22. PWELCH Power Spectral Density estimate via Welch's method.


Pxx = PWELCH(X) returns the Power Spectral Density (PSD) estimate, Pxx, of
a discrete-time signal vector X using Welch's averaged, modified periodogram
method.

23. SPECGRAM Calculate spectrogram from signal.


B = SPECGRAM(A,NFFT,Fs,WINDOW,NOVERLAP) calculates the
spectrogram for the signal in vector A. SPECGRAM splits the signal into
overlapping
segments, windows each with the WINDOW vector and forms the columns of
B with their zero-padded, length NFFT discrete Fourier transforms.

24. CONV2 - Two dimensional convolution.


C = CONV2(A, B) performs the 2-D convolution of matrices A and B. If
[ma,na] = size(A) and [mb,nb] = size(B),
then size(C) = [ma+mb-1,na+nb-1].
C = CONV2(H1, H2, A) convolves A first with the vector H1 along the rows
and then with the vector H2 along the columns.

25. SPRINTF - Write formatted data to string.


[S,ERRMSG] = SPRINTF(FORMAT,A,...) formats the data in the real part of
matrix A (and in any additional matrix arguments), under control of the
specified FORMAT string, and returns it in the MATLAB string variable S.
ERRMSG is an optional output argument that returns an error message string if
an error occurred or an empty matrix if an error did not occur. SPRINTF is the
same as FPRINTF except that it returns the data in a MATLAB string variable
rather than writing it to a file.

Rohan Devare. Patkar College M.Sc.(cs) Part – I


Digital Signal Processing

26. DEC2BIN Convert decimal integer to a binary string.


DEC2BIN(D) returns the binary representation of D as a string.
D must be a non-negative integer smaller than 2^52.
DEC2BIN(D,N) produces a binary representation with at least N bits.

Rohan Devare. Patkar College M.Sc.(cs) Part – I

Anda mungkin juga menyukai