Psa Lab Report
Psa Lab Report
Psa Lab Report
Submitted by:
Group-15:
Ghulam Samdani (2018-EE-285)
Muhammad Umer (2018-EE-285)
Syed Muhammad Ali Raza Naqvi (2018-EE-285)
Section:
A
Date:
15 July, 2021
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Pre-Lab
TASK-1.A. Answer
1. Display the variable X. An error occurs because a variable X does not exist in the workspace,
2. Set the variable X to 12 and display the result.
3. Update the variable X with the value equal to the addition of the current value of X and 2.
4. Add 3 in value of X and store in Y.
5. Multiply Y with 6.
6. Solve equation mathematically.
7. Taking square of Y and store in X.
8. Taking sqare root of Y and store in Z.
9. Declare values of X and Y, add them up, store in Z.
10. Taking Y as exponent of X, and store in Z.
11. Store X=12x10^6
12. Clear screen.
13. Store and display any random value in x.
14. Store and display any random value in x.
15. Give description of ‘rand’ command.
TASK-1.B. Answer
1. Display Imaginary number.
2. Display Imaginary number.
3. Store and display complex number in X.
4. Store and display complex number in Y.
5. Add X and Y, store in Z.
6. Multiply X and Y, Store in Z.
7. Display real part of Z.
8. Display imaginary part of Z.
9. Display conjugate of Z.
10. Give magnitude of Z, sqrt[X2+Y2]
11. Display angle between real and imaginary part.
12. Display only names of all stored variables.
13. Display name and other properties (size, bytes, class …..) of all stored variables.
14. Clear all the stored variables.
15. Display only names of all stored variables. (show nothing because all variables were cleared.)
TASK-1.C. Answer
1. Store and display the value from 2 to 10 with increment of 2 in X.
2. Store the values from 1 to 5 with increment off 1 in Y.
3. Do elemental sum.
4. Do elemental multiplication.
5. Not possible because multiplication rule fails.
6. Do elemental division.
7. Simple division gives only a single ans.
8. Multiply 2 with each element of Y.
9. Store and display the values from 0 to 10 with increment of 1 in Z.
10. Gives sum of all elements of Z.
11. Declare a row matrix Y.
12. Declare a column matrix Y.
13. Take transpose of Y and store in Z.
14. Gives value of Z at position 1.
15. Gives value of Z at position 2.
16. Display values of Z from position 1 to 3.
17. Display values of Z from position 2 to 4.
18. Gives length(number of elements) in Z.
19. Declare a row matrix X.
20. Perform operation of log2(X) for each value of X and store in Y.
21. Not possible because multiplication rule fails (it must be a square matrix)
22. Take square of each elemnt of Y.
23. Generate a random matrix of order 1x5.
24. Generate a random matrix of order 4x4.
25. Declare a row matrix Y.
26. Gives mean of Y.
27. Gives variance of Y.
28. Gives min value of matrix Y.
29. Gives max value of matrix Y.
30. Store min value of Y at a, and position of that element at b.
31. Write in ascending order.
32. Additon of an element ‘5’ in matrix Y.
33. Store the 3rd , 4th element of Y and 1st , 2nd element of X in Z respectively.
TASK-1.D. Answers
1. Store 3x4 matrix in variable X.
2. Display element at position 2x1.
3. Display element at position 2x3.
4. Display 1st row of mxn.
5. Display 2nd column of mxn.
6. Display 1st and 2nd row.
7. Display 1st and 2nd column.
8. Store and display matrix Y of 3x3.
9. Take transpose of matrix Y.
10. Create null matrix Y.
11. Store 2nd row elements of X in 1st row of Y.
12. Store 1st row elements of X in 2nd row of Y.
13. Store given values in 3rd row of Y.
14. Can’t add due to matrix order difference.
15. Can’t multiply due to matrix multiply rule fails.
16. Multiply X and transpose of Y then store the result in Z.
17. Can’t do elemental multipliation because matrix dimension don’t agree.
18. Can’t multiply due to matrix multiplication rule fails. It happens in case of square matrix.
19. Take individual element’s square of matrix X.
20. Take each element of X as an exponent of 2 and store in Z.
21. Do elemental square of X and multiply each element of Y with 3. Error in addition because matrix
dimensions don’t agree.
22. Display max value from each column.
23. Take mean in each column of matrix Z.
24. Take mean in each column of matrix Y.
25. Return max value from mean of Z.
26. Give min value from each column.
27. Give max form max Z.
28. Inverse not possible due to non-square matrix.
29. Can’t multiply due to matrix multiply rule fails.
30. Give order of matrix Z.
TASK-1.E. Answers
1. Store and display the values of x from 0 to 10 with an increment of 0.1.
2. Store and display the value of function sin(x) in y1 for every value of x.
3. Store the value of function cos(x) in y2 for every value of x.
4. Plot graph for values of x which gives a straight line.
5. Plot graph for values of y1 which gives a sine wave.
6. Plot graph for values of (x, y1).
7. Make grid on graph.
8. Last plot remains on graph.
9. Plot graph for values of (x, y2) coupled with last plot.
10. Store and display the value of function exp(-x) in y3 for every value of x.
11. Plot graph for values of (x, y2) with red colored line.
12. Add legends in the graph for given functions on right top corner.
13. Define range for both axes. x-axis (-5 to 15), y-axis (-3 to 3)
14. Define range for both axes. x-axis (-5 to 15), y-axis (-3 to 3)
15. Open a new graph window.
16. Gives a new graph with 3 rows, 1 column at position 1.
17. Plot graph for values of (x, y1) on subplot at position 1.
18. Gives a new graph with 3 rows, 1 column at position 2.
19. Plot graph for values of (x, y2) on subplot at position 2.
20. Gives a new graph with 3 rows, 1 column at position 3.
21. Plot graph for values of (x, y3) on subplot at position 3.
22. It is same as plot except a logarithmic base 10 scale is used for y-axis.
23. Gives description of plot.
24. Gives description of semiology.
TASK-1.F. Answers
1. Store elements in row of matrix A.
2. Compare each element with a number 3 whether its greater or not.
3. Compare each element with a number 2 whether its greater or not, and store and display logical result
in B.
4. Perform bitwiseAND operation.
5. Perform bitwiseOR operation.
6. Perform NOT operation.
7. Check whether the corresponding elements are equal.
8. Check whether the corresponding elements are not-equal.
9. Store values in x from 0 to 10 with anincrement of 0.01.
10. Compare all values of x with number 3 and store logical result in y.
11. New graph windoe opens.
12. Plot graph between the values of (x, y), define both axes [x-axis (0 to 10), y-axis (-2 to 2)], also shows
up the grid.
13. Compare values of x with 1 and 4, then perform bitwiseAND operation between both results and store
result in y.
14. Plot graph between the values of (x, y), define both axes [x-axis (0 to 10), y-axis (-2 to 2)], also shows
up the grid.
15. Gives logical answer 1.
16. Axis range error.
17. Plot graph between the values of (x, y), define both axes [x-axis (0 to 10), y-axis (-2 to 2)], also shows
up the grid.
Main Lab
TASK 2-A:
Output:
>> LAB_2A
ans =
cos(t)
ans =
-cos(t)
ans =
ans =
97.7094
ans =
ans =
30
TASK 2-B:
Verify the following quantities by using the symbolic math. Capture the calculation Results.
TASK 2-B:
MATLAB Input:
syms z x
int(exp(-z^2),z,-Inf,Inf)
Output:
>> LAB1_2B
ans =
pi^(1/2)
TASK 2-B:
MATLAB Input:
syms r
g =(1/3)^r;
symsum(g,r,1,inf)
Output:
>> LAB1_2B_limit
ans =
1/2
TASK 2-B:
MATLAB Input:
syms x
g =(1+(1/x))^x;
limit(g,x,inf)
Output:
>> LAB1_2B_c
ans =
exp(1)
TASK-3A:
Follow the steps below and learn how to create and execute an m-file.
Step 1. Open a new script file editing window.
Step 2. Shown in the box below is an m-file that plots y = x sin(ax), for the cases of a = 0.1, 0.25, 0.3, 0.4, 0.5,
0.6, 0.7 and 0.8 over the range 0 < x < (10 + D), where D = the last digit of your student ID number. Write
this m-file and save it as Lab1 3A.m. The m-file name must begin with a letter, files with a name that begins
with a number will not executed in MATLAB. Be sure not to use a space or mathematical operator in the file
name.
Input:
x=0:0.1:10; %Roll Number 290 So last digit is 0 ; 10+0=10
for n=1:8
a=n/10;
if(a==0.2)
a=0.25;
end
y(n,:)= x.*sin(a*x);
end
plot(x,y)
xlabel('x')
ylabel('y=x sin(ax)')
legend('a=0,1','a=0.25','a=0.3','a=0.4','a=0.5','a=0.6','a=0.7','a=0.8')
grid on
Output:
TASK-3A.3:
>>y : compute the function at each value of x and repeats for each value of n and store in y.
TASK-4.A:
Let us write a MATLAB function that converts a number in linear scale into dB scale. In MATLAB, open the
script file editor and write the following m-file. Save the m-file as lin2dB.m (if you click "save," the default
file name will be lin2dB.m).
Answer:
Output:
TASK-4.B:
TASK-4.B1:
TASK-4B-2:
TASK-4.C:
Write a user-defined function swap(A,row0col1,c,d) that swaps two rows (or columns) of a matrix. If
row0col1 is 0, then swap(A, row0col1,c,d) swaps the c-th row and the d-th row of a matrix A and returns
the swapped matrix. If row0col1 is 1, then swap(A,row0col1,c,d) swaps the c-th column and the d-th column
of a matrix A and returns the swapped matrix.
TASK-4C.1:
An incomplete version of swap.m is provided below. Complete all parts marked by ' ?' and add a comment
for each line you are completing.
Execute the following command lines and capture the results. Check whether or not your swap function works
correctly.
>>x=rand(4,5)
>>y=swap(x,0,2,4)
>>z=swap(y,1,5,1)
Commands Implementation:
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
TASK-3A(a):
Input Code:
[x1,n1]=impseq(-5,10,3);
x1=3*x1;
[x2,n2]=impseq(-5,10,6);
x2=-1*x2;
[y,n] = sigadd(x1,n1,x2,n2);
stem(n,y)
title('POST LAB Q3A-a')
Output:
TASK-3A(b):
Input Code:
n = [0:20];
x1 = n.*(stepseq(0,20,0)-stepseq(0,20,10));
x1 = 10*exp(-0.3*(n-1)).*(stepseq(0,20,0)-stepseq(0,20,20));
x=x1+x2;
stem(n,x)
title('POST LAB Q3A-b')
xlabel('n')
ylable('x')
Output:
TASK-3A(c):
Input Code:
n=-10:9;
x=[5 4 3 2 1];
xtilde=x'*ones(1,4);
xtilde=xtilde(:);
xtilde=xtilde';
stem(n,xtilde)
title('POST LAB Q3A-c')
Output:
TASK-3B:
Input Code:
x=[-1,2,3,4,5,6,7,6,5,4,3,-2,1];
n= 0:length(x)-1;
[x11,n11] = sigshift(x,n,5);
[x12,n12] = sigshift(x,n,-4);
[x1,n1] = sigadd(2*x11,n11,-3*x12,n12);
x=[-1,2,3,4,5,6,7,6,5,4,3,-2,1];
n= 0:length(x)-1;
[x21,n21] = sigfold(x,n);
[x21,n21] = sigshift(x21,n21,3);
[x22,n22] = sigshift(x,n,2);
[x2,n2] = sigadd(2*x11,n11,-3*x12,n12);
subplot(2,1,1);
stem(n1,x1);
xlabel('n');
ylabel('x1(n)');
title('Sequence in 3B(a)')
subplot(2,1,2);
stem(n2,x2);
xlabel('n');
ylabel('x2(n)');
title('Sequence in 3B(b)')
Output:
TASK-3C:
Cmplx function:
function [x,n] = cmplx(n1,n2,a,b)
n= [n1:n2];
x = exp(a+1i*b)*n;
stem(n,x);
end
Input Code:
[x,n] = cmplx(-10,10,0.1,0.3);
subplot(4,1,1);
stem(n,real(x));
xlabel('Time Samples');
ylabel('Real Part');
subplot(4,1,2);
stem(n,imag(x));
xlabel('Time Samples');
ylabel('Imaginary Part');
subplot(4,1,3);
stem(n,abs(x));
xlabel('Time Samples');
ylabel(' Magnitude');
subplot(4,1,4);
stem(n,angle(x));
xlabel('Time Samples');
ylabel('Phase');
Output:
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Input Code:
x = [1,2,3,4,5];
h= [6 7 8 0]; %Roll Number 2018-EE-290 Last digit of 290 is 0
nx=[-3:3];
nh=[-1:4];
[y, ny] = conv_m(x,nx, h,nh)
x=impz(x)
y=impz(y)
[y,H]=convtp(x,h)
Output:
y=
6 19 40 61 82 67 40 0
ny =
-4 -3 -2 -1 0 1 2 3
x=
y=
6
19
40
61
82
67
40
y=
6 19 40 61 82 67 40 0
H=
6 0 0 0 0
7 6 0 0 0
8 7 6 0 0
0 8 7 6 0
0 0 8 7 6
0 0 0 8 7
0 0 0 0 8
0 0 0 0 0
We can see that the Toeplitz matrix is created by firstly put a column of h and a row with first index of h and
repeat it on diagonally whilst the remaining fill with zero.
TASK-3D:
Function impseq:
function [x,n] = impseq(n0,n1,n2)
n = n1:n2;
x = (n-n0) == 0;
end
Function stepseq:
function [x,n] = stepseq(n1,n2,n0)
n = [n1:n2];
x = [(n-n0)>=0];
stem(n,x)
end
Input Code:
b = 1;
a = [1 -1 0.9];
x = impseq(0,-20,100);
n = -20:100;
h = filter(b,a,x);
subplot(2,1,1);
stem(n,h);
title('Impulse Response');
xlabel('n');
ylabel('h[n]');
x = stepseq(0,-20,100);
s = filter(b,a,x);
subplot(2,1,2);
stem(n,s);
title('Step Response');
xlabel('n');
ylabel('s[n]')
Output:
>> sum(abs(h))
ans =
22
Solution:
So,
𝟎. 𝟔𝟒𝐳 −𝟐
𝐗(𝐳) =
𝟏 − 𝟎. 𝟖𝐳 −𝟏
𝑧 > |0.8|
MATLAB:
>> b=[0,0,0.64];
>> a= [1,-0.8];
>> [x,n]= impseq(0,7,0);
>> x= filter(b,a,x)
x =
>> x=[0.8.^n].*stepseq(0,7,2)
x =
Solution:
So,
𝟏 𝟏
𝑿(𝒛) = −𝟏
+
𝟏 − 𝟎. 𝟓𝒛 𝟏 + 𝟎. 𝟖𝒛−𝟏
Region of convergence (ROC):
MATLAB:
>> R=[1,1];
>> p= [0.5,-0.8];
>> C=[];
>> [b,a]=residuez(R,p,C);
>> [x,n]= impseq(0,7,0);
>> x= filter(b,a,x)
x =
>> x= [(0.5).^n+(-0.8).^n].*stepseq(0,7,0)
x =
TASK-4D:
Given a casual system
1. Write a function that would determine H(z) and sketch its pole-zero plot.
Solution:
𝑌(𝑧) 1
=
𝑋(𝑧) 1 − 0.9𝑧 −1
As
𝑌(𝑧)
𝐻(𝑧) =
𝑋(𝑧)
So
1 𝑧
𝐻(𝑧) = =
1 − 0.9𝑧 −1 𝑧 − 0.9
MATLAB:
>> b=[1,0];
>> a= [1,-0.9];
>> tf(b,a,-1)
ans =
z
-------
z - 0.9
>> zplane(b,a);
Solution:
MATLAB:
>> zplane(b,a);
>> a=[1,-0.9];
>> b=[1,0];
>> [H,w] = freqz(b,a,100,'whole');
>> H_m = abs(H);
>> H_p = angle(H);
>> subplot(2,1,1);
>> plot(w/pi,H_m);
>> title('Magnitude Response');
>> subplot(2,1,2);
>> plot(w/pi, H_p/pi);
>> title('Phase Response');
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
MAIN-LAB
TASK-5I:
Input Code:
x = rand(1,11);
n = 0:10;
k = 0:500;
w = (pi/500)*k;
X = x * (exp(-1i*pi/500)).^(n'*k);
Y_check = (exp(-1i*2).^w).*X;
error = max(abs(Y-Y_check))
MATLAB Output:
error =
7.7334e-15
………………………………………………………………………………………………………………
TASK-5J:
Input Code:
n = -5:10;
x = rand(1,length(n));
k = -100:100;
w = (pi/100)*k; % frequency between -pi and +pi
X = x * (exp(-1i*pi/100)).^(n'*k); % DTFT of % folding property
y = fliplr(x);
m = -fliplr(n); % signal folding
Y = y * (exp(-1i*pi/100)).^(m'*k);
Y_check = fliplr(X);
error = max(abs(Y-Y_check))
MATLAB Output:
error =
1.7764e-15
………………………………………………………………………………………………………………
TASK-5K:
Input Code:
[x1,n1] = stepseq(0,40,0);
[x2,n2] = stepseq(0,40,40);
[x3,n3] = sigadd(x1,n1,-x2,n2);
n = n3;
h = sinc(0.2*n).*x3;
w = [-300:300]*pi/300;
H = dtft(h,n,w);
magH = abs(H);
phaH = angle(H)*180/pi;
subplot(2,1,1);
plot(w/pi,magH);
title('Magnitude phase')
xlabel('w/pi')
ylabel('|H|')
subplot(2,1,2);
plot(w/pi,phaH);
title('Phase response')
xlabel('w/pi')
ylabel('Degree')
MATLAB Output:
………………………………………………………………………………………………………………
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
(a)
Input Code:
n = [0:1:99];
x = cos(0.48*pi*n)+cos(0.52*pi*n);
n2 = [0:99];
y2 = [x(1:10) zeros(1,90)];
subplot(2,1,1) ;
stem(n2,y2) ;
title("signal x(n),0<=n<=9+90 zeros");
xlabel("n")
Y2 =dfs(y2,100);
magY2 = abs(Y2(1:51));
k2 = 0:50;
w2 = 2*pi/100*k2;
subplot(2,1,2);
plot(w2/pi,magY2);
title("DTFT Magnitude");
xlabel("frequency in pi units")
MATLAB Output:
(b)
Input Code:
n = [0:1:99];
x = cos(0.48*pi*n)+cos(0.52*pi*n);
subplot(2,1,1);
stem(n,x);
title( "signal x(n), 0 <= n <= 99 ");
xlabel( "n")
X = dfs(x,100);
magX = abs(X(1:1:51));
k = 0:1:50;
w = 2*pi/100*k;
subplot(2,1,2); plot(w/pi,magX);
title( "DTFT Magnitude ");
xlabel( "frequency in pi units ")
MATLAB Output:
(c)
Input Code:
n = [0:1:99];
func = cos(0.48*pi*n)+cos(0.52*pi*n);
subplot(2,1,1);
stem(n,func);
title('x(n)');
xlabel('n');
%FFT Calculation
X=fft(func,100);
magnitude = abs(X(1:1:51));
n2 = 0:1:50;
w = 2*pi/100*n2;
subplot(2,1,2);
plot(w/pi,magnitude);
xlim(0:1);
title('DTFT Magnitude for 100 point FFT');
MATLAB Output:
………………………………………………………………………………………………………………
TASK-6F:
(a)
Input Code:
n = 0:10;
x = 10*(0.8) .^ n;
y = x(mod(-n,11)+1);
subplot(2,1,1);
stem(n,x);
title( "Original sequence ")
xlabel( "n ");
ylabel( "x(n) ");
subplot(2,1,2);
stem(n,y);
title( "Circularly folded sequence ")
xlabel( "n ");
ylabel( "x(-n mod 10) ");
MATLAB Output:
(b)
Input Code:
n = [0:1:99];
n = 0:10;
x = 10*(0.8) .^ n;
y = x(mod(-n,11)+1);
X = dfs(x,11); Y = dfs(y,11);
subplot(2,2,1); stem(n,real(X));
title('Real(DFT[x(n)])'); xlabel('k');
subplot(2,2,2); stem(n,imag(X));
title('Imag(DFT[x(n)])'); xlabel('k');
subplot(2,2,3); stem(n,real(Y));
title('Real(DFT[x((-n))_{11}])'); xlabel('k');
subplot(2,2,4); stem(n,imag(Y));
title('Imag(DFT[x((-n))_{11}])'); xlabel('k');
MATLAB Output:
………………………………………………………………………………………………………………
TASK-6G:
Input Code:
x1 = [1,2,2];
x2 = [1,2,3,4];
N=5;
y = circonvt(x1,x2,N)
x1 = [1,2,2];
x2 = [1,2,3,4];
N=6;
y = circonvt(x1,x2,N)
MATLAB Output:
y=
9 4 9 14 14
y=
1 4 9 14 14 8
………………………………………………………………………………………………………………
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Input Code:
% Digital Filter Specifications:
wp = 0.2*pi; % digital Passband freq in Hz
ws = 0.3*pi; % digital Stopband freq in Hz
Rp = 1; % Passband ripple in dB
As = 15; % Stopband attenuation in dB
MATLAB Output:
>> Q7D
b=
0.0000
0.0006
0.0101
0.0161
0.0041
0.0001
a=
1.0000
-3.3635
5.0684
-4.2759
2.1066
-0.5706
0.0661
………………………………………………………………………………………………………………
TASK-7E:
Input Code:
% Digital Filter Specifications:
wp = 0.2*pi; % digital Passband freq in rad
ws = 0.3*pi; % digital Stopband freq in rad
Rp = 1; % Passband ripple in dB
As = 15; % Stopband attenuation in dB
% Analog Prototype Specifications: Inverse mapping for frequencies
T = 1; Fs = 1/T; % Set T=1
OmegaP = (2/T)*tan(wp/2); % Prewarp Prototype Passband freq
OmegaS = (2/T)*tan(ws/2); % Prewarp Prototype Stopband freq
% Analog Butterworth Prototype Filter Calculation:
[cs,ds] = afd_butt(OmegaP,OmegaS,Rp,As);
% Bilinear transformation:
[b,a] = bilinear(cs,ds,Fs)
freqz(b,a)
MATLAB Output:
>> Q7E
a=
………………………………………………………………………………………………………………
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Input Code:
wp=1500;
ws=2000;
Rp=3;As=40;
Ripple=10^(Rp/20); %Ripple in dB
Attn=10^(-As/20); %Attenuation in dB
[b,a]=afd_chb1(wp,ws,Rp,As);
[C,B,A]=sdir2cas(b,a) [db,mag,pha,w]=freqs_m(b,a,1500);
[ha,x,t]=impulse(b,a);
subplot(411);
plot(w/pi,mag);
xlabel('frequency in pi units');
ylabel('|H|');
title('Magnitude response');
subplot(412);
plot(w/pi,db);
xlabel('frequency in pi units');
ylabel('Decibels');
title('Magnitude response in DB');
subplot(413);
plot(w/pi,pha);
xlabel('frequency in pi units');
ylabel('radians');
title('phase reponse');
subplot(414);
plot(t,ha);
xlabel('time(sec)');
ylabel('ha(t)');
title('Impulse response');
MATLAB Output:
2.676 ×1014
𝐻𝑎 𝑠 =
(0.06s + 91.92)(0.04s + 282.26)(0.02s + 434.92)
Part-(a):
H(z) = 5.96e-8
Part-(b):
BILINEAR TRANSFORMATION:
c=2.676e+12;
d=[0.000048,1.456056,9483.6517,1128446.92];
T=1;
[b,a]=bilinear(c,d,T);
Part-(c):
………………………………………………………………………………………………………………
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Solution:
𝑅𝑝 𝐴𝑠 𝑅𝑝
1 + 𝑎𝑛𝑡𝑖𝑙𝑜𝑔 (−20) ∗ 𝑎𝑛𝑡𝑖𝑙𝑜𝑔 (−20 ) − 𝑎𝑛𝑡𝑖𝑙𝑜𝑔(−20)
𝛿1 =
𝑅𝑝 𝐴𝑠
1 − 𝑎𝑛𝑡𝑖𝑙𝑜𝑔 (−20) ∗ 𝑎𝑛𝑡𝑖𝑙𝑜𝑔(−20 )
𝐴𝑠
𝛿2 = 𝑎𝑛𝑡𝑖𝑙𝑜𝑔 ( ) ∗ (1 + 𝛿1 )
−20
Function:
Input:
MATLAB Output:
delta1 = 0.0315
delta2 = 0.0033
………………………………………………………………………………………………………………
TASK-9D:
Function:
Input:
MATLAB Output:
d = 12 10 -4 -2 2 -8
L= 6
………………………………………………………………………………………………………………
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Input Code:
wp = 0.2*pi;
ws = 0.3*pi;
As = 50;
tr_width = ws - wp;
M = ceil((As-7.95)/(2.285*tr_width)/1)+1
n = [0:1:M-1];
beta = 0.1102*(As-8.7)
wc = (ws+wp)/2;
hd = ideal_lp(wc,M);
w_kai = (kaiser(M,beta))';
h = hd .* w_kai;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
As = -round(max(db(ws/delta_w+1:1:501))) % Min Stopband Attenuation
% Plots
subplot(2,2,1);
stem(n,hd);
title('Ideal Impulse Response')
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('hd(n)')
subplot(2,2,2);
stem(n,w_kai);
title('Kaiser Window')
axis([0 M-1 0 1.1]);
xlabel('n');
ylabel('w(n)')
subplot(2,2,3);
stem(n,h);
title('Actual Impulse Response')
axis([0 M-1 -0.1 0.3]);
xlabel('n');
ylabel('h(n)')
subplot(2,2,4);
plot(w/pi,db);
title('Magnitude Response in dB');
grid
axis([0 1 -100 10]);
xlabel('frequency in pi units');
ylabel('Decibels')
MATLAB Output:
………………………………………………………………………………………………………………
TASK-10C:
Input Code:
ws1 = 0.2*pi;
wp1 = 0.35*pi;
wp2 = 0.65*pi;
ws2 = 0.8*pi;
As = 60;
tr_width = min((wp1-ws1),(ws2-wp2));
M = ceil(11*pi/tr_width) + 1
n=[0:1:M-1];
wc1 = (ws1+wp1)/2;
wc2 = (wp2+ws2)/2;
hd = ideal_lp(wc2,M) - ideal_lp(wc1,M);
w_bla = (blackman(M))';
h = hd .* w_bla;
[db,mag,pha,grd,w] = freqz_m(h,[1]);
delta_w = 2*pi/1000;
Rp = -min(db(wp1/delta_w+1:1:wp2/delta_w)) % Actual Passband Ripple
As = -round(max(db(ws2/delta_w+1:1:501))) % Min Stopband Attenuation
%Plots
subplot(2,2,1); stem(n,hd); title('Ideal Impulse Response')axis([0 M-1 -0.4
0.5]);xlabel('n');ylabel('hd(n)')
subplot(2,2,2); stem(n,w_bla);title('Blackman Window')axis([0 M-1 0 1.1]); xlabel('n');
ylabel('w(n)')
subplot(2,2,3); stem(n,h);title('Actual Impulse Response')axis([0 M-1 -0.4 0.5]);
xlabel('n'); ylabel('h(n)')
subplot(2,2,4);plot(w/pi,db);axis([0 1 -150 10]);title('Magnitude Response in
dB');grid; xlabel('frequency in pi units'); ylabel('Decibels')
MATLAB Output:
………………………………………………………………………………………………………………
Submitted to: Sir Ammar Naseer Submitted by: 2018-EE-285,290,291
Function:
function tone=tone_gen(num)
Fs = 8000; Ts = 1/Fs; N = 800;t = Ts*(0:N-1);
switch num
case '0'
tone=sin(2*pi*941*t)+sin(2*pi*1336*t);
case '1'
tone=sin(2*pi*697*t)+sin(2*pi*1209*t);
case '2'
tone=sin(2*pi*697*t)+sin(2*pi*1336*t); sound(tone);
case '3'
tone=sin(2*pi*697*t)+sin(2*pi*1477*t);
case '4'
tone=sin(2*pi*770*t)+sin(2*pi*1209*t);
case '5'
tone=sin(2*pi*770*t)+sin(2*pi*1336*t);
case '6'
tone=sin(2*pi*770*t)+sin(2*pi*1477*t);
case '7'
tone=sin(2*pi*852*t)+sin(2*pi*1209*t);
case '8'
tone=sin(2*pi*852*t)+sin(2*pi*1336*t);
case '9'
tone=sin(2*pi*852*t)+sin(2*pi*1477*t);
case '*'
tone=sin(2*pi*941*t)+sin(2*pi*1209*t);
case '#'
tone=sin(2*pi*941*t)+sin(2*pi*1477*t);
otherwise error('Invalid Input');
end
end
function num=generate_tone(arr)
len = length(arr);
for i=1:len
tone = generate_tone(input(i));
num(i) = decode_tone(tone);
end
end
TASK-11B:
Input Code:
function num = Q7E(tone)
Fs = 8000; N = 800; f = [697 770 852 941 1209 1336 1477]; indxs = round(f/Fs*N)+1;
x = goertzel(tone,indxs); F=(f(abs(x)>100));
f1=F(1); f2=F(2);
if(f1==697)
if(f2==1209)
num=1;
elseif(f2==1336)
num=2;
elseif(f2==1477)
num=3;
end
elseif(f1==770)
if(f2==1209)
num=4;
elseif(f2==1336)
num=5;
elseif(f2==1477)
num=6;
end
elseif(f1==852)
if(f2==1209)
num=7;
elseif(f2==1336)
num=8;
elseif(f2==1477)
num=9;
end
elseif(f1==941)
if f2==1209
num='*';
elseif(f2==1336)
num=0;
elseif(f2==1477)
num='#';
end
end
end
MATLAB script:
input=['2' '9' '0'];
len = length(input);
for i=1:len
tone = generate_tone(input(i));
num(i) = decode_tone(tone);
end
num
MATLAB Output:
num =
2 9 0
………………………………………………………………………………………………………………