DSP Lab
DSP Lab
%Auto correlation
t=0:1:n-1;
Y=xcorr(X);
subplot(2,1,1);
stem(t,X);
xlabel('time');
ylabel('Amplitude');
title('input sequence');
subplot(2,1,2);
stem(t,Y);
xlabel('time');
ylabel('Amplitude');
title('output sequence');
xlabel('Time, [s]');
ylabel('Amplitude');
grid;
grid;
xlabel('lags');
ylabel('Autocorrelation');
%cross correlation
t=0:1:n-1;
Y=xcorr(X,h);
Subplot(2,1,1);
Stem(x,t);
Xlabel(‘time’);
Ylabel(‘Amplitude’);
Title(‘input sequence’);
Subplot(2,1,2);
Stem(h,t);
Xlabel(‘time’);
Ylabel(‘Amplitude’);
Title(‘impulse sequence’);
Subplot(2,1,3);
Stem(y,t);
Xlabel(‘time’);
Ylabel(‘Amplitude’);
Title(‘output sequence’);
Output
IMPLEMENTATION OF LOW PASS IIR FILTERS
PROGRAM:
clc;
close all;
clear all;
format long
rp=input('enter the passband ripple');
rs=input('enter stopband ripple');
wp=input('enter passband freq');
ws=input('enter stopband freq');
fs=input('enter sampling freq');
w1=2*wp/fs;
w2=2*ws/fs;
%Analog LPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(3)
plot(om/pi,m);
title('**** Analog Output Magnitude *****');
ylabel('gain in db...>');
xlabel('normalised freq..>');
figure(2)
plot(om/pi,an);
title('**** Analog Output Phase ****');
xlabel('normalised freq..>');
ylabel('phase in radians...>');
n
wn
%Digital LPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn);
w=0:.01:pi;
[h,om]=freqz(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(1)
plot(om/pi,m);
title('**** Digital Output Magnitude *****');
ylabel('gain in db...>');
xlabel('normalised freq..>');
figure(4)
plot(om/pi,an);
title('**** Digital Output Phase ****');
xlabel('normalised freq..>');
ylabel('phase in radians...>');
n
wn
INPUT:
rp = 0.500
rs = 100
wp = 1500
ws = 3000
fs = 10000
Output:
n = 13
wn = 0.32870936151976
Output Waveform
IMPLEMENTATION OF HIGH PASS IIR FILTERS
PROGRAM:
clc;
close all;
clear all;
format long
rp=input('enter the passband ripple');
rs=input('enter stopband ripple');
wp=input('enter passband freq');
ws=input('enter stopband freq');
fs=input('enter sampling freq');
w1=2*wp/fs;
w2=2*ws/fs;
%Analog HPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
figure(1)
plot(om/pi,m);
title('**** Analog Output Magnitude *****');
ylabel('gain in db...>');
xlabel('normalised freq..>');
figure(2)
plot(om/pi,an);
title('**** Analog Output Phase ****');
xlabel('normalised freq..>');
ylabel('phase in radians...>');
n
wn
%Digital HPF
[n,wn]= buttord(w1,w2,rp,rs);
[b,a]=butter(n,wn,'high');
w=0:.01:pi;
[h,om]=freqz(b,a,w); m=20*log10(abs(h));
an=angle(h);
figure(3)
plot(om/pi,m);
title('**** Digital Output Magnitude *****');
ylabel('gain in db...>');
xlabel('normalised freq..>');
figure(4)
plot(om/pi,an);
title('**** Digital Output Phase ****');
xlabel('normalised freq..>');
ylabel('phase in radians...>');
n
wn
Input:
rp = 0.5000 rs = 100
wp = 1200 ws = 2400 fs = 8000
Output Waveform
n = 13
wn = 0.32870936151976
Output Waveform
IMPLEMENTATION OF BANDPASS FILTER
% Program for the design of Butterworth analog Bandpass filter
clc;
close all;
clear all;
format long
rp=input('enter the passband ripple...');
rs=input('enter the stopband ripple...');
wp=input('enter the passband freq...');
ws=input('enter the stopband freq...');
fs=input('enter the sampling freq...');
w1=2*wp/fs;
w2=2*ws/fs;
[n]=buttord(w1,w2,rp,rs);
wn=[w1 w2];
[b,a]=butter(n,wn,'bandpass,s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h); subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in dB --.');
xlabel('(a) Normalised frequency --.');
subplot(2,1,2);
plot(om/pi,an);
xlabel('(b) Normalised frequency --.');
ylabel('Phase in radians --.');
OUTPUT:
enter the passband ripple... 0.36
enter the stopband ripple... 36
enter the passband freq... 1500
enter the stopband freq... 2000
EXPECTED GRAPH:
IMPLEMENTATION OF CHEBYSHEV TYPE-2 ANALOG FILTERS
% Program for the design of Chebyshev Type-2 High pass analog filter
clc;
close all;
clear all;
format long
rp=input('enter the passband ripple...');
rs=input('enter the stopband ripple...');
wp=input('enter the passband freq...');
ws=input('enter the stopband freq...');
fs=input('enter the sampling freq...');
w1=2*wp/fs;
w2=2*ws/fs;
[n,wn]=cheb2ord(w1,w2,rp,rs,'s');
[b,a]=cheby2(n,rs,wn,'high','s');
w=0:.01:pi;
[h,om]=freqs(b,a,w);
m=20*log10(abs(h));
an=angle(h);
subplot(2,1,1);
plot(om/pi,m);
ylabel('Gain in dB --.');
xlabel('(a) Normalised frequency --.');
subplot(2,1,2);plot(om/pi,an);