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')
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')
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
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)
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')
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