0% found this document useful (0 votes)
18 views

DSP Record

The document describes finding the frequency response of a system using its transfer function in MATLAB. It involves taking the numerator and denominator polynomials of a transfer function, evaluating them over a range of frequencies and calculating the magnitude and phase response. Plots of magnitude response obtained from the program and from an inbuilt MATLAB function are also shown.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views

DSP Record

The document describes finding the frequency response of a system using its transfer function in MATLAB. It involves taking the numerator and denominator polynomials of a transfer function, evaluating them over a range of frequencies and calculating the magnitude and phase response. Plots of magnitude response obtained from the program and from an inbuilt MATLAB function are also shown.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 43

AIM: To find Z-Transform of given discrete time signal, to locate the Zeros and Poles and plot

Pole-Zero maps in Z-Plane for the given transfer function using MATLAB.

SOFTWARE USED: MATLAB 2020a/ 2020a b/(MATLAB Online)

PROGRAM:

% CLEARING PREVIOUS CONTENTS


clc;
clear all;
close all;
% case-1 for n=[-1 0 1 2]
x=[1,2,3,4];% Input sequence
n=[-1,0,1,2]; % Range of n
l=length(x);
X=0;
z=sym('z');% Create symbolic expressions in terms of z
for i=1:l
X=X+x(i)*z^(-n(i)); % Z-transform equation
end
disp('For n=-1:2')
disp(X);% Displays output
%case-2 for n= [0 1 2 3]
X=0;
n=[0 1 2 3];
z=sym('z');
for i=1:l
X=X+x(i)*z^(-n(i));
end
disp('For n=0:3')
disp(X);
%case-3 for n=[-4 -3 -2 -1]
X=0;
n=[-4 -3 -2 -1];
z=sym('z');
for i=1:l
X=X+x(i)*z^(-n(i));
end
disp('For n=-4:-1')
disp(X);
ts=0.1;
%finding transfer function:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:1
%Given H(z)=(2*z^-3+z^-1+1)/(z^-4-z^-2+3*z^-1+2)
% Or H(z) = (z^3+z^2+2)/(2*z^4+3*z^3-z^2+1)
n=[1 1 0 2]; %Numerator polynomial
d=[2 3 -1 0 1]; %Denominator polynomial
systf=tf(n,d,ts,'Variable','z^-1')% gives transfer function in terms of z
[z p k] = tf2zp(n,d)
pzmap(n,d);% Plot of pole zero map in z-domain
title('pole-zero plot in z-domain');
grid

OUTPUT:
For n=-1:2
z + 3/z + 4/z^2 + 2
For n=0:3
2/z + 3/z^2 + 4/z^3 + 1
For n=-4:-1
z^4 + 2*z^3 + 3*z^2 + 4*z
systf =

1 + z^-1 + 2 z^-3
------------------------
2 + 3 z^-1 - z^-2 + z^-4

Sample time: 0.1 seconds


Discrete-time transfer function.
z=

-1.6956 + 0.0000i
0.3478 + 1.0289i
0.3478 - 1.0289i
p=

-1.6923 + 0.0000i
-0.6873 + 0.0000i
0.4398 + 0.4863i
0.4398 - 0.4863i
k=

0.5000

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:2
SIMULATION GRAPHS:

INFERENCE: Z-transform of a given signal x[n] is given by:

n=-
X[z] consists of positive powers of z if n is negative and vice-versa. And for a stable and causal
case ROC includes unit circle and powers of z are negative respectively.

RESULT:
MATLAB program to find Z-Transform of given discrete time signal, locating the Zeros and
Poles and plotting the Pole-Zero maps in Z-Plane for the given transfer function is performed
and the output is verified.

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:3
AIM: To find DFT and IDFT of a given discrete time signal using MATLAB.

SOFTWARE USED: MATLAB 2020a/ 2020a b/(MATLAB Online)

PROGRAM:

% CLEARING PREVIOUS CONTENTS


clc;
clear all;
close all;
a=input('Enter the input sequence:');
N=length(a);
A=zeros(N,1);

%A(K) is DFT of a[n]

for k=0:N-1
for n=0:N-1
A(k+1)=A(k+1)+a(n+1)*exp(-1i*2*pi*n*k/N);
end
end
disp('A[k]=')
disp(A)

%b[n] is IDFT of A[k]

N1=length(A);
b=zeros(N1,1);
for n=0:N-1
for k=0:N-1
b(n+1)=b(n+1)+(A(k+1)*exp(i*2*pi*n*k/N)/N);
end
end
disp('b[n]=')
disp(b);
figure(1)

%plotting input sequence

k=0:N-1;
subplot(3,1,1);

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:4
stem(a);
title("a[n]");
xlabel("n-->");
ylabel("amplitude");

%plotting magnitude

subplot(3,1,2);
stem(k,abs(A));
title("|A[k]|");
xlabel("k-->");
ylabel("magnitude");

%plotting phase

subplot(3,1,3);
stem(k,angle(A));
title("phase");
xlabel("k-->");
ylabel("angle");

OUTPUT:

Enter the input sequence:


[1 2 3 4]
A[k]=
10.0000 + 0.0000i
-2.0000 + 2.0000i
-2.0000 - 0.0000i
-2.0000 - 2.0000i

b[n]=
1.0000 - 0.0000i
2.0000 - 0.0000i
3.0000 - 0.0000i
4.0000 + 0.0000i

Simulation Graphs:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:5
INFERENCE: DFT of a given signal x[n] is given by:
N-1

n=0
IDFT of X[k] is given by:
N-1

k=0
DFT values of x[n] consists of real values and complex values which occur in complex conjugate
pairs.

RESULT:
DFT and IDFT of a given discrete time signal are found and the output is verified using
MATLAB

AIM: To find response of LTI system using graphical approach of linear convolution using
MATLAB.

SOFTWARE USED: MATLAB 2020a/ 2020a b/(MATLAB Online)

PROGRAM:

% CLEARING PREVIOUS CONTENTS

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:6
clc;
close all;
clear all;

a=input('enter the values of x[n]: '); %Enter input x[n]


b=input('enter the values for h[n]: '); %Enter h[n]
N1=length(a);
N2=length(b);
N=N1+N2-1;
h1=[zeros(1,N2-1),b,zeros(1,N-N2)];
hf=flip(b);
h=[hf,zeros(1,N-1)];
x=[zeros(1,N2-1),a,zeros(1,N-N1)];
y=zeros(1,N);
t=-(N2-1):1:(N-1);
figure(2)
for n=0:N-1
hshif = circshift(h,n);
subplot(N1,2,n+1);
stem(t,hshif);
str=sprintf('h(%d-k)', n); % To plot each sequence h(-k)
title(str);
ylabel('Amplitude');
xlabel('time index');
y(n+1)=sum( x .* hshif );
end
fprintf('\nResult of graphical linear convolution is:')
disp(y);

fprintf('\nResult of convolution using inbuilt fuction is:');


y1=conv(a,b)
figure(1);
subplot(3,1,1)
stem(t,x)
title('x(k)');
ylabel('Amplitude');
xlabel('time index');

subplot(3,1,2)
stem(t,h1);
title('h(k)');
ylabel('Amplitude');

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:7
xlabel('time index');

subplot(3,1,3)
stem(t,h);
title('h(-k)');
ylabel('Amplitude');
xlabel('time index');

OUTPUT:
enter the values of x[n]:
[1 2 3 4 ]
enter the values for h[n]:
[1 -1 2 -3]

Result of graphical linear convolution is: 1 1 3 2 -4 -1 -12

Result of convolution using inbuilt fuction is:


y1 =

1 1 3 2 -4 -1 -12

Simulation graphs:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:8
DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:9
INFERENCE: Output of LTI system if input is x[n] and impulse response h[n] is given by:

n=-
Length of output signal is given by = length(x)+length(h)-1

RESULT:
To response of LTI system using graphical approach of linear convolution is found using
MATLAB software and the respective waveforms are plotted.

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:10
AIM: To find the power spectrum of a given signal using Weiner-Kintchine
relation using MATLAB.

SOFTWARE USED: MATLAB 2020a/ 2020a b/(MATLAB Online)

PROGRAM:

% CLEARING PREVIOUS CONTENTS


clc;
clear all;
close all;
a=input('enter sample values of x[n]: ');%enter the input x[n]
b=flip(a);
N1=length(a);
N2=length(b);
lenY=N1+N2-1;
h1=[zeros(1,N2-1),b,zeros(1,lenY-N2)];
hf=flip(b);
h=[hf,zeros(1,lenY-1)];
x=[zeros(1,N2-1),a,zeros(1,lenY-N1)];
y=zeros(1,lenY);
t=-(N2-1):1:(N1-1);
figure(1)
subplot(3,1,1)
stem(a)
title('x(n)');
ylabel('Amplitude');
xlabel('time index');
for n=0:lenY-1
hshif = circshift(h,n);
y(n+1)=sum( x .* hshif );
end
fprintf('\nResult of graphical autocorrelation is:')
disp(y);
fprintf('\nResult of autocorrelation using inbuilt fuction is:');
y1=xcorr(a);
disp(y1);
subplot(3,1,2)
stem(t,y);
DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:11
title('autocorrelation(graphically)');
ylabel('Amplitude');
xlabel('time index');
N=length(y);
A=zeros(N,1);
for k = 0:N-1
for n = 0:N-1
A(k+1)=A(k+1)+y(n+1)*exp(-1i*2*pi*n*k/N); %dft of y[n]=y[w]
end
end
disp('A=')
disp(A)
m=abs(A);
disp('m=')
disp(m)
k=-(N2-1):1:(N1-1);
subplot(3,1,3);
stem(k,m);
xlabel('k');
ylabel('|A(k)|');
title('Magnitude');

OUTPUT:
enter sample values of x[n]:
[1 2 3 4]
Result of graphical autocorrelation is: 4 11 20 30 20 11 4
Result of autocorrelation using inbuilt fuction is: 4.0000 11.0000 20.0000 30.0000 20.0000
11.0000 4.0000
A=
1.0e+02 *

1.0000 + 0.0000i
-0.3859 - 0.1859i
0.0391 + 0.0490i
-0.0131 - 0.0575i
-0.0131 + 0.0575i
0.0391 - 0.0490i
-0.3859 + 0.1859i

m=
100.0000
42.8364

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:12
6.2658
5.8979
5.8979
6.2658
42.8364

Simulation Graphs:

INFERENCE: Output of LTI system if input is x[n] and impulse response h[n] is given by:

n=-
Length of output signal is given by = length(x)+length(h)-1
Wiener-kintchine relation gives the relation between auto-correlation and power density
spectrum. It states that:-
“Power density spectrum is equal to fourier transform of auto-correlation function Rₓₓ(T)
Sₓₓ(w) = F.T[Rₓₓ(T)]
Auto-correlation is given by:-

l=-

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:13
RESULT: MATLAB program to find power density spectrum of x[n] using its auto-correlation
function has been found and magnitude of auto-correlation has been plotted.

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:14
AIM: To find frequency response of a given system using its transfer function.

SOFTWARE USED: MATLAB 2020a/ 2020a b/(MATLAB Online)

PROGRAM:

% CLEARING PREVIOUS CONTENTS


clc;
clear all;
close all;
a = input("Enter the numerator coefficients:");%Numerator coeff of transfer function
b = input("Enter the denominator coefficients:");%denominator coeff of transfer function
l1 = length(a);
l2 = length(b);
num=0;
den=0;
syms w;
for k=0:l1-1
num=num+a(k+1)*(exp(i*w))^(-k); %Numerator polynomial
end
fprintf("Equation of numerator :");
disp(num); %equation of numerator
for k=0:l2-1
den=den+b(k+1)*(exp(i*w))^(-k); %Denominator polynomial
end
fprintf("Equation of denominator :");
disp(den); %equation of denominator
N=1;
for w=0:0.01:pi
A(N)=subs(num);
B(N)=subs(den);
N=N+1;
end
H=A./B;
w=0:0.01:pi;
H1=freqz(a,b,w); %frequency response using inbuilt function
subplot(2, 2, 1);
plot(w,20*log10(abs(H)));%plotting magnitude
xlabel("w");
ylabel("|H(w)|");
title("Magnitude without using inbuilt function");
subplot(2, 2, 2);
plot(w,20*log10(abs(H1))); %magnitude using inbuilt

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:15
xlabel("w")
ylabel("|H(w)|");
title("Magnitude using inbuilt function");
subplot(2,2,3);
plot(w,angle(H)); % angle
xlabel("w")
ylabel("<H(w)");
title("phase without using inbuilt function ");
subplot(2,2,4);
plot(w,angle(H1)); % angle using inbuilt
xlabel("w")
ylabel("<H(w)");
title("phase using inbuilt function");

OUTPUT:
Enter the numerator coefficients:
[1 -1]
Enter the denominator coefficients:
[1 -1 2]
Equation of numerator :1 - exp(-w*1i)
Equation of denominator :1 + 2*exp(-w*2i) - exp(-w*1i)

Simulation Graphs:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:16
INFERENCE: Given transfer function is:
H(ₑ(-j*w))=1-ₑ(-j*w)/(1-(ₑ-j*w)+2*ₑ(-j*w))
Its magnitude and phase spectrums are plotted at various values of w using H(w)

RESULT: MATLAB program to find frequency response of a given signal using its transfer
function and its magnitude and phase values are verified theoretically and spectrums are plotted.

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:17
AIM: To implement low pass and high pass FIR filters using Windowing technique.

SOFTWARE USED: MATLAB R-2020a

PROGRAM:
% CLEARING PREVIOUS CONTENTS
clc;
close all;
clear all;
% ENTER THE CUTOFF FREQUENCY AND LENGTH OF THE WINDOW
wc=input('Enter the cut off frequency: ');
N=input('Enter the length of the window: ');
k=(N-1)/2;
% EXPRESSION FOR LPF (Applying Fourier Series Technique)
for n=0:1:N-1
hd(n+1)=(sin(wc*(n-k+0.000001)))/(pi*(n-k+0.000001));
end
%for hpf:hd(n+1)=(sin(pi*(n-k+0.00001))/(pi*(n-k+0.00001)))-(sin(wc*(n-k+0.00001)))/(pi*(n-
k+0.00001))
% GENERATION OF DIFFERENT WINDOWS
for n=0:N-1
wrec(n+1)=1; % rectangular
wtri(n+1)=1-((2*abs(n-((N-1)/2)))/(N-1)); % triangular
wbn(n+1)=0.42-0.5*cos((2.*pi*n)/(N-1))+0.08*cos((4.*pi*n)/(N-1)); %Blackman
whm(n+1)=0.54-0.46*cos((2.*pi*n)/(N-1)); %Hamming
whn(n+1)=0.5*(1-(cos((2.*pi*n)/(N-1)))); %Hanning
end
wk = kaiser(N,4);%Kaiser
% MULTIPLYING WINDOW FUNCTIONS WITH hd(n)
hrec=hd.*wrec;
htri=hd.*wtri;
hbn=hd.*wbn;
hhm=hd.*whm;
hhn=hd.*whn;
hk=hd.*wk'; %Transpose wk as it is column matrix

%FINDING THE FREQUENCY RESPONSE AND PLOTTING THE MAGNITUDE AND


PHASE RESPONSES
% Finding the frequency response
p=0:0.01:pi;
[Hrec,W]=freqz(hrec,1,p);
[Htri,W]=freqz(htri,1,p);
[Hbn,W]=freqz(hbn,1,p);

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:18
[Hhm,W]=freqz(hhm,1,p);
[Hhn,W]=freqz(hhn,1,p);
[Hk,W]=freqz(hk,1,p);
% Finding the Magnitude (in db) and Phase responses
Mrec=20*log10(abs(Hrec)); Prec=angle(Hrec);
Mtri=20*log10(abs(Htri)); Ptri=angle(Htri);
Mbn=20*log10(abs(Hbn)); Pbn=angle(Hbn);
Mhm=20*log10(abs(Hhm)); Phm=angle(Hhm);
Mhn=20*log10(abs(Hhn)); Phn=angle(Hhn);
Mk=20*log10(abs(Hk)); Pk=angle(Hk);
% Plotting of Windows. Magnitude and Phase Responses
n=0:N-1;
p=0:0.01:pi;
figure(1)
%Rectangular Window
subplot(3,3,1);
stem(n,wrec);
xlabel('time index');
ylabel('amplitude');
title('Rectangular Window');
subplot(3,3,2);
plot(p,Mrec);
xlabel('frequency');
ylabel('amplitude');
title('magnitudeUsingRec');
subplot(3,3,3);
plot(p,Prec);
xlabel('frequency');
ylabel('Angle');
title('PhaseUsingRec');
%TRIANGLE WINDOW
subplot(3,3,4);
stem(n,wtri);
xlabel('time index');
ylabel('amplitude');
title('triangular Window');
subplot(3,3,5);
plot(p,Mtri);
xlabel('frequency');
ylabel('amplitude');
title('magnitudeUsingTri');
subplot(3,3,6);
plot(p,Ptri);
xlabel('frequency');

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:19
ylabel('Angle');
title('PhaseUsingTri');
%BLACKMAN WINDOW
subplot(3,3,7);
stem(n,wbn);
xlabel('time index');
ylabel('amplitude');
title('Blackman Window');
subplot(3,3,8);
plot(p,Mbn);
xlabel('frequency');
ylabel('amplitude');
title('magnitudeUsingBn');
subplot(3,3,9);
plot(p,Pbn);
xlabel('frequency');
ylabel('Angle');
title('PhaseUsingBn');
figure(2)
%HAMMINGTON WINDOW
subplot(3,3,1);
stem(n,whm);
xlabel('time index');
ylabel('amplitude');
title('Hamming Window');
subplot(3,3,2);
plot(p,Mhm);
xlabel('frequency');
ylabel('amplitude');
title('magnitudeUsingHm');
subplot(3,3,3);
plot(p,Phm);
xlabel('frequency');
ylabel('Angle');
title('PhaseUsingHm');
%HANNINGTON WINDOW
subplot(3,3,4);
stem(n,whn);
xlabel('time index');
ylabel('amplitude');
title('hannington Window');
subplot(3,3,5);
plot(p,Mhn);
xlabel('frequency');

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:20
ylabel('amplitude');
title('magnitudeUsingHn');
subplot(3,3,6);
plot(p,Ptri);
xlabel('frequency');
ylabel('Angle');
title('PhaseUsingTri');
%KAISER WINDOW
subplot(3,3,7);
stem(n,wk);
xlabel('time index');
ylabel('amplitude');
title('Kaiser Window');
subplot(3,3,8);
plot(p,Mk);
xlabel('frequency');
ylabel('amplitude');
title('magnitudeUsingKaiser');
subplot(3,3,9);
plot(p,Pk);
xlabel('frequency');
ylabel('Angle');
title('PhaseUsingKaiser');

OUTPUT:
Enter the cut off frequency:
pi/2
Enter the length of the window:
11

SIMULATION GRAPHS: LPF:-

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:21
HPF:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:22
INFERENCE:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:23
For low pass filter:
hd(n)=sin(n*wc)/pi*n
For high pass:
hd(n)=(sin(n*pi)/n*pi)-(sin(n*wc)/pi*n

RESULT: MATLAB program to design low pass and high pass filters using different
windowing techniques and magnitude and phase are plotted.

AIM: To implement the Low Pass Analog and Digital Butterworth IIR Filters using MATLAB.

SOFTWARE USED: MATLAB 2020a/ 2020a b/MATLAB Online

PROGRAM(7a):
% clearing previous contents
clc;
clear all;
close all;
al_p=input("Enter pass band ripple in db");
al_s=input("Enter stop band ripple in db");
f_p=input("Enter pass band cut off frequency in hz");
f_s=input("Enter stop band cut off frequency in hz");
om_p=2*pi*f_p
om_s=2*pi*f_s
% TO CALCULATE N
n_n=log10(sqrt((10^(0.1*al_s)-1)/(10^(0.1*al_p)-1)));
n_d=log10(om_s/om_p);
N=round(n_n/ n_d)
p=1/(2*N);
om_c=om_p/((10^(0.1*al_p)-1)^p) % cut_off omega_c
fi=0;
s=0;

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:24
for i=1:N
fi(i)=(pi/2)+((((2*i)-1)*pi)/(2*N));
s(i)=exp(j*fi(i));
t(i)=s(i)*om_c;
end
s
y=poly(t); % poly returns polynomial using t matrix values
B=(om_c)^N; % numerator
A=y; % denominator polynomial
w=0:0.01:3000*pi; %value greater than cut_off
[H,w]=freqs(B,A,w);
subplot(2,2,1)
plot(w,20*log10(abs(H)));
title("Magnitude plot");
xlabel("Analog freq");
ylabel("Gain in dB");

subplot(2,2,2)
plot(w,angle(H));
title("Phase plot");
xlabel("Analog freq");
ylabel("Angle in degrees");
[b,a]=butter(N,om_c,'s') % Using inbuilt
[H1,w1]=freqs(b,a,w);
subplot(2,2,3)
plot(w1,20*log10(abs(H1)));
title("Magnitude plot");
xlabel("Analog freq");
ylabel("Gain in dB");
subplot(2,2,4)
plot(w1,angle(H1));
title("Phase plot");
xlabel("Analog freq");
ylabel("Angle in degrees");

OUTPUT:

Enter pass band ripple in db 1


Enter stop band ripple in db 30
Enter pass band cut off frequency in hz 200
Enter stop band cut off frequency in hz 600
om_p = 1.2566e+03
om_s = 3.7699e+03
N = 4

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:25
om_c = 1.4879e+03
s = -0.3827 + 0.9239i -0.9239 + 0.3827i -0.9239 - 0.3827i -0.3827 - 0.9239i
b = 1.0e+12 *
0 0 0 0 4.9006
a = 1.0e+12 *
0.0000 0.0000 0.0000 0.0086 4.9006

SIMULATION GRAPHS:

INFERENCE:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:26
In designing digital filters, first analog prototypes are designed using order and cutoff
frequencies from which normalized case is obtained and using numerator=cutoff power N
unnormalized case is obtained

RESULT:
MATLAB program to design Butterworth IIR Filters and magnitude and phase spectrums are
plotted and verified using inbuilt functions

PROGRAM(7b):
% clearing previous contents
clc;
clear all;
close all;
alpha_p=input('Enter pass band ripple in db');
alpha_s=input('Enter stop band ripple in db');
omegap_digital=input('Enter pass band cut-off freq');
omegas_digital=input('Enter stop band cut-off freq');

%Calculation of analog frequencies from digital and normalize it divide by pi)


omega_p=omegap_digital/pi;
omega_s=omegas_digital/pi;
num=sqrt((10^(0.1*alpha_s)-1)/(10^(0.1*alpha_p)-1));
den=omega_s/omega_p;
N=ceil(log10(num)/log10(den)) %Calculation of order
power=1/(2*N);
d1=10^(0.1*alpha_p)-1;
cut_off=omega_p/(d1^power) %Calculation of omegac
for k=1:N
phi_k(k)=0;
phi_k(k)=(pi/2)+(((2*k)-1)*pi)/(2*N);

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:27
end
for i=1:N
s(i)=0;
s(i)=exp(j*phi_k(i));
t(i)=cut_off*s(i);
end
p=poly(t); %poly returns polynomial using t matrix values
A=p;
B=cut_off^N;

%Using method:
[r1,p1,k1]=residue(B,A);
r1z=r1;
p1z=exp(p1);
[Bi,Ai]=residue(r1z,p1z,k1);
Bif=[Bi,0];
w=0:0.001:pi;
[H3,w]=freqz(Bif,Ai,w);
subplot(2,2,1);
plot(w,20*log10(abs(H3)));
title('Magnitude plot without inbuilt');
xlabel('Normalised digital freq');
ylabel('Gain in dB');
subplot(2,2,2);
plot(w,angle(H3));
title('Phase plot without inbuilt');
xlabel('Normalised digital freq');
ylabel('Angle in degrees');
w=0:0.001:pi;
[bi,ai]=impinvar(B,A,1);%T=1;
[H4,w1]=freqz(bi,ai,w);
subplot(2,2,3);
plot(w1,20*log10(abs(H4)));
title('Magnitude plot using inbuilt');
xlabel('Normalised digital freq');
ylabel('Gain in dB');
subplot(2,2,4);
plot(w1,angle(H4));
title('Phase plot using inbuilt');
xlabel('Normalised digital freq');
ylabel('Angle in degrees');

OUTPUT:
Enter pass band ripple in db 1

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:28
Enter stop band ripple in db 30
Enter pass band cut-off freq pi/2
Enter stop band cut-off freq 3*pi/4
N = 11
cut_off = 0.5317

SIMULATION GRAPHS:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:29
INFERENCE:
In designing digital filters, we first design analog prototype and using impulse variation
technique and bilinear transformation techniques we convert analog to digital filters.
Impulse variation technique:
Ω=w/T
And poles:
1/(s-pi) <--- > 1/(s-A*e^pi)

RESULT:
MATLAB program to design butter-worth IIR filters and magnitude and phase spectrums are
plotted and verified using inbuilt functions

AIM: To implement decimation process and compare decimated outputs with down sampled
signals.

SOFTWARE USED: MATLAB R-2020a

PROGRAM:
% clear previous contents
clc;
clear all;
close all;
D=2; %Decimator value
f=100;
t=0:0.0001:(1/f);
x=sin(2*pi*f*t); % Input signal
%x(n) plot (input signal plot):
figure(1);
subplot(311);
stem(t,x);
xlabel('time domain x(t)');
ylabel('amplitude');
title('Input signal for down-sampler');
%down sampled sampling:
Nx=length(x);

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:30
d=Nx/D;
l=D-1;
for i=1:ceil(d)
yd(i)=x(i*D-l); % Down sampling without filter
end
ty=0:(ceil(d)-1);
y1=decimate(x,D);% Using inbuilt function decimated signal
subplot(312);
stem(ty,yd);
xlabel('time');
ylabel('amplitude');
title('decimated signal yd(t)');
subplot(313);
stem(ty,y1);
xlabel('time');
ylabel('amplitude');
title('decimated signal yd(t) inbuilt function');
figure(2);
% Dtft of input sequence:-
nx=0:length(x)-1;
w=0:0.01:2*pi;
for i=1:length(w)
X(i)=0;
for k=1:length(x)
X(i)=X(i)+x(k).*exp(-j.*w(i).*nx(k));
end
end
% Dtft(frequency spectrum) of down sampled sequence:-
ns=0:length(yd)-1;
w=0:0.01:2*pi;
for i=1:length(w)
Xd(i)=0;
for k=1:length(yd)
Xd(i)=Xd(i)+yd(k).*exp(-j.*w(i).*ns(k));
end
end
%Dtft spectrum of decimated output:
ns=0:length(y1)-1;
w=0:0.01:2*pi;
for i=1:length(w)
Xo(i)=0;
for k=1:length(y1)
Xo(i)=Xo(i)+y1(k).*exp(-j.*w(i).*ns(k));
end

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:31
end
%plots of spectrums:-frequency domain outputs
subplot(311);
plot(w,abs(X));
xlabel('freq');
ylabel('amplitude');
title('Magnitude of input signal'); %input signal plot
subplot(312);
plot(w,abs(Xd));
xlabel('freq');
ylabel('amplitude');
title('Magnitude of down-sampled signal'); %Down-sampled signal
subplot(313);
plot(w,abs(Xo));
xlabel('freq');
ylabel('amplitude');
title('Magnitude of decimated signal'); %Decimated signal plot

OUTPUT:
D=2

SIMULATION GRAPHS:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:32
INFERENCE:Down-sampled signal consists of less number of samples and aliasing effect is
observed, since the spectrum is expanded, to avoid this the signal is first passed through a low
pass filter and then applied to down-sampler.

Decimator :-
x(n) Low-pass filter Down sampler y(n)

RESULT: Decimated process has been implemented using a MATLAB program and spectrums
of down-sampled and decimated signal have been plotted.

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:33
AIM: To implement Interpolater process and compare interpolator outputs with up sampled
signals.

SOFTWARE USED: MATLAB R-2020a

PROGRAM:

% CLEARING PREVIOUS CONTENTS


clc;
clear all;
close all;
I=2; % Interpolator value
f=100;
t=0:0.001:(1/f);
x=sin(2*pi*f*t); %input signal
%x(n) plot (input signal):
figure(1);
subplot(311);
stem(t,x);
xlabel('time domain x(t)');
ylabel('amplitude');

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:34
title('Input signal for up-sampler');
% Up-Sampling :
Nx=length(x);
k1=I*Nx;
for i=I:k1
if rem(i,I)==0
yu(i-I+1)=x(i/I); %Up sampling without filter
else
yu(i)=0;
end
end
y2=interp(x,I); % interpolated signal using inbuilt function
ty=0:0.01:(length(yu)-1)*0.01;
subplot(312);
stem(ty,yu);
xlabel('time');
ylabel('Amplitude');
title('Up-sampled signal yu(t)'); %Up sampled signal time domain plot
subplot(313);
ty1=0:0.01:(length(y2)-1)*0.01;
stem(ty1,y2);
xlabel('time');
ylabel('amplitude');
title('Interpolated signal yu(t) using inbuilt function'); %interpolated signal
figure(2); % Spectrums:
% Dtft of input signal:-
nx=0:length(x)-1;
w=0:0.01:2*pi;
for i=1:length(w)
X(i)=0;
for k=1:length(x)
X(i)=X(i)+x(k).*exp(-j.*w(i).*nx(k));
end
end
% Dtft of up-sampled signal:
nu=0:length(yu)-1;
w=0:0.01:2*pi;
for i=1:length(w)
Xu(i)=0;
for k=1:length(yu)
Xu(i)=Xu(i)+yu(k).*exp(-j.*w(i).*nu(k));
end
end
%Dtft of interpolated signal:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:35
no=0:length(y2)-1;
w=0:0.01:2*pi;
for i=1:length(w)
Xu1(i)=0;
for k=1:length(y2)
Xu1(i)=Xu1(i)+y2(k).*exp(-j.*w(i).*no(k));
end
end
%Plots:-
%plots of spectrums:-frequncy domain
subplot(311);
plot(w,abs(X));
xlabel('freq');
ylabel('amplitude');
title('Magnitude of input signal'); %input signal frequency domain plot
subplot(312);
plot(w,abs(Xu));
xlabel('freq');
ylabel('amplitude');
title('Magnitude of up-sampled signal'); %up-sampled signal magnitude plot
subplot(313);
plot(w,abs(Xu1));
xlabel('freq');
ylabel('amplitude');
title('Magnitude of Interpolated signal'); %interpolated signal magnitude plot

OUTPUT:
I=2

SIMULATION GRAPHS:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:36
INFERENCE: Up-sampled signal consists of more number of samples and repetition of
spectrums is observed, since the spectrum is compressed, to avoid this the signal after up-
sampling is passed through a low pass filter.
Interpolator :-
x(n) Up-Sampler Low-pass filter y(n)

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:37
RESULT: Interpolater process has been implemented using a MATLAB program and
spectrums of up-sampled and interpolated signal have been plotted.

AIM: To implement I/D sampling rate converter.

SOFTWARE USED: MATLAB R-2020a

PROGRAM:

% CLEARING PREVIOUS CONTENTS

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:38
clc;
clear all;
close all;
I=13; %interpolator value
D=6; %Decimator value
f=44100;
t=0:(0.1/f):(1/f);
x=sin(2*pi*f*t);
y=resample(x,I,D); %Sampling rate converter
y1=interp(x,I);
y2=decimate(y1,D); % Interpolator, decimator
subplot(311);
stem(t,x);
xlabel('time');
ylabel('Amplitude');
title('Input signal');%Input
ly=0:length(y)-1;
subplot(312);
stem(ly,y);
xlabel('time');
ylabel('Amplitude');
title('Sampled signal(dac&adc)');%Sampled rate converter
ly2=0:length(y2)-1;
subplot(313);
stem(ly2,y2);
xlabel('time');
ylabel('Amplitude');
title('Sampled signal(decimator & interpolator)');%using inbuilt function

OUTPUT:

I=2

SIMULATION GRAPHS:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:39
INFERENCE: Traditional process of sampling-rate converter consists of ADC and DAC
converters which is a costly process. Hence interpolators and decimators are used. First the
signal is passed through a up-sampler and then passed through a low-pass filter. Low pass filter
output is then passed through a down-sampler and output of down-sampler is y(n)
Sampling rate converter:-
x(n) Up-Sampler Low-pass filter Down sampler y(n)

RESULT: Sampling rate converter has been implemented using a MATLAB program and
spectrums of up-sampled and interpolated signal have been plotted.

AIM:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:40
SOFTWARE USED: MATLAB R-2020a

PROGRAM:

% CLEARING PREVIOUS CONTENTS


clc;
close all;
clear all;
number = input('Enter the number in single quotes: ');
L = length(number);
t = [0:0.01:0.5]'; %t(time vector) is a column matrix
x = 2*pi*[697 770 852 941]; %fixed frequencies for rows of dial pad
y = 2*pi*[1209 1336 1477]; %fixed frequencies for columns of dial pad
tx = [sin(x(1)*t) sin(x(2)*t) sin(x(3)*t) sin(x(4)*t)];
ty = [sin(y(1)*t) sin(y(2)*t) sin(y(3)*t)];
for i=1:L
switch number(i)
case'1'
tone = tx(:,1) + ty(:,1);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 1');
case'2'
tone = tx(:,1) + ty(:,2);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 2');
case'3'
tone = tx(:,1) + ty(:,3);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 3');
case'4'
tone = tx(:,2) + ty(:,1);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 4');
case'5'
tone = tx(:,2) + ty(:,2);
sound(tone);
subplot(4,3,i);

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:41
stem(tone);
title('tone for number 5');
case'6'
tone = tx(:,2) + ty(:,3);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 6');
case'7'
tone = tx(:,3) + ty(:,1);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 7');
case'8'
tone = tx(:,3) + ty(:,2);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 8');
case'9'
tone = tx(:,3) + ty(:,3);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 9');
case'*'
tone = tx(:,4) + ty(:,1);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number *');
case'0'
tone = tx(:,4) + ty(:,2);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number 0');
case'#'
tone = tx(:,4) + ty(:,3);
sound(tone);
subplot(4,3,i);
stem(tone);
title('tone for number #');

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:42
otherwise
disp('invalid number');
sound(sin(2*pi*5600*t));
end
pause(1)%delay between successive tones
end

OUTPUT:
Enter the number in single quotes:
'0123456789*#'

Simulation Graphs:

INFERENCE:

RESULT:

DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:43

You might also like