Digital Signal Processing Lab: Dr. Nanda Kumar M
Digital Signal Processing Lab: Dr. Nanda Kumar M
amplitude--->
4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
n1--->
amplitude--->
10
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
n2--->
amplitude--->
40
20
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
n2--->
Linear convolution
• clc; clear all; close all;
• x1=input('Enter the first sequence x1(n) = ');
x2=input('Enter the second sequence x2(n) = ');
• L=length(x1);
• M=length(x2); N=L+M-1;
• yn=conv(x1,x2);
• disp(‘The values of yn are= ‘); disp(yn);
• n1=0:L-1;
• subplot(311); stem(n1,x1); grid on;
• xlabel('n1--->'); ylabel('amplitude--->');
title('First sequence');
• n2=0:M-1;
• subplot(312); stem(n2,x2); grid on;
• xlabel('n2--->');
• ylabel('amplitude--->');
• N2=0:N-1;
• subplot(313); stem(n2,yn); grid on;
• xlabel('n2--->');
• ylabel('amplitude--->');
First sequence
amplitude--->
4
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
n1--->
amplitude--->
0
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
n2--->
amplitude--->
20
10
0
0 0.5 1 1.5 2 2.5 3 3.5 4
n2--->
4. DFT/IDFT and FFT of given
DTsignal
clc; close all; clear all;
xn=input('Enter the sequence x(n)');
ln=length(xn);
xk=zeros(1,ln);
ixk=zeros(1,ln);
for k=0:ln-1
for n=0:ln-1
xk(k+1)=xk(k+1)+(xn(n+1)*exp((-i)*2*pi*k*n/ln));
End
end
%Plotting input sequence %
t=0:ln-1;
subplot(221);
stem(t,xn);
ylabel ('Amplitude');
xlabel ('Time Index');
title('Input Sequence'); %-----------------------
• magnitude=abs(xk);
• t=0:ln-1;
• subplot(222);
• stem(t,magnitude);
• ylabel ('Amplitude');
• xlabel ('K'); title('Magnitude Response');
phase=angle(xk);
• t=0:ln-1;
• subplot(223);
• stem(t,phase);
• ylabel ('Phase');
• xlabel ('K'); title ('Phase Response');
IDFT
for n=0:ln-1
for k=0:ln-1
ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln));
end
End
ixk=ixk./ln;
t=0:ln-1;
subplot(224);
stem(t,ixk);
ylabel ('Amplitude'); xlabel ('Time Index’)
FFT
• clc; clear all;close ll;
• x=input('Enter the sequence : ')
• N=length(x)
• xK=fft(x,N)
• xn=ifft(xK)
• n=0:N-1;
• subplot (2,2,1); stem(n,x); xlabel('n >'); ylabel('amplitude');
title('input sequence');
• subplot (2,2,2); stem(n,abs(xK));xlabel('n ---------------- >');
ylabel('magnitude'); title('magnitude response');
• subplot (2,2,3); stem(n,angle(xK));xlabel('n ---------------- >');
ylabel('phase'); title('Phase responce');
• subplot (2,2,4); stem(n,xn); xlabel('n >'); ylabel('amplitude');
title('IFFT');
5.PSD
Program
clc; clear all;close all;
N=256;
fs=8000;
f=input('enter the frequency[1 to 5000]:'); n=0:N-1;
x=sin(2*pi*(f/fs)*n)
Y = fft(y,512);
Pyy = Y.* conj(Y) / 512;
f = 1000*(0:256)/512;
subplot(2,1,2);
plot(f, Pyy(1:257))
title('Frequency content of y');
xlabel('frequency (Hz)');
6. Implement IIR filter (LP/HP/BP)
Aim: write a program to implement IIR filter (LP/HP/BP)
a) Butterworth filter b) Chebyshev Type-I filter
c) Chebyshev Type- II filter
APPARATUS REQUIRED:
System with Matlab, windows OS
Program
• clc; clear all; close all;
• disp('enter the IIR filter design specifications');
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]=buttord(w1,w2,rp,rs,'s');
• disp('Frequency response of IIR LPF is:');
• [b,a]=butter(n,wn,'low','s');
• w=0:.01:pi;
• [h,om]=freqs(b,a,w);
• m=20*log10(abs(h));
• an=angle(h);
• figure,subplot(2,1,1);
• plot(om/pi,m);
• title('magnitude response of IIR filter is:');
• xlabel('(a) Normalized freq. -->');
• ylabel('Gain in dB-->');
• subplot(2,1,2);plot(om/pi,an);
• title('phase response of IIR filter is:');
• xlabel('(b) Normalized freq. -->');
• ylabel('Phase in radians-->');
7. Design FIR filter (LP/HP) using windowing technique
APPARATUS REQUIRED:
System with Matlab, windows OS
clc; clear all; close all;
clc; clear all; close all;
n=20; fp=200; fq=300; fs=1000; n=20; fp=300; fq=200; fs=1000;
fn=2*fp/fs; fn=2*fp/fs; window=blackman(n+1);
window=blackman(n+1); b=fir1(n,fn,'high',window);
b=fir1(n,fn,window); [H W]=freqz(b,1,128);
[H W]=freqz(b,1,128); subplot(2,1,1);
subplot(2,1,1); plot(W/pi,abs(H));
plot(W/pi,abs(H)); title('mag res of lpf');
title('magnitude response of lpf'); ylabel('gain in db >');
ylabel('gain in db >');
xlabel('normalized frequency ----- >');
xlabel('normalized frequency ----- >');
subplot(2,1,2);
subplot(2,1,2); plot(W/pi,angle(H));
title('phase response of lpf'); plot(W/pi,angle(H)); title('phase res of
ylabel('angle ------- >'); lpf'); ylabel('angle >');
xlabel('normalized frequency ----- >'); xlabel('normalized frequency ----- >');
8. Down sampling and Up sampling of given
sequence
• Aim: write a program to find Power Spectral Density of a sequence
• APPARATUS REQUIRED:
• System with Matlab, windows OS
• Theory:
• • Down-sampling operation is implemented by keeping every M-th
sample of x[n] and removing in-between samples to generate y[n]
• • Input-output relation
• y[n] = x[nM]
• Up sampling
• x [n] =x[n / M],
Program
Down sampling Up sampling
clc; Clear all; Close all; clc; clear all; close all;
D=input('enter the downsampling factor'); L=input('enter the upsampling factor');
L=input('enter the length of the input signal'); N=input('enter the length of the input signal');
f1=input('enter the frequency of first sinusodal');
f1=input('enter the frequency of first
f2=input('enter the frequency of second sinusodal');
sinusodal');
n=0:L-1;
f2=input('enter the frequency of second
x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
sinusodal');
y=decimate(x,D,'fir');
subplot(2,1,1); n=0:N-1;
stem(n,x(1:L)); x=sin(2*pi*f1*n)+sin(2*pi*f2*n);
title('input sequence'); xlabel('time(n)'); y=interp(x,L);
ylabel('amplitude'); subplot(2,1,1) stem(n,x(1:N))
subplot(2,1,2) m=0:(L/D)-1; title('input sequence'); xlabel('time(n)');
stem(m,y(1:L/D)); 117 ylabel('amplitude'); subplot(2,1,2)
title('Decimated sequence'); xlabel('time(n)');
m=0:N*L-1;
ylabel('amplitude');
stem(m,y(1:N*L)) title('output sequence ');
xlabel('time(n)'); ylabel('amplitude');
Up sampling
Down sampling
input sequence
input sequence 2
2
1
amplitude
1
amplitude
0
0
-1
-1
-2
-2 0 1 2 3 4 5 6 7 8 9
0 10 20 30 40 50 60 70 80 90 100 time(n)
time(n) output sequence
2
Decimated sequence
2
0
1
amplitude
0 -2
-1
-4
0 5 10 15 20 25 30 35 40 45 50
-2
0 2 4 6 8 10 12 14 16 18 20
time(n)
9. Conversion of Analog filter to Digital Filter
Aim: write a program Conversion of Analog filter to
Digital Filter.
a) impulse invariant transformation
b) bilinear transformation
APPARATUS REQUIRED:
System with MATLAB, windows OS
10. Generation of DTMF signals
Aim: Write a program to generate DTMF signals
APPARATUS REQUIRED:
System with MATLAB, Windows OS
Theory: Dual-tone Multi-Frequency (DTMF)
signalling is the basis for voice communications
control and is widely used worldwide in modern
telephony to dial numbers and configure
switchboards. It is also used in systems such as in
voice mail, electronic mail and telephone banking.
Program
Fs = 8000; N = 800; t = (0:N-1)/Fs; pit = 2*pi*t;
tones = zeros(N,size(f,2));
for toneChoice=1:12,
tones(:,toneChoice) = sum(sin(f(:,toneChoice)*pit))‘;
subplot(4,3,toneChoice),
plot(t*1e3,tones(:,toneChoice)); title(['Symbol "', symbol {toneChoice},'":
[',num2str(f(1,toneChoice)),',',num2str(f(2,toneChoice)),']']) set(gca, 'Xlim', [0
25]); ylabel('Amplitude');
if toneChoice>9, xlabel('Time (ms)'); end
end
set(gcf, 'Color', [1 1 1], 'Position', [1 1 1280 1024])
annotation(gcf,'textbox', 'Position',[0.38 0.96 0.45 0.026],...
'EdgeColor',[1 1 1],...
'String', '\bf Time response of each tone of the telephone pad', ...
'FitHeightToText','on');
11. Generation of DTMF signals
Aim: Write a program to generate DTMF signals
APPARATUS REQUIRED:
System with MATLAB, Windows OS
Theory: Dual-tone Multi-Frequency (DTMF)
signalling is the basis for voice communications
control and is widely used worldwide in modern
telephony to dial numbers and configure
switchboards. It is also used in systems such as in
voice mail, electronic mail and telephone banking.
• clc;
• clear all;
• close all;
• t = -2:0.05:2;
• x=input('enter the input number');
• fr1=697;
• fr2=770;
• fr3=852;
• fr4=941;
• fc1=1209;
• fc2=1336;
• fc3=1477;
• fc4=1633;
• y0 = sin(2*pi*fr4*t) + sin(2*pi*fc2*t); % 0
• y1 = sin(2*pi*fr1*t) + sin(2*pi*fc1*t); % 1
• y2 = sin(2*pi*fr1*t) + sin(2*pi*fc2*t); % 2
• y3 = sin(2*pi*fr1*t) + sin(2*pi*fc3*t); % 3
• y4 = sin(2*pi*fr2*t) + sin(2*pi*fc1*t);
• y5 = sin(2*pi*fr2*t) + sin(2*pi*fc2*t); % 5
• y6 = sin(2*pi*fr2*t) + sin(2*pi*fc3*t); % 6
• y7 = sin(2*pi*fr3*t) + sin(2*pi*fc1*t); % 7
• y8 = sin(2*pi*fr3*t) + sin(2*pi*fc2*t); % 8
• y9 = sin(2*pi*fr3*t) + sin(2*pi*fc3*t); % 9
• y_start = sin(2*pi*fr4*t) + sin(2*pi*fc1*t); % *
• y_canc = sin(2*pi*fr4*t) + sin(2*pi*fc3*t); % #
• if (x==1)
• plot(t,y1)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==2)
• plot(t,y2)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==3)
• plot(t,y3)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==4)
• plot(t,y4)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==5)
• plot(t,y5)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==6)
• plot(t,y6)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==7)
• plot(t,y7)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==8)
• plot(t,y8)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==9)
• plot(t,y9)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==0)
• plot(t,y0)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==11)
• plot(t,y_start)
• xlabel('time(t)')
• ylabel('amplitude')
• elseif (x==12)
• plot(t,y_canc)
• xlabel('time(t)')
• ylabel('amplitude')
• else
• disp('enter the correct input')
• end