Laboratory Report

docx

School

Concordia University *

*We aren’t endorsed by this school

Course

342

Subject

Electrical Engineering

Date

Jan 9, 2024

Type

docx

Pages

25

Uploaded by mannybenka

Report
Laboratory Report ELEC 342 Laboratory experiment #2 Additional MATLAB features, Properties of Signals and Systems, Convolution and System Response By Anas Senouci (40132281) Laboratory made on February 1 st , 2022 Lab section: MJ-X Lab instructor: Mohebbi, Ali Due date: February 14, 2022
OBJECTIVES Part I of this lab will go over some more MATLAB programming language capabilities, such as loops, conditional selection and array processing. Part II will demonstrate how to utilise the MATLAB convolution function show the relation between input, output and transfer function. The goal will be to understand how MATLAB can verify various properties of signals and systems such as: linearity, time variation, evenness, oddness will be verified using simple MATLAB scripts. THEORY The theory behind this lab was mainly to learn new concepts like loops, the logic behind functions properties like linearity and time variation. TASKS, RESULTS AND DISCUSSION Part I Questions 1-a: The first question aims to find the energy of a signal and use the disp function of MATLAB. get familiar with MATLAB's subplot and hold commands. The total energy of x[n] found was 285 and the total energy of y[n] was 15333. The result can be found in appendix I with the code used. The graphs created (Figure 1) show that y[n] grow exponentially since y[n]=x[n]^2. Questions 1-b: The part of the question is the same as the first, but the input was changed to be a sinusoidal function. The energy of x[n] was found to be 5 and the energy of y[n] was found to be 3.75. The Figure 2 in the Appendix II show the signals. Questions 2-a: Question 2 is all about understanding the properties of signal, mainly linearity. In the first part, a function sin and a function cos were given as being dual using a system. To find out if the signals were linear, the law of superposition and homogeneity was applied to the systems (scaling and additivity). When the scaled outputs y1 and y2 are added together, they produce the same result
as when the scaled inputs x1 and x2 are summed. This is what Figure 3 shows, the results are similar whose systems are linear. Questions 2-b: This question refers to the concept of linearity but also of temporal variance. An input is given, and the output is squared. Is this system linear and time invariant? This is what we will discover in two ways, with an output equal to 1 or 0 and an output of our much wider choice. The trap is that 0 squared gives back 0 so we could believe that some results are the same while for the rest of the figures, the law of additivity and scaling are not respected. We find using the formulas in Appendix IV and Figure 4 that the system y[n] = x2[n] is not linear and is invariant over time. Also, the system y[n] = 2x[n] + 5δ[n] is not linear and is time variant. Figures 6 and 7 show that the delay of n (the time value), the systems results are not the same for outputs and inputs. Question 3-a: For the last task of the first part, the concept of even, odd and mirror components are introduced with the MATLAB functions abs and exp. The function p has been used. The mirror of this function can be found in Figure 12, the only one has chosen to do was to reverse the sign of n. Subsequently, the odd and even components were found thanks to the functions: even= (x[n]+x[-n])/2 and odd=(x[n]-x[-n])/2. It is important to say that this signal has no even part so the signal itself is odd over the interval n: 0 to 10. Question 3-b: The same process was done as the first part of the question but with a new system: This system has no odd component, so it is therefore, even. Question 3-c: The first method to generate the MATLAB arrays x1 and x2 uses the initialisation of an array n of size 20. Then, the array is used as the variable n of the x1 equation. This method is easy to understand and uses only two lines of code. The other method used a for loop to fill elements in the array. It is a bit more complex to understand and needs more time from the computer. The first method is ideal.
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Part II Question 1: This question introduces the concept of output response of signals and difference equation. A for loop was used to the array y that represents . The Figure 15 shows the output response. Question 2: This question introduces the function conv of MATLAB which is used to make convolutions. The question asks to compute the system response of question 1 by convolving H[n] and x[n]. The answer is shows by Figure 16. The main difference between the output in the first and second question is the number of values from the conv function is bigger than the values from the for loop (method one). The graphs however (Figure 15 and 16) are the same. Question 3-a: In this question, it is asked to find the linearity of an unknown signal. The linearity was tested with the additivity and scaling methods with random inputs. In this case, the constants of scaling are 5 and 3 because in the case of exponentials, the output will differ. Putting something different and not equal to 1 or 0 gives very few possibilities to make mistakes. The output will show if the system in linear or not, if the two outputs are similar, then the system is linear. Observations were made, when different inputs were fed to the system, different outputs showed as arrays. The system is linear, but more proof is needed like feeding a ramp function to the system. If the output of the system is a line, then the system is linear. Question 3-b: The time variance of the system can be checked by shifting the original input by a constant and see if the output is the same as the non-shifted one. In the experiment, the constant 1 has been shifting the input and output. The system is time variant.
CONCLUSION The lab explores the use of the logic and concept of the MATLAB program that are used to find the properties of signals. Several basic functions and commands needed to be used to answer questions about linearity, convolution, time variance of different systems. Simple proofs were required to promote learning of computer behavior and operations. APPENDIX I %Question 1 a): clear all ; clc; n=0:9; x=n; y=x.^2; subplot(2,1,1); stem(n,x); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x[n]' ) subplot(2,1,2); stem(n,y); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y[n]' ); Ex=0; Ey=0; for i = 1:10 Ex=Ex+x(i)^2; Ey=Ey+y(i)^2; end disp( 'Energy of signal x[n] is ' ); disp(Ex); disp( 'Energy of signal y[n] is ' ); disp(Ey); Energy of signal x[n] is 285 Energy of signal y[n] is 15333
Figure 1. Part I Q1(a) APPENDIX II %Question 1 b): clear all ; clc; n=0:9; x=sin((2*pi)/10*n); y=x.^2; subplot(2,1,1); stem(n,x); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x[n]' ); subplot(2,1,2); stem(n,y); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y[n]' ); Ex=0; Ey=0; for i = 1:10
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Ex=Ex+x(i)^2; Ey=Ey+y(i)^2; end disp( 'Energy of signal x[n] is ' ); disp(Ex) disp( 'Energy of signal y[n] is ' ); disp(Ey) Energy of signal x[n] is 5.0000 Energy of signal y[n] is 3.7500 Figure 2. Part I Q1(b) APPENDIX III %Question 2 a): clear all ; clc; n=[0:10]; x1=sin((2*pi/10)*n); x2=cos((2*pi/10)*n); x3=x1+x2; y1=2.*x1;
y2=2.*x2; y3=2.*x3; if (y3 == (y1+y2)) disp( "Output is consistent with a linear system" ); else disp( "System is not linear" ); end subplot(2,3,1); stem(n,x1); xlabel( 'n' );ylabel( 'x1(n)' );title( 'x1(n)=sin(2*pi*n/10)' ) subplot(2,3,2); stem(n,x2); xlabel( 'n' );ylabel( 'x2(n)' );title( 'x2(n)=cos(2*pi*n/10)' ) subplot(2,3,3); stem(n,x3); xlabel( 'n' );ylabel( 'x2(n)' );title( 'x3(n)=x1(n)+x2(n)' ) subplot(2,3,4); stem(n,y1); xlabel( 'n' );ylabel( 'y1(n)' );title( 'y1(n)=2*x1(n)' ) subplot(2,3,5); stem(n,y2); xlabel( 'n' );ylabel( 'y2(n)' );title( 'y2(n)=2*x2(n)' ) subplot(2,3,6); stem(n,y3); xlabel( 'n' );ylabel( 'y3(n)' );title( 'y3=y1(n)+y2(n)' ) Output is consistent with a linear system
Figure 3. Part I Q2(a) APPENDIX IV %Question 2 b): clear all ; clc; %i) %Linearity n[0,1]: n=0:20; for i=1:length(n) x1(i)=1; x2(i)=1; end x3=x1+x2; y3=x3.^2; y1=x1.^2; y2=x2.^2; y4=y1+y2; subplot(2,1,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,1,2); stem(n,y4); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y4[n]' ); if y3==y4 disp( 'Output consistent with a linear system' ) else disp( 'Non-linear system' ) end %Time invariance n[0,1]: figure subplot(2,2,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' );
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
subplot(2,2,2); stem(n-1,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n-1]' ); subplot(2,2,3); stem(n,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n]' ); subplot(2,2,4); stem(n-1,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n-1]' ); if y3(1)== x3(1).^2; disp( 'Time invariant' ) else disp( 'Time variant' ) end %Linearity bigger n: for i=1:length(n) x1(i)=i; x2(i)=i+13; end x3=x1+x2; y1=x1.^2; y2=x2.^2; y3=x3.^2; y4=y1+y2; figure subplot(2,1,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,1,2); stem(n,y4); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y4[n]' ); if y3==y4 disp( 'Output consistent with a linear system' ) else
disp( 'Non-linear system' ) end %Time invariance bigger n: figure subplot(2,2,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,2,2); stem(n-4,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n-4]' ); subplot(2,2,3); stem(n,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n]' ); subplot(2,2,4); stem(n-4,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n-4]' ); r=6; if y3(r+2)== x3(r+2).^2; disp( 'Time invariant' ) else disp( 'Time variant' ) end n[0,1]: Non-linear system Time invariant Bigger n: Non-linear system Time invariant
Figure 4. Part I Q2 (b) i) Figure 5. Part I Q2 (b) i)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Figure 6. Part I Q2 (b) i)
Figure 7. Part I Q2 (b) i) APPENDIX V %Question 2 b): clear all ; clc; %ii) %Linearity n[0,1]: n=0:20; for i=1:length(n) x1(i)=0; x2(i)=1; d1(i)=dirac(0); d2(i)=dirac(1); end x3=x1+x2; y3=x3.^2; y1=2*x1+5*d1; y2=2*x2+5*d2; y4=y1+y2;
subplot(2,1,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,1,2); stem(n,y4); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y4[n]' ); if y3==y4 disp( 'Output consistent with a linear system' ) else disp( 'Non-linear system' ) end %Time invariance n[0,1]: figure subplot(2,2,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,2,2); stem(n-1,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n-1]' ); subplot(2,2,3); stem(n,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n]' ); subplot(2,2,4); stem(n-1,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n-1]' ); if y3(1)== 2*x3(1)+5*dirac(1) disp( 'Time invariant' ) else disp( 'Time variant' ) end %Linearity bigger n: for i=1:length(n) x1(i)=i;
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
x2(i)=i+12; d1(i)=dirac(i); d2(i)=dirac(i+12); end x3=x1+x2; y3=x3.^2; y1=2*x1+5*d1; y2=2*x2+5*d2; y4=y1+y2; figure subplot(2,1,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,1,2); stem(n,y4); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y4[n]' ); if y3==y4 disp( 'Output consistent with a linear system' ) else disp( 'Non-linear system' ) end %Time invariance bigger n: figure subplot(2,2,1); stem(n,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n]' ); subplot(2,2,2); stem(n-4,y3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'y3[n-4]' ); subplot(2,2,3); stem(n,x3); xlabel( 'n' ); ylabel( 'Amplitude' ); title( 'x3[n]' ); subplot(2,2,4); stem(n-4,x3); xlabel( 'n' ); ylabel( 'Amplitude' );
title( 'x3[n-4]' ); if y3(6)== 2*x3(6)+5*dirac(6); disp( 'Time invariant' ) else disp( 'Time variant' ) end n[0,1]: Non-linear system Time variant Bigger n: Non-linear system Time variant Figure 8. Part I Q2 (b) ii)
Figure 9. Part I Q2 (b) ii) Figure 10. Part I Q2 (b) ii)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
Figure 11. Part I Q2 (b) ii) APPENDIX VI %Question 3 a): clear all ; clc; n=0:10; x1=exp(-2.*abs(n)).*sin( (2*pi/36)*n); subplot(2,2,1); stem(n,x1); ylabel x[n] ; xlabel n ; title 'x[n]' ; % x1 mirror: x2 = exp(-2.*abs(n)).*sin( (2*pi/36)*-n); subplot(2,2,2) stem(-n,x2); ylabel x[n] ; xlabel n ; title 'Mirror of x[n]' ; % x1 even: e=(1/2)*(x1+x2);
subplot(2,2,3); stem(n,e); ylabel x[n] ; xlabel n ; title 'Even component of x[n]' ; % x1 odd o = (1/2) * ( x1 - x2); subplot(2,2,4); stem(n,o); ylabel x[n] ; xlabel n ; title 'Odd component of x[n]' ; Figure 12. Part 1 Q3 (a) APPENDIX VII %Question 3 b): clear all ; clc; n=-5:5; x1 = (-1).^(n-1); subplot(2,2,1);
stem(n,x1); ylabel x[n] ; xlabel n ; title 'x[n]' ; % x1 mirror: x2 = (-1).^(-n-1); subplot(2,2,2) stem(-n,x2); ylabel x[n] ; xlabel n ; title 'Mirror of x[n]' ; % x1 even: e=(1/2)*(x1+x2); subplot(2,2,3); stem(n,e); ylabel x[n] ; xlabel n ; title 'Even component of x[n]' ; % x1 odd o = (1/2) * ( x1 - x2); subplot(2,2,4); stem(n,o); ylabel x[n] ; xlabel n ; title 'Odd component of x[n]' ; Figure 13. Part 1 Q3 (b)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
APPENDIX IIX %Question 3 c): clear all ; clc; n = [1 : 20 ]; x1 = sin((2*pi/40) * n) .* cos((2*pi/40) * n); for index = 1 : 20 x2(index) = sin((2*pi/40) * index) * cos((2*pi/40) * index); end subplot(2,1,1) stem(n, x1) title 'Elegant method making full use of MATLABs array capabilities' xlabel n ylabel x[n] subplot(2,1,2) stem(n, x2) title 'Gets the job done but it is a lot of work and we are not in the MATLAB mindset' xlabel n ylabel x[n] Figure 14. Part 1 Q3 (c)
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
APPENDIX IX %Part II: %Question 1: clear all ; clc; n=0:9; x=zeros(1:10); x(2:4)=1; y(1)=0; for (i=1:10) if (i==1) y(i)=x(i); else y(i)=x(i)+((1/4).*y(i-1)); end end stem (n,y) xlabel n ylabel y[n] title 'Output Response y[n]' Figure 15. Part 2 Q1
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
APPENDIX X %Part II: %Question 2: clear all ; clc; n=0:9; x=zeros(1:10); x(2:4)=1; y(1)=0; h=(1/4).^n; y=conv(x(1:9),h(1:9)); stem(y) title 'Output response y[n]' xlabel n ylabel y[n] Figure 16. Part 2 Q2
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help
APPENDIX XI %Part II: %Question 3: clear all ; clc; %a) x=[1 2 3]; y=Sys1(x); n=0:10; y1=5*y; y2=3*y; y3=y1+y2; x1=Sys1(5*x); x2=Sys1(3*x); x3=x1+x2; if y3==x3 disp( 'Output consistent with a linear system' ) else disp( 'Non-linear system' ) end disp(x3); disp(y3); %b) if y3(1)== x3(1); disp( 'Time invariant' ) else disp( 'Time variant' ) end
Your preview ends here
Eager to read complete document? Join bartleby learn and gain access to the full version
  • Access to all documents
  • Unlimited textbook solutions
  • 24/7 expert homework help