SlideShare a Scribd company logo
1 of 30
Lab-1
Q1 generate and plot each of the followingseqencesoverthe interval –n:n determinedbyyour roll
numberas shown below
1)
clc
clearall
close all
n=(58/2)+5
N=-n:1:n
x=2*(N==-2)-(N==4)
stem(N,x)
xlabel('Time')
ylabel('Amplitude')
title('Graphof x')
Q2 generate the followingcomplex valuedsignal and plotits magnitudesphase and the real part and
the imajinarypart in four separate subplots…
X4(n)=e^(-0.1+j0.3)n
clc
clearall
close all
n=(58/2)+5
N=-n:1:n
x= N.*((N>=0) - (N>=10)+( (10.*exp(-0.3*(N-10))).*((N>=10)-(N>=20) ) ) )
stem(N,x)
xlabel('Time')
ylabel('Amplitude')
title('Graphof x')
Q2
clc
clearall
close all
n=(58/2)+5
N=-n:2:n
x=exp((-0.1+j*0.3)*N)
subplot(2,2,1)
stem(N,abs(x))
xlabel('Time')
ylabel('Amplitude')
legend('Magnitude')
subplot(2,2,2)
stem(N,angle(x))
xlabel('Time')
ylabel('Amplitude')
legend('Phase')
subplot(2,2,3)
stem(N,imag(x))
xlabel('Time')
ylabel('Amplitude')
legend('Imaginarypart')
subplot(2,2,4)
stem(N,real(x))
xlabel('Time')
ylabel('Amplitude')
legend('Real part')
Lab1
Creatinga user definedfunction
Write a matlab functionfor followingbasicseuences.functionshouldtake input variablesn0,n1,n2
and returns x and n.as givenby equations
task1(a)
unitsample
function [x,n] = impseq( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[(n-n0)==0]%logical operation for comparison
stem(n,x)
end
task1(b)
unitstep
function [x,n] = impseq( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[(n-n0)>=0]
stem(n,x)
end
task1(c)
rise function
function [x,n] = exp1( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[exp(n-n0)]
stem(n,x)
end
task1(d)
decay funtion
function [x,n] = exp1( n0,n1,n2 )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
n=[n1:n2]%range
x=[exp(-1.*(n-n0))]
stem(n,x)
end
write matlab recursive function code to compute the factorial of
number .also verify ur function
task 2 (a)
function [y] =fact( x )
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
if x>1
n = 1
y=x*fact(x-1)
else
y=1
end
Plot the following two signals together in the same plot
X1(t)=cos(t) and x2(t)=sin(t+pi/2)
Where t=0 to 2sec
pre lab task 3(a)
clc
close all
clear all
t=0:2
x1=cos(t)
x2=sin(t+(pi/2))
plot(t,x1,'G')
title('cosine signal')
xlabel('time')
ylabel('amplitude')
grid on
hold on
plot(t,x2,'R*')
xlabel('time')
ylabel('amplitude')
legend('sin(t+(pi/2))','cos(t)')
grid on
pre lab task 3(b)
clc
close all
clear all
t=0:2
x1=3.*cos(3*pi*t+(pi/3))
plot(t,x1,'G')
title('cosine signal')
xlabel('time')
ylabel('amplitude')
legend('3.*cos(3*pi*t=(pi/3))')
grid on
Q1 generate and plot each of the followingseqencesoverthe interval –n:n determinedbyyour roll
numberas shown below
pre lab task 1(a)
clc
close all
clear all
n=57
x1=2.*((n)==2)-((n)==4)
stem(n,x1,'G')
title('functi0n ')
xlabel('time')
ylabel('amplitude')
legend('2*((n-2)==0)-((n-4)==0)')
grid on
Lab 2
Task 1
Consider the following continuose time sinusoidal signal
Xa(t)=cos(2pi f t) 0<=t<=2
Plot the discrete time signal x(n),0<=n<=19 for sampling frequency Fs=100H and f=10,50 and
90 Hz compare the graph by identifying similarities and differences .
clc
clearall
closeall
Fs=100
t=1/Fs
n=0:t:19.*t
f=10
f1=50
f2=90
x1=cos(2.*pi.*f.*n)
x2=cos(2.*pi.*f1.*n)
x3=cos(2.*pi.*f2.*n)
subplot(3,1,1)
stem(n,x1)
xlabel('Time')
ylabel('Amplitude')
legend('x1=cos(2.*pi.*f.*n)')
title('GRAPH OF x1')
subplot(3,1,2)
stem(n,x2)
xlabel('Time')
ylabel('Amplitude')
legend('x1=cos(2.*pi.*f1.*n)')
title('GRAPH OF x2')
subplot(3,1,3)
stem(n,x3)
xlabel('Time')
ylabel('Amplitude')
legend('x1=cos(2.*pi.*f2.*n)')
title('GRAPH OF x3')
b)Quantize the signal x(n)for f=10Hz using 4 bits and plot sampled , quantized and error signal
on same figure
clc
clearall
closeall
f=10
n=4
L=2^n
t=0:1/(2*f):2
x=cos(2*pi*f*t)
D=[(max(x)-min(x))]/L //levels nikalta han
xq=quant(x,D) //quantize
error=x-xq //error
figure
stairs(t,xq)//levels ko plot
ylim([-5 5])//limits for y axis
xlabel('Time')
ylabel('Amplitude')
legend('Quantized')
title('GRAPH OF xq')
figure
stem(t,error)
ylim([-5 5])
xlabel('Time')
ylabel('Amplitude')
legend('Error')
title('GRAPH OF ERROR')
figure
stem(t,x)
ylim([-5 5])
xlabel('Time')
ylabel('Amplitude')
legend('Sample')
title('GRAPH OF SAMPLE')
c)Quantize the sampled signal x(n) for f=100Hz using 4,5 and 6 bits respectively ,compute the
difference in the output by computing SQNRT
clc
clearall
closeall
f=100
n1=4
n2=5
n3=6
L1=2^n1
L2=2^n2
L3=2^n3
t=0:(1/(pi)):2
x=cos(2*pi*f*t)%
D1=[(max(x)-min(x))]/L1
D2=[(max(x)-min(x))]/L2
D3=[(max(x)-min(x))]/L3
xq1=quant(x,D1)%
xq2=quant(x,D2)
xq3=quant(x,D3)%
error1=x-xq1
error2=x-xq2
error3=x-xq3
SQNR1=10.*log10(sum(x.^2)/sum(error1.^2))
SQNR2=10.*log10(sum(x.^2)/sum(error2.^2))
SQNR3=10.*log10(sum(x.^2)/sum(error3.^2))
Task 2
Given the digital speech signal in the file guitartune wav write a Matlab program to
a) Read the audio file and find sampling frequency
b) Quantize x(z) using 4 bit quantizers to obtain the quantized signal xq, assuming the signal
range isfrom -1 to 1 volts
c) plot the original speech and quantization error.
d) calculate the SQNRT
clc
clearall
closeall
[x,fs]=audioread('guitartune.wav')
n=4
L=2.^n
t=0.1:length(x-1)
D=[1-(-1/L)]
xq=quant(x,D)
error=x-xq
subplot(3,1,1)
stairs(t,xq)
xlabel('Time')
ylabel('Amplitude')
legend('Quantized')
title('GRAPH OF xq')
subplot(3,1,2)
stem(t,error)
xlabel('Time')
ylabel('Amplitude')
legend('Error')
title('GRAPH OF ERROR')
subplot(3,1,3)
stem(t,x)
xlabel('Time')
ylabel('Amplitude')
legend('Sample')
title('GRAPH OF SAMPLE')
SQNR=10.*log10(sum(x.^2)/sum(error.^2))
TASK 3
1.Write your own custome function which is able to simulate a uniform quantizer .the inputs
should contain sampled signal numberof bits used in quantization and return quantized and
error signal
2.write ur own custom function which able to the SQNRT due to
quantization
function [ error, xq, SQNR ] = q( x, n)
L=2.^n
D=(max(x)-min(x))/L
xq=quant(x,D)
error=x-xq
SQNR=10.*log10(sum(x.^2)/sum(error.^2))
end
or
function [ error, xq, SQNR ] = q( x, n)
% Quantized
max=20
min=0
L=2.^n
D=(max-min)/L
xq=quant(x,D)
error=x-xq
SQNR=10.*log10(sum(x.^2)/sum(error.^2))
end
Lab 3
Task 1
Given the following two sequence determine the convolution
y[n].plot each step in the subplot.
X[n]=[3,11,7,0,-1,4,2] -3<=n<=3; h[n]=[2,0,-5,2,1] -1<=n<=4
clc
clearall
closeall
x=[3 11 7 0 -1 4 2]
h=[2 3 0 -5 2 1]
n1=[-3:3]
n2=[-1:4]
c=conv(x,h)
subplot(3,1,1)
stem(n1,x)
xlabel('Time')
ylabel('Amplitude')
legend('x')
title('GRAPH OF x')
subplot(3,1,2)
stem(n2,h)
xlabel('Time')
ylabel('Amplitude')
legend('h')
title('GRAPH OF h')
subplot(3,1,3)
stem(c)
xlabel('Time')
ylabel('Amplitude')
legend('y(n)=x(n)*h(n)')
title('GRAPH OF x(n)*h(n)')
Task-2
Write a matlab fuctionto systematicallydevelopthe sequence y[n]generatedbythe convolutionof
the two finite lengthsequence x[n]andh[n] program shouldbe able to handle causal and non causal
sequences.youshouldverifythis functionalityof the program .program shouldcall for the input
sequencesandtheir indicesvectors
function [ y,ny ] = convo_1(nx,nh,x,h )
ny1=nx(1)+nh(1)
ny2=nx(length(x))+nh(length(h))
ny=[ny1:ny2]
y=conv(x,h)
end
Task3:
lab 4
clc
clear all
close all
num=[4 3 9]
den=[4 3 -4]
H=num/den
[R,p,K] = residuez(num,den) [z,p,K] = tf2zp(num,den)
zplane(z,p
[sos,g]=zp2sos(z,p,K)
TASK 1
Determine the rational Z-Transform from its polesand zero locations.The zeros are at ζ1 = 0.21, ζ2 =
3.14 , ζ3 = −0.3 + 𝑗 0.5 , ζ4= −0.3 − 𝑗0.5 And polesare at 𝜆1= −0.45 , 𝜆2 = −0.67, 𝜆3= 0.81 + 𝑗 0.72 , 𝜆4=
0.81 − 𝑗0.72 and the gain constant is 2.2.
clc
clear all
close all
z=[0.21;3.14;-0.3+0.5i;-0.3-0.5i]
p=[-0.45;-0.67;0.81+0.72i;0.81-0.72j]
k=2.2
[num,den] = zp2tf(z,p,k)%
tf(num,den,-1)
task 2
UsingMATLAB, determine the partial fraction expansionofthe z transform (𝑧),givenby
clc
clear all
close all
syms z
num=[18 0 0 0]
den=[18 3 -4 -1]
Hz=num/den
[r,p,K] = residuez(num,den) //for partial fraction
p=[(r(1)/(1-p(1).*z.^(-1)))+(r(2)/(1-p(2).*z.^(-1)))+(r(3)/(1-p(3).*z.^(-
1)))]
pretty(p)
task 3
Determine the rational form of z transform from its partial fraction expansion of the
following z transforms and then determine theirinverse z transform. Write down your
analysis.
clc
clear all
close all
num=[1 -1 0]
den=[1 1.3 0.3]
[R,p,K] = residuez(num,den)
[z,p,K] = tf2zp(num,den)
zplane(z,p)
zplane(z,p)
A) casual andmarginal stable
B) Anti-causal andunstable b/cnotinclude unitcircle
C) non-causal andstable
Lab 6
pre lab
Write a MATLAB functionto compute K-pointDFT and IDFT of N-pointsequence.The function should
take sequence (array),integervalue K and binary value switchto decide ifto compute DFT or IDFT.
The functionshouldreturn the sequence aftercomputation.
function [y] = lab6(x,N,b )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here
if b==1
n=[0:1:N-1]
k=[0:1:N-1]
WN=exp(-j*2*pi/N)
nk=n'*k
WNnk=WN.^nk
y=x*WNnk;
else if b==0
n=[0:1:N-1]
k=[0:1:N-1]
WN=exp(-j*2*pi/N);
nk=n'*k
WNnk=WN.^(-nk);
y=x*WNnk/N;
end
end
task-1
Compute the M-pointDFT of the followingN-pointsequence.
u(n)={1 ,0<=n<=N-1
0 , otherwise}
compute the M pointDFT
clc
close all
clear all
N=5
M=7
n=0:1:N-1
x=1.*(n>=0)
y=dft(+x,M,N)
task-3
Write a MATLAB program to compute the circular convolution oftwo length- N sequences via
DFT based approach. Using this program determine the circular convolution ofthe following pairs
of sequences.
a) 𝑔[𝑛] = {3 ,4 − 2 ,0 , 1 , −4} , ℎ[𝑛] = { 1,−3, 0,4 , −2 , 3}
b)x[n]=sin(pi*n)/2,y[n] =(roll number)^n 0<=n<=4
clc
close all
clear all
g=[3,4'-2,0,1,-4]
h=[1,-3,0,4,-2,3]
c=cconv(g,h)
stem(c)
:
question
function [y] = lab6( x,N,b )
%b is the value of switch
if b==1
n=[0:1:N-1]
k=[0:1:N-1]
WN=exp(-j*2*pi)/N;
nk=n'*k
WNnk=WN.^nk;
y=x*WNnk
else if b==0
n=[0:1:N-1];
k=[0:1:N-1]
WN=exp(-j*2*pi/N);
nk=n'*k;
WNnk=WN.^(-nk);
y=(x*WNnk)/N;
end
end
output:
>> lab6
Error usinglab6(line 4)
Notenoughinputarguments.
>> b=1
b =
1
>> x=[1 2 3 4 5]
x =
1 2 3 4 5
>> N=5
N =
5
>> [y] = lab6( x,N,b)
n =
0 1 2 3 4
k =
0 1 2 3 4
nk =
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
0 3 6 9 12
0 4 8 12 16
Undefinedfunctionorvariable "WNnk".
Error inlab6 (line 10)
y=x*WNnk
>> [y] = lab6( x,N,b)
n =
0 1 2 3 4
k =
0 1 2 3 4
nk =
0 0 0 0 0
0 1 2 3 4
0 2 4 6 8
0 3 6 9 12
0 4 8 12 16
y =
15.0000 + 0.0000i 1.5600 + 0.0000i 1.0851 + 0.0000i 1.0162 + 0.0000i 1.0032 + 0.0000i
y =
15.0000 + 0.0000i 1.5600 + 0.0000i 1.0851 + 0.0000i 1.0162 + 0.0000i 1.0032 + 0.0000i
>>
Lab 7
TASK-1
Write MATLAB code that determines and plot the N-point Discrete Fourier Transform of
x[n]defined by the following equations:
x(n)=sin(0.5pi*n), 0<=n<=16
Compute and plot 16-point DFT usingtwo 8-pointFFTs and combiningtechniques.
function [y]=fft16(x)
%stage1
for n=0:1:7
twiddle=exp(-2*pi*j*n*1/16)
x1(n+1)=x(n+1)+x(n+9)
x1(n+9)=(x(n+1)-x(n+9))*twiddle;
end
%stage 2
for n=0:1:3
twiddle=exp(-2*pi*j*n*1/8)
x2(n+1)=x1(n+1)+x1(n+5)
x2(n+5)=(x1(n+1)-x(n+5))*twiddle;
x2(n+9)=x1(n+9)+x1(n+13);
x2(n+13)=x1(n+9)-x1(n+13)*twiddle;
end
%stage 3
for n=0:1:1
twiddle=exp(-2*pi*j*n*1/4)
x3(n+1)=x2(n+1)+x2(n+3)
x3(n+3)=(x2(n+1)-x2(n+3))*twiddle
x3(n+5)=x2(n+5)+x2(n+7)
x3(n+7)=(x2(n+5)-x2(n+7))*twiddle
x3(n+9)=x2(n+9)+x2(n+11)
x3(n+11)=(x2(n+9)-x2(n+11))*twiddle
x3(n+13)=x2(n+13)+x2(n+15)
x3(n+15)=(x2(n+13)-x2(n+15))*twiddle
end
%stage 4
twiddle=exp(-2*pi*j*n*1/2)
x4(1)=x3(1)+x3(2)
x4(2)=(x3(1)-x3(2))*twiddle
x4(3)=x3(3)+x3(4)
x4(4)=(x3(3)-x3(4))*twiddle
x4(5)=x3(5)+x3(6)
x4(6)=(x3(5)-x3(6))*twiddle
x4(7)=x3(7)+x3(8)
x4(8)=(x3(7)-x3(8))*twiddle
x4(9)=x3(9)+x3(10)
x4(10)=(x3(9)-x3(10))*twiddle
x4(11)=x3(11)+x3(12)
x4(12)=(x3(11)-x3(12))*twiddle
x4(13)=x3(13)+x3(14)
x4(14)=(x3(13)-x3(14))*twiddle
x4(15)=x3(15)+x3(16)
x4(16)=(x3(15)-x3(16))*twiddle
y=bitrevorder(x4);
end
****Calling Mfile****
clc
clear all
close all
a=16
n=0:15
x=sin(0.5*pi*n)
f1=fft(x)
subplot(211)
stem(abs(f1))
title('matlab fft')
f2=fft16(x)
subplot(212)
stem(abs(f2))
title('self made function fft')
TASK-2
Write MATLAB code to compare the efficiency linear convolution and the high-speed convolution
times for 5 ≤ N ≤ 150
clc
clear all
close all
conv_time = zeros(1,150); fft_time = zeros(1,150);
%
for L = 1:150
tc = 0; tf=0;
N = 2*L-1; I=1
nu = ceil(log10(N*I)/log10(2)); N = 2^nu;
for I=1:100
h = randn(1,L); x = rand(1,L);
t0 = clock; y1 = conv(h,x); t1=etime(clock,t0); tc = tc+t1;
t0 = clock; y2 = ifft(fft(h,N).*fft(x,N)); t2=etime(clock,t0);
tf = tf+t2;
end
%
conv_time(L)=tc/100; fft_time(L)=tf/100;
end
n=1:150;
subplot(1,1,1);
plot(n(25:150),conv_time(25:150),n(25:150),fft_time(25:150))
TASK-3
Write a MATLAB functionto implementablock convolutionalgorithm calledthe overlap-and-save
method(and its companion the overlap-and-addmethod),whichis usedto convolve a very large
sequence witha relativelysmallersequence.
Function [y] = ovrlpsav(x,h,N)
% Overlap-Save method of block convolution
% ----------------------------------------
% [y] = ovrlpsav(x,h,N)
% y = output sequence
% x = input sequence
% h = impulse response
% N = block length
Lenx = length(x)
M = length(h)
M1 = M-1; L = N-M1
h = [h zeros(1,N-M)]
%
x = [zeros(1,M1), x, zeros(1,N-1)] % preappend (M-1) zeros
K = floor((Lenx+M1-1)/(L)) % # of blocks
Y = zeros(K+1,N)
% convolution with succesive blocks
for k=0:K
xk = x(k*L+1:k*L+N)
Y(k+1,:) = circonvt(xk,h,N)
end
Y = Y(:,M:N) % discard the first (M-1) samples
y = (Y(:))' ; % assemble output
TASK-4
Usingthe functionof task 3, write a MATLAB program to implementlength-Nmovingaverage filterto
filtera noise corrupted signal. Where Nis class Roll Number.
clc
clear all
close all
n=1:5
s=n*pi
subplot(221)
stem(s)
title('original signal')
d=rand(1,5)
subplot(222)
stem(d)
title('noise ')
p=ovrlpsav(s,d,6),
subplot(223)
stem(p)
title('corrupted signal')
m=5
xu=0
for i=1:m
x=s+d
xu=xu+x
end
xu=xu/m
subplot(224)
stem(xu)
title('filtered signal')
lab 8
Task 1
Build a SIMULINK model for Sampling and Reconstruction ofanalog signal
where,
R = Your Reg. Number
i i) Sample the analog signal x(t) at 8 times the Nyquistrate.
ii ii) Non-uniformly quantize the discrete time signal using μ-lawcompanding method, μ=255
and number of quantization levels = 16.
iii iii) Encode and Decode the signal into binary.
iv iv) Reconstruct the analog signal.
v v) Show both time and frequency domain results.
% A simple sampling and reconstruction model for students
% beginners of Digital Signal Processing
% by Mukhtar Hussain (Email: mukhtarhussain@ciitlahore.edu.pk)
% f - The frequency of analog sinosoid signal
% F - Sampling Rate
% qbits - Number of Quantizations bits
% A - Amplitude of sinusoid signal
% L - Number of quantization levels based on qbits
% I - Quantization Interval
% sim_time - Simultaion Time
% span - x-axis range of frequency plot 1 & 3 (spectrum scope 1 & 3)
% span1 - x-axis range of frequency plot 2 (spectrum scope 2)
% NFFT - Number of FFT points
clc;
clear;
close all;
f = input('Enter the frequency of signal = ');
F = input('Enter the sampling frequency = ');
A = input('Enter max amplitude of signal = ');
qbits = input('Enter the number of quantization bits = ');
fc = input('Enter the lowpass filter cutoff frequency = ');
L = 2^qbits;
I = 2*A/(L-1);
% Settings for
Spectrum Scope
span = 8*F;
span1 = 8*F;
NFFT = 256;
% To run simulink model
t = 1/f;
sim_time = 10*t;
sim('sampling.slx');
TASk 2
Write MATLAB Code to
i i) Plot discrete time sampled signal sampled at FS = 8R [] xn
ii ii) Non-uniformly quantize the discrete time signal using μ-lawcompanding method, μ=100
and number of bits = 8
iii iii) Encode the signal into discrete levels.
iv iv) Decode the signal from discrete level and reconstruct using spline and cubic
interpolation to
v v) Analyze which interpolation method performs better.
clc
clear all
close all
t=0:0.001:1
fm=10
fs=1000
N=8
L=2.^N
%message signals
x=sin(2*pi*fm*t)
figure
subplot 211
plot(t,x)
title('message signal')
xlabel('time')
ylabel('amplitude')
%pulse traain
d=0:1/50:1
y=pulstran(t,d,'rectpuls',0.001)
subplot 212
plot(t,y)
title('pulse train')
xlabel('time')
ylabel('amplitude')
%sampling
z=x.*y
figure
subplot 211
plot(t,z)
title('sampled signal')
xlabel('time')
ylabel('amplitude')
%quantization
D=[max(x)-min(x)]/(L-1)
xq=quant(x,D)
subplot 212
plot(t,xq)
title('quantized signal')
xlabel('time')
ylabel('amplitude')
%encoder
H_e=dsp.UniformEncoder(max(xq),N)
encoder=step(H_e,xq)
figure
subplot 211
plot(t,encoder)
title('encoded signal')
xlabel('time')
ylabel('amplitude')
%decoder
H_d=dsp.UniformDecoder(max(xq),N)
decoder=step(H_d,encoder)
subplot 212
plot(t,decoder)
title('decoded sig')
xlabel('time')
ylabel('amplitude')
%interpolation
time=0:1/(2*fs):5
interpolation=interp1(t,decoder,time)
figure
subplot 211
plot(time,interpolation)
title('interpolation')
%SC interpolation
subplot 212
xx=0:0.001:1
sc=spline(t,x,xx)
plot(t,sc)
title('spline interpolation')
LAB 11
Round ki command used for
dfilt ki command used for design filter
H1=dfilt.df1(num,den)
fvtool ki command used for ploting filter
IIR
clc
clear all
close all
syms z
H1N=[2 0 2]
H1D=[1 -0.8 0.64]
H2N=[4 -2]
H2D=[1 -0.75]
H3N=[2 4 2]
H3D=[1 0 0.81]
A1=conv(H1N,H2N)
HN=conv(A1,H3N)
A2=conv(H1D,H2D)
HD=conv(A2,H3D)
num=round(HN,3)
den=round(HD,3)
H1=dfilt.df1(num,den)
fvtool(H1)
H2=dfilt.df2(num,den)
fvtool(H2)
H3=dfilt.cascade(H1,H2)
fvtool(H3)
FIR
% phase responce linearhotaha
% num hotaha or den1 hota ha
clc
clear all
close all
syms z
H1N=[2 0 2]
H1D=[1 -0.8 0.64]
H2N=[4 -2]
H2D=[1 -0.75]
H3N=[2 4 2]
H3D=[1 0 0.81]
A1=conv(H1N,H2N)
HN=conv(A1,H3N)
A2=conv(H1D,H2D)
HD=conv(A2,H3D)
num=round(HN,3)
den=round(HD,3)
H1=dfilt.dffir(num)
fvtool(H1)
H2=dfilt.dffirt(num)
fvtool(H2)
LAB 12
Task 1
Designa band pass Chebyshev Type II filter using analog prototyping. The order
of filter is 20 witha value of 60 dB stop band attenuationand 0.75dB pass band
ripple where, Pass band edge = 800Hz Stopband edge=2000HzSampling
frequency = 6000
%Chebyshev
clc
clear all
close all
Rp=0.75
Rs=60
fp=800
fst=2000
fs=6000
ft=fs/2
wp=fp/ft
wst=fst/ft
%chebbyshev
[n1,wn]=cheb1ord(wp,wst,Rp,Rs)
[num,den]=cheby1(n1,Rp,wn)
[H,w]=freqz(num,den,512,fs)
plot(w,20*log10(abs(H)))
title('Chebbyshev mag in dB')
task 2
Design a Digital Bandpass IIR filter using Analog filter prototype and
Frequency Transformation. The filter should have following
specifications: Minimum order of the filter Lab Experiment | 12
Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab
Manual 83 Maximum passband = 0.5dB Minimum stopband
attenuation= 30 dB Pass band edge frequencies = (N-5) – (N+5) MHz
Stop band edge frequencies = (N-5.5) – (N+5.5) MHz Sampling rate of
8N MHz Where 𝑁 = { 10𝑅, 𝑖𝑓𝑅< 15 𝑅, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑤𝑒, 𝑀𝐻𝑧 𝑅 = 𝑌𝑜𝑢𝑟
𝑅𝑒𝑔. 𝑁𝑜. i) Give reason which filter type you would prefer based on
the specification ii) Compute the normalized passband and stopband
frequencies iii) Compute the order and transfer function of desired
filter iv) Properly present your results to show that your designed
filter meet the specification
%BANDPASS
clc
clear all
close all
Rp=0.5
Rs=30
fp=2000
fst=2500
N=13
fs=8*N
ft=fs/2
wp=fp/ft
wst=fst/ft
t=0:1/fs:4*(1/f1)
x=sin(2*pi*f*t)
X=fft(x)
subplot(2,2,1)
plot(t,x)
title('x(t)')
subplot(2,2,2)
plot(abs(fftshift(X)))
title('x(F)')
%Lowpass butterworth filter
[n,wn]=buttord(wp,wst,Rp,Rs)
[num,den]=butter(n1,wn1)
y=filter(num,den,x)
subplot(2,2,3)
plot(t,y)
title('y')
yf=fft(y)
subplot(2,2,4)
plot(abs(shift(yf)))
title('y(F)')
LAB 13
clc
clearall
close all
As=50
wp=0.2*pi
wst=0.3*pi
fs=16000
ft=fs/2
fp=wp*ft
fs=wst*ft
DelF=wst-wp
%filterorder=M
M=ciel((As-7.95)/(14.36*DelF))+1
%Byhann window
wn=(wp+wst)/2
win=hann(M)
num=fir1(M-1,wn,'Low',win)
[H,w]=freq2(num,1,512,fs)
subplot(1,2,1)
plot(w,20*log10(abs(H)))
title('Hanwindow MAGindB')
subplot(1,2,2)
plot(w,abs(H))
title('HannwindowMAGinlinearscale')

More Related Content

Similar to DSP LAB COMPLETE CODES.docx

Informe laboratorio n°1
Informe laboratorio n°1Informe laboratorio n°1
Informe laboratorio n°1luisescobedo38
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plottingAmr Rashed
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Alamgir Hossain
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab plotingAmeen San
 
Rosser's theorem
Rosser's theoremRosser's theorem
Rosser's theoremWathna
 
wavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdfwavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdfbrijeshagarwa329898l
 
Basic simulation lab manual1
Basic simulation lab manual1Basic simulation lab manual1
Basic simulation lab manual1Janardhana Raju M
 
Natural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesNatural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesMark Brandao
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programmingDamian T. Gordon
 
4.5 sec and csc worked 3rd
4.5   sec and csc worked 3rd4.5   sec and csc worked 3rd
4.5 sec and csc worked 3rdJonna Ramsey
 
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docxhyacinthshackley2629
 
Root Locus Method - Control System - Bsc Engineering
Root Locus Method - Control System - Bsc EngineeringRoot Locus Method - Control System - Bsc Engineering
Root Locus Method - Control System - Bsc Engineeringdexik15916
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Alexander Litvinenko
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)asghar123456
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfkarthikaparthasarath
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03Krish_ver2
 

Similar to DSP LAB COMPLETE CODES.docx (20)

Informe laboratorio n°1
Informe laboratorio n°1Informe laboratorio n°1
Informe laboratorio n°1
 
Matlab plotting
Matlab plottingMatlab plotting
Matlab plotting
 
Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report Digital signal Processing all matlab code with Lab report
Digital signal Processing all matlab code with Lab report
 
Matlab ploting
Matlab plotingMatlab ploting
Matlab ploting
 
Rosser's theorem
Rosser's theoremRosser's theorem
Rosser's theorem
 
Recursion in C
Recursion in CRecursion in C
Recursion in C
 
wavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdfwavelet decomposition process code in matlabSolution WAVE.pdf
wavelet decomposition process code in matlabSolution WAVE.pdf
 
Basic simulation lab manual1
Basic simulation lab manual1Basic simulation lab manual1
Basic simulation lab manual1
 
Natural and Clamped Cubic Splines
Natural and Clamped Cubic SplinesNatural and Clamped Cubic Splines
Natural and Clamped Cubic Splines
 
Introduction to MatLab programming
Introduction to MatLab programmingIntroduction to MatLab programming
Introduction to MatLab programming
 
4.5 sec and csc worked 3rd
4.5   sec and csc worked 3rd4.5   sec and csc worked 3rd
4.5 sec and csc worked 3rd
 
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx17, r) -,r I  -l19.t... 121.2t-314 23. ^t -rr - .docx
17, r) -,r I -l19.t... 121.2t-314 23. ^t -rr - .docx
 
Dsp Lab Record
Dsp Lab RecordDsp Lab Record
Dsp Lab Record
 
Root Locus Method - Control System - Bsc Engineering
Root Locus Method - Control System - Bsc EngineeringRoot Locus Method - Control System - Bsc Engineering
Root Locus Method - Control System - Bsc Engineering
 
Dsp lab task1 ganesh
Dsp lab task1 ganeshDsp lab task1 ganesh
Dsp lab task1 ganesh
 
Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics Tucker tensor analysis of Matern functions in spatial statistics
Tucker tensor analysis of Matern functions in spatial statistics
 
Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)Amth250 octave matlab some solutions (1)
Amth250 octave matlab some solutions (1)
 
3.pdf
3.pdf3.pdf
3.pdf
 
BUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdfBUilt in Functions and Simple programs in R.pdf
BUilt in Functions and Simple programs in R.pdf
 
5.2 divede and conquer 03
5.2 divede and conquer 035.2 divede and conquer 03
5.2 divede and conquer 03
 

Recently uploaded

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSKurinjimalarL3
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxDeepakSakkari2
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escortsranjana rawat
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerAnamika Sarkar
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLDeelipZope
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingrakeshbaidya232001
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escortsranjana rawat
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxupamatechverse
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsCall Girls in Nagpur High Profile
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Dr.Costas Sachpazis
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxJoão Esperancinha
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...ranjana rawat
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxupamatechverse
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxAsutosh Ranjan
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSCAESB
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile servicerehmti665
 

Recently uploaded (20)

APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICSAPPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
APPLICATIONS-AC/DC DRIVES-OPERATING CHARACTERISTICS
 
Biology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptxBiology for Computer Engineers Course Handout.pptx
Biology for Computer Engineers Course Handout.pptx
 
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Isha Call 7001035870 Meet With Nagpur Escorts
 
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCRCall Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
Call Us -/9953056974- Call Girls In Vikaspuri-/- Delhi NCR
 
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(PRIYA) Rajgurunagar Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube ExchangerStudy on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
Study on Air-Water & Water-Water Heat Exchange in a Finned Tube Exchanger
 
Current Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCLCurrent Transformer Drawing and GTP for MSETCL
Current Transformer Drawing and GTP for MSETCL
 
Porous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writingPorous Ceramics seminar and technical writing
Porous Ceramics seminar and technical writing
 
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
(MEERA) Dapodi Call Girls Just Call 7001035870 [ Cash on Delivery ] Pune Escorts
 
Introduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptxIntroduction and different types of Ethernet.pptx
Introduction and different types of Ethernet.pptx
 
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
★ CALL US 9953330565 ( HOT Young Call Girls In Badarpur delhi NCR
 
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur EscortsHigh Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
High Profile Call Girls Nagpur Meera Call 7001035870 Meet With Nagpur Escorts
 
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
Structural Analysis and Design of Foundations: A Comprehensive Handbook for S...
 
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptxDecoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
Decoding Kotlin - Your guide to solving the mysterious in Kotlin.pptx
 
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
9953056974 Call Girls In South Ex, Escorts (Delhi) NCR.pdf
 
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
(ANJALI) Dange Chowk Call Girls Just Call 7001035870 [ Cash on Delivery ] Pun...
 
Introduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptxIntroduction to Multiple Access Protocol.pptx
Introduction to Multiple Access Protocol.pptx
 
Coefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptxCoefficient of Thermal Expansion and their Importance.pptx
Coefficient of Thermal Expansion and their Importance.pptx
 
GDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentationGDSC ASEB Gen AI study jams presentation
GDSC ASEB Gen AI study jams presentation
 
Call Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile serviceCall Girls Delhi {Jodhpur} 9711199012 high profile service
Call Girls Delhi {Jodhpur} 9711199012 high profile service
 

DSP LAB COMPLETE CODES.docx

  • 1. Lab-1 Q1 generate and plot each of the followingseqencesoverthe interval –n:n determinedbyyour roll numberas shown below 1) clc clearall close all n=(58/2)+5 N=-n:1:n x=2*(N==-2)-(N==4) stem(N,x) xlabel('Time') ylabel('Amplitude') title('Graphof x') Q2 generate the followingcomplex valuedsignal and plotits magnitudesphase and the real part and the imajinarypart in four separate subplots… X4(n)=e^(-0.1+j0.3)n clc clearall close all n=(58/2)+5 N=-n:1:n x= N.*((N>=0) - (N>=10)+( (10.*exp(-0.3*(N-10))).*((N>=10)-(N>=20) ) ) ) stem(N,x) xlabel('Time') ylabel('Amplitude') title('Graphof x') Q2 clc clearall close all n=(58/2)+5 N=-n:2:n x=exp((-0.1+j*0.3)*N) subplot(2,2,1) stem(N,abs(x)) xlabel('Time') ylabel('Amplitude')
  • 2. legend('Magnitude') subplot(2,2,2) stem(N,angle(x)) xlabel('Time') ylabel('Amplitude') legend('Phase') subplot(2,2,3) stem(N,imag(x)) xlabel('Time') ylabel('Amplitude') legend('Imaginarypart') subplot(2,2,4) stem(N,real(x)) xlabel('Time') ylabel('Amplitude') legend('Real part') Lab1 Creatinga user definedfunction Write a matlab functionfor followingbasicseuences.functionshouldtake input variablesn0,n1,n2 and returns x and n.as givenby equations task1(a) unitsample function [x,n] = impseq( n0,n1,n2 ) %UNTITLED4 Summary of this function goes here % Detailed explanation goes here n=[n1:n2]%range x=[(n-n0)==0]%logical operation for comparison stem(n,x) end task1(b) unitstep function [x,n] = impseq( n0,n1,n2 ) %UNTITLED4 Summary of this function goes here % Detailed explanation goes here n=[n1:n2]%range x=[(n-n0)>=0] stem(n,x)
  • 3. end task1(c) rise function function [x,n] = exp1( n0,n1,n2 ) %UNTITLED4 Summary of this function goes here % Detailed explanation goes here n=[n1:n2]%range x=[exp(n-n0)] stem(n,x) end task1(d) decay funtion function [x,n] = exp1( n0,n1,n2 ) %UNTITLED4 Summary of this function goes here % Detailed explanation goes here n=[n1:n2]%range x=[exp(-1.*(n-n0))] stem(n,x) end write matlab recursive function code to compute the factorial of number .also verify ur function task 2 (a) function [y] =fact( x ) %UNTITLED4 Summary of this function goes here % Detailed explanation goes here if x>1 n = 1 y=x*fact(x-1) else y=1 end
  • 4. Plot the following two signals together in the same plot X1(t)=cos(t) and x2(t)=sin(t+pi/2) Where t=0 to 2sec pre lab task 3(a) clc close all clear all t=0:2 x1=cos(t) x2=sin(t+(pi/2)) plot(t,x1,'G') title('cosine signal') xlabel('time') ylabel('amplitude') grid on hold on plot(t,x2,'R*') xlabel('time') ylabel('amplitude') legend('sin(t+(pi/2))','cos(t)') grid on pre lab task 3(b) clc close all clear all t=0:2 x1=3.*cos(3*pi*t+(pi/3)) plot(t,x1,'G') title('cosine signal') xlabel('time') ylabel('amplitude') legend('3.*cos(3*pi*t=(pi/3))') grid on Q1 generate and plot each of the followingseqencesoverthe interval –n:n determinedbyyour roll numberas shown below pre lab task 1(a) clc close all clear all n=57 x1=2.*((n)==2)-((n)==4)
  • 5. stem(n,x1,'G') title('functi0n ') xlabel('time') ylabel('amplitude') legend('2*((n-2)==0)-((n-4)==0)') grid on Lab 2 Task 1 Consider the following continuose time sinusoidal signal Xa(t)=cos(2pi f t) 0<=t<=2 Plot the discrete time signal x(n),0<=n<=19 for sampling frequency Fs=100H and f=10,50 and 90 Hz compare the graph by identifying similarities and differences . clc clearall closeall Fs=100 t=1/Fs n=0:t:19.*t f=10 f1=50 f2=90 x1=cos(2.*pi.*f.*n) x2=cos(2.*pi.*f1.*n) x3=cos(2.*pi.*f2.*n) subplot(3,1,1) stem(n,x1) xlabel('Time') ylabel('Amplitude') legend('x1=cos(2.*pi.*f.*n)') title('GRAPH OF x1') subplot(3,1,2) stem(n,x2) xlabel('Time')
  • 6. ylabel('Amplitude') legend('x1=cos(2.*pi.*f1.*n)') title('GRAPH OF x2') subplot(3,1,3) stem(n,x3) xlabel('Time') ylabel('Amplitude') legend('x1=cos(2.*pi.*f2.*n)') title('GRAPH OF x3') b)Quantize the signal x(n)for f=10Hz using 4 bits and plot sampled , quantized and error signal on same figure clc clearall closeall f=10 n=4 L=2^n t=0:1/(2*f):2 x=cos(2*pi*f*t) D=[(max(x)-min(x))]/L //levels nikalta han xq=quant(x,D) //quantize error=x-xq //error figure stairs(t,xq)//levels ko plot ylim([-5 5])//limits for y axis xlabel('Time') ylabel('Amplitude') legend('Quantized') title('GRAPH OF xq')
  • 7. figure stem(t,error) ylim([-5 5]) xlabel('Time') ylabel('Amplitude') legend('Error') title('GRAPH OF ERROR') figure stem(t,x) ylim([-5 5]) xlabel('Time') ylabel('Amplitude') legend('Sample') title('GRAPH OF SAMPLE') c)Quantize the sampled signal x(n) for f=100Hz using 4,5 and 6 bits respectively ,compute the difference in the output by computing SQNRT clc clearall closeall f=100 n1=4 n2=5 n3=6 L1=2^n1 L2=2^n2 L3=2^n3 t=0:(1/(pi)):2 x=cos(2*pi*f*t)% D1=[(max(x)-min(x))]/L1 D2=[(max(x)-min(x))]/L2 D3=[(max(x)-min(x))]/L3 xq1=quant(x,D1)% xq2=quant(x,D2)
  • 8. xq3=quant(x,D3)% error1=x-xq1 error2=x-xq2 error3=x-xq3 SQNR1=10.*log10(sum(x.^2)/sum(error1.^2)) SQNR2=10.*log10(sum(x.^2)/sum(error2.^2)) SQNR3=10.*log10(sum(x.^2)/sum(error3.^2)) Task 2 Given the digital speech signal in the file guitartune wav write a Matlab program to a) Read the audio file and find sampling frequency b) Quantize x(z) using 4 bit quantizers to obtain the quantized signal xq, assuming the signal range isfrom -1 to 1 volts c) plot the original speech and quantization error. d) calculate the SQNRT clc clearall closeall [x,fs]=audioread('guitartune.wav') n=4 L=2.^n t=0.1:length(x-1) D=[1-(-1/L)] xq=quant(x,D) error=x-xq subplot(3,1,1) stairs(t,xq) xlabel('Time') ylabel('Amplitude') legend('Quantized') title('GRAPH OF xq') subplot(3,1,2) stem(t,error) xlabel('Time') ylabel('Amplitude') legend('Error') title('GRAPH OF ERROR') subplot(3,1,3) stem(t,x) xlabel('Time')
  • 9. ylabel('Amplitude') legend('Sample') title('GRAPH OF SAMPLE') SQNR=10.*log10(sum(x.^2)/sum(error.^2)) TASK 3 1.Write your own custome function which is able to simulate a uniform quantizer .the inputs should contain sampled signal numberof bits used in quantization and return quantized and error signal 2.write ur own custom function which able to the SQNRT due to quantization function [ error, xq, SQNR ] = q( x, n) L=2.^n D=(max(x)-min(x))/L xq=quant(x,D) error=x-xq SQNR=10.*log10(sum(x.^2)/sum(error.^2)) end or function [ error, xq, SQNR ] = q( x, n) % Quantized max=20 min=0 L=2.^n D=(max-min)/L xq=quant(x,D) error=x-xq SQNR=10.*log10(sum(x.^2)/sum(error.^2)) end Lab 3 Task 1 Given the following two sequence determine the convolution y[n].plot each step in the subplot. X[n]=[3,11,7,0,-1,4,2] -3<=n<=3; h[n]=[2,0,-5,2,1] -1<=n<=4 clc clearall closeall
  • 10. x=[3 11 7 0 -1 4 2] h=[2 3 0 -5 2 1] n1=[-3:3] n2=[-1:4] c=conv(x,h) subplot(3,1,1) stem(n1,x) xlabel('Time') ylabel('Amplitude') legend('x') title('GRAPH OF x') subplot(3,1,2) stem(n2,h) xlabel('Time') ylabel('Amplitude') legend('h') title('GRAPH OF h') subplot(3,1,3) stem(c) xlabel('Time') ylabel('Amplitude') legend('y(n)=x(n)*h(n)') title('GRAPH OF x(n)*h(n)') Task-2 Write a matlab fuctionto systematicallydevelopthe sequence y[n]generatedbythe convolutionof the two finite lengthsequence x[n]andh[n] program shouldbe able to handle causal and non causal sequences.youshouldverifythis functionalityof the program .program shouldcall for the input sequencesandtheir indicesvectors function [ y,ny ] = convo_1(nx,nh,x,h ) ny1=nx(1)+nh(1) ny2=nx(length(x))+nh(length(h)) ny=[ny1:ny2] y=conv(x,h) end Task3:
  • 11. lab 4 clc clear all close all num=[4 3 9] den=[4 3 -4] H=num/den [R,p,K] = residuez(num,den) [z,p,K] = tf2zp(num,den) zplane(z,p [sos,g]=zp2sos(z,p,K) TASK 1 Determine the rational Z-Transform from its polesand zero locations.The zeros are at ζ1 = 0.21, ζ2 = 3.14 , ζ3 = −0.3 + 𝑗 0.5 , ζ4= −0.3 − 𝑗0.5 And polesare at 𝜆1= −0.45 , 𝜆2 = −0.67, 𝜆3= 0.81 + 𝑗 0.72 , 𝜆4= 0.81 − 𝑗0.72 and the gain constant is 2.2. clc clear all close all z=[0.21;3.14;-0.3+0.5i;-0.3-0.5i] p=[-0.45;-0.67;0.81+0.72i;0.81-0.72j] k=2.2 [num,den] = zp2tf(z,p,k)% tf(num,den,-1)
  • 12. task 2 UsingMATLAB, determine the partial fraction expansionofthe z transform (𝑧),givenby clc clear all close all syms z num=[18 0 0 0] den=[18 3 -4 -1] Hz=num/den [r,p,K] = residuez(num,den) //for partial fraction p=[(r(1)/(1-p(1).*z.^(-1)))+(r(2)/(1-p(2).*z.^(-1)))+(r(3)/(1-p(3).*z.^(- 1)))] pretty(p) task 3 Determine the rational form of z transform from its partial fraction expansion of the following z transforms and then determine theirinverse z transform. Write down your analysis. clc clear all close all num=[1 -1 0] den=[1 1.3 0.3] [R,p,K] = residuez(num,den) [z,p,K] = tf2zp(num,den) zplane(z,p)
  • 13. zplane(z,p) A) casual andmarginal stable B) Anti-causal andunstable b/cnotinclude unitcircle C) non-causal andstable Lab 6 pre lab Write a MATLAB functionto compute K-pointDFT and IDFT of N-pointsequence.The function should take sequence (array),integervalue K and binary value switchto decide ifto compute DFT or IDFT. The functionshouldreturn the sequence aftercomputation. function [y] = lab6(x,N,b ) %UNTITLED2 Summary of this function goes here % Detailed explanation goes here if b==1 n=[0:1:N-1] k=[0:1:N-1] WN=exp(-j*2*pi/N) nk=n'*k WNnk=WN.^nk y=x*WNnk; else if b==0 n=[0:1:N-1] k=[0:1:N-1] WN=exp(-j*2*pi/N); nk=n'*k WNnk=WN.^(-nk); y=x*WNnk/N; end end task-1 Compute the M-pointDFT of the followingN-pointsequence. u(n)={1 ,0<=n<=N-1 0 , otherwise} compute the M pointDFT clc
  • 14. close all clear all N=5 M=7 n=0:1:N-1 x=1.*(n>=0) y=dft(+x,M,N) task-3 Write a MATLAB program to compute the circular convolution oftwo length- N sequences via DFT based approach. Using this program determine the circular convolution ofthe following pairs of sequences. a) 𝑔[𝑛] = {3 ,4 − 2 ,0 , 1 , −4} , ℎ[𝑛] = { 1,−3, 0,4 , −2 , 3} b)x[n]=sin(pi*n)/2,y[n] =(roll number)^n 0<=n<=4 clc close all clear all g=[3,4'-2,0,1,-4] h=[1,-3,0,4,-2,3] c=cconv(g,h) stem(c) : question function [y] = lab6( x,N,b ) %b is the value of switch if b==1
  • 16. N = 5 >> [y] = lab6( x,N,b) n = 0 1 2 3 4 k = 0 1 2 3 4 nk = 0 0 0 0 0 0 1 2 3 4 0 2 4 6 8 0 3 6 9 12 0 4 8 12 16 Undefinedfunctionorvariable "WNnk". Error inlab6 (line 10) y=x*WNnk
  • 17. >> [y] = lab6( x,N,b) n = 0 1 2 3 4 k = 0 1 2 3 4 nk = 0 0 0 0 0 0 1 2 3 4 0 2 4 6 8 0 3 6 9 12 0 4 8 12 16 y = 15.0000 + 0.0000i 1.5600 + 0.0000i 1.0851 + 0.0000i 1.0162 + 0.0000i 1.0032 + 0.0000i y = 15.0000 + 0.0000i 1.5600 + 0.0000i 1.0851 + 0.0000i 1.0162 + 0.0000i 1.0032 + 0.0000i
  • 18. >> Lab 7 TASK-1 Write MATLAB code that determines and plot the N-point Discrete Fourier Transform of x[n]defined by the following equations: x(n)=sin(0.5pi*n), 0<=n<=16 Compute and plot 16-point DFT usingtwo 8-pointFFTs and combiningtechniques. function [y]=fft16(x) %stage1 for n=0:1:7 twiddle=exp(-2*pi*j*n*1/16) x1(n+1)=x(n+1)+x(n+9) x1(n+9)=(x(n+1)-x(n+9))*twiddle; end %stage 2 for n=0:1:3 twiddle=exp(-2*pi*j*n*1/8) x2(n+1)=x1(n+1)+x1(n+5) x2(n+5)=(x1(n+1)-x(n+5))*twiddle; x2(n+9)=x1(n+9)+x1(n+13); x2(n+13)=x1(n+9)-x1(n+13)*twiddle; end %stage 3 for n=0:1:1 twiddle=exp(-2*pi*j*n*1/4) x3(n+1)=x2(n+1)+x2(n+3) x3(n+3)=(x2(n+1)-x2(n+3))*twiddle x3(n+5)=x2(n+5)+x2(n+7) x3(n+7)=(x2(n+5)-x2(n+7))*twiddle x3(n+9)=x2(n+9)+x2(n+11) x3(n+11)=(x2(n+9)-x2(n+11))*twiddle x3(n+13)=x2(n+13)+x2(n+15) x3(n+15)=(x2(n+13)-x2(n+15))*twiddle end %stage 4 twiddle=exp(-2*pi*j*n*1/2) x4(1)=x3(1)+x3(2) x4(2)=(x3(1)-x3(2))*twiddle x4(3)=x3(3)+x3(4) x4(4)=(x3(3)-x3(4))*twiddle x4(5)=x3(5)+x3(6)
  • 19. x4(6)=(x3(5)-x3(6))*twiddle x4(7)=x3(7)+x3(8) x4(8)=(x3(7)-x3(8))*twiddle x4(9)=x3(9)+x3(10) x4(10)=(x3(9)-x3(10))*twiddle x4(11)=x3(11)+x3(12) x4(12)=(x3(11)-x3(12))*twiddle x4(13)=x3(13)+x3(14) x4(14)=(x3(13)-x3(14))*twiddle x4(15)=x3(15)+x3(16) x4(16)=(x3(15)-x3(16))*twiddle y=bitrevorder(x4); end ****Calling Mfile**** clc clear all close all a=16 n=0:15 x=sin(0.5*pi*n) f1=fft(x) subplot(211) stem(abs(f1)) title('matlab fft') f2=fft16(x) subplot(212) stem(abs(f2)) title('self made function fft') TASK-2 Write MATLAB code to compare the efficiency linear convolution and the high-speed convolution times for 5 ≤ N ≤ 150 clc clear all close all conv_time = zeros(1,150); fft_time = zeros(1,150); % for L = 1:150 tc = 0; tf=0; N = 2*L-1; I=1
  • 20. nu = ceil(log10(N*I)/log10(2)); N = 2^nu; for I=1:100 h = randn(1,L); x = rand(1,L); t0 = clock; y1 = conv(h,x); t1=etime(clock,t0); tc = tc+t1; t0 = clock; y2 = ifft(fft(h,N).*fft(x,N)); t2=etime(clock,t0); tf = tf+t2; end % conv_time(L)=tc/100; fft_time(L)=tf/100; end n=1:150; subplot(1,1,1); plot(n(25:150),conv_time(25:150),n(25:150),fft_time(25:150)) TASK-3 Write a MATLAB functionto implementablock convolutionalgorithm calledthe overlap-and-save method(and its companion the overlap-and-addmethod),whichis usedto convolve a very large sequence witha relativelysmallersequence. Function [y] = ovrlpsav(x,h,N) % Overlap-Save method of block convolution % ---------------------------------------- % [y] = ovrlpsav(x,h,N) % y = output sequence % x = input sequence % h = impulse response % N = block length Lenx = length(x) M = length(h) M1 = M-1; L = N-M1 h = [h zeros(1,N-M)] % x = [zeros(1,M1), x, zeros(1,N-1)] % preappend (M-1) zeros K = floor((Lenx+M1-1)/(L)) % # of blocks Y = zeros(K+1,N) % convolution with succesive blocks for k=0:K xk = x(k*L+1:k*L+N)
  • 21. Y(k+1,:) = circonvt(xk,h,N) end Y = Y(:,M:N) % discard the first (M-1) samples y = (Y(:))' ; % assemble output TASK-4 Usingthe functionof task 3, write a MATLAB program to implementlength-Nmovingaverage filterto filtera noise corrupted signal. Where Nis class Roll Number. clc clear all close all n=1:5 s=n*pi subplot(221) stem(s) title('original signal') d=rand(1,5) subplot(222) stem(d) title('noise ') p=ovrlpsav(s,d,6), subplot(223) stem(p) title('corrupted signal') m=5 xu=0 for i=1:m x=s+d xu=xu+x end xu=xu/m subplot(224) stem(xu) title('filtered signal') lab 8 Task 1 Build a SIMULINK model for Sampling and Reconstruction ofanalog signal where, R = Your Reg. Number i i) Sample the analog signal x(t) at 8 times the Nyquistrate.
  • 22. ii ii) Non-uniformly quantize the discrete time signal using μ-lawcompanding method, μ=255 and number of quantization levels = 16. iii iii) Encode and Decode the signal into binary. iv iv) Reconstruct the analog signal. v v) Show both time and frequency domain results. % A simple sampling and reconstruction model for students % beginners of Digital Signal Processing % by Mukhtar Hussain (Email: mukhtarhussain@ciitlahore.edu.pk) % f - The frequency of analog sinosoid signal % F - Sampling Rate % qbits - Number of Quantizations bits % A - Amplitude of sinusoid signal % L - Number of quantization levels based on qbits % I - Quantization Interval % sim_time - Simultaion Time % span - x-axis range of frequency plot 1 & 3 (spectrum scope 1 & 3) % span1 - x-axis range of frequency plot 2 (spectrum scope 2) % NFFT - Number of FFT points clc; clear; close all; f = input('Enter the frequency of signal = '); F = input('Enter the sampling frequency = '); A = input('Enter max amplitude of signal = '); qbits = input('Enter the number of quantization bits = '); fc = input('Enter the lowpass filter cutoff frequency = '); L = 2^qbits; I = 2*A/(L-1); % Settings for Spectrum Scope span = 8*F; span1 = 8*F; NFFT = 256; % To run simulink model t = 1/f; sim_time = 10*t; sim('sampling.slx');
  • 23. TASk 2 Write MATLAB Code to i i) Plot discrete time sampled signal sampled at FS = 8R [] xn ii ii) Non-uniformly quantize the discrete time signal using μ-lawcompanding method, μ=100 and number of bits = 8 iii iii) Encode the signal into discrete levels. iv iv) Decode the signal from discrete level and reconstruct using spline and cubic interpolation to v v) Analyze which interpolation method performs better. clc clear all close all t=0:0.001:1 fm=10 fs=1000 N=8 L=2.^N %message signals x=sin(2*pi*fm*t) figure subplot 211 plot(t,x) title('message signal') xlabel('time') ylabel('amplitude') %pulse traain d=0:1/50:1 y=pulstran(t,d,'rectpuls',0.001) subplot 212 plot(t,y) title('pulse train') xlabel('time') ylabel('amplitude') %sampling z=x.*y figure subplot 211 plot(t,z) title('sampled signal') xlabel('time') ylabel('amplitude') %quantization D=[max(x)-min(x)]/(L-1) xq=quant(x,D) subplot 212 plot(t,xq) title('quantized signal') xlabel('time')
  • 24. ylabel('amplitude') %encoder H_e=dsp.UniformEncoder(max(xq),N) encoder=step(H_e,xq) figure subplot 211 plot(t,encoder) title('encoded signal') xlabel('time') ylabel('amplitude') %decoder H_d=dsp.UniformDecoder(max(xq),N) decoder=step(H_d,encoder) subplot 212 plot(t,decoder) title('decoded sig') xlabel('time') ylabel('amplitude') %interpolation time=0:1/(2*fs):5 interpolation=interp1(t,decoder,time) figure subplot 211 plot(time,interpolation) title('interpolation') %SC interpolation subplot 212 xx=0:0.001:1 sc=spline(t,x,xx) plot(t,sc) title('spline interpolation') LAB 11 Round ki command used for dfilt ki command used for design filter H1=dfilt.df1(num,den) fvtool ki command used for ploting filter
  • 25. IIR clc clear all close all syms z H1N=[2 0 2] H1D=[1 -0.8 0.64] H2N=[4 -2] H2D=[1 -0.75] H3N=[2 4 2] H3D=[1 0 0.81] A1=conv(H1N,H2N) HN=conv(A1,H3N) A2=conv(H1D,H2D) HD=conv(A2,H3D) num=round(HN,3) den=round(HD,3) H1=dfilt.df1(num,den) fvtool(H1) H2=dfilt.df2(num,den) fvtool(H2) H3=dfilt.cascade(H1,H2) fvtool(H3) FIR % phase responce linearhotaha % num hotaha or den1 hota ha clc clear all close all syms z H1N=[2 0 2]
  • 26. H1D=[1 -0.8 0.64] H2N=[4 -2] H2D=[1 -0.75] H3N=[2 4 2] H3D=[1 0 0.81] A1=conv(H1N,H2N) HN=conv(A1,H3N) A2=conv(H1D,H2D) HD=conv(A2,H3D) num=round(HN,3) den=round(HD,3) H1=dfilt.dffir(num) fvtool(H1) H2=dfilt.dffirt(num) fvtool(H2) LAB 12 Task 1 Designa band pass Chebyshev Type II filter using analog prototyping. The order of filter is 20 witha value of 60 dB stop band attenuationand 0.75dB pass band ripple where, Pass band edge = 800Hz Stopband edge=2000HzSampling frequency = 6000 %Chebyshev clc clear all close all Rp=0.75 Rs=60 fp=800 fst=2000 fs=6000 ft=fs/2
  • 27. wp=fp/ft wst=fst/ft %chebbyshev [n1,wn]=cheb1ord(wp,wst,Rp,Rs) [num,den]=cheby1(n1,Rp,wn) [H,w]=freqz(num,den,512,fs) plot(w,20*log10(abs(H))) title('Chebbyshev mag in dB') task 2 Design a Digital Bandpass IIR filter using Analog filter prototype and Frequency Transformation. The filter should have following specifications: Minimum order of the filter Lab Experiment | 12 Muhammad Usman Iqbal |EEE324 | Digital Signal Processing Lab Manual 83 Maximum passband = 0.5dB Minimum stopband attenuation= 30 dB Pass band edge frequencies = (N-5) – (N+5) MHz Stop band edge frequencies = (N-5.5) – (N+5.5) MHz Sampling rate of 8N MHz Where 𝑁 = { 10𝑅, 𝑖𝑓𝑅< 15 𝑅, 𝑜𝑡ℎ𝑒𝑟𝑤𝑖𝑠𝑤𝑒, 𝑀𝐻𝑧 𝑅 = 𝑌𝑜𝑢𝑟 𝑅𝑒𝑔. 𝑁𝑜. i) Give reason which filter type you would prefer based on the specification ii) Compute the normalized passband and stopband frequencies iii) Compute the order and transfer function of desired filter iv) Properly present your results to show that your designed filter meet the specification %BANDPASS clc