DSP Record
DSP Record
Pole-Zero maps in Z-Plane for the given transfer function using MATLAB.
PROGRAM:
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
-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:
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.
PROGRAM:
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)
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)
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:
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.
PROGRAM:
DSP LABAY: 2020-21 SEM: I Class: 3/4B.Tech ECE- B Roll No: 18251A04C0 Page No:6
clc;
close all;
clear all;
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]
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.
PROGRAM:
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.
PROGRAM:
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.
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
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
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.
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:
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');
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.
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.
PROGRAM:
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.
PROGRAM:
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:
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