EXERCISES Problem 1 n = input('Enter the value of n: ') Wn = input('Enter the value of Wn between 0 to 1: ') Fs = 20000; if n>=0 & n<=5 disp('Chebychev type1 Lowpass Filter') r = input('please enter the value of r between 0 to 1: ') [b,a] = cheby1(n,r,Wn); freqz(b,a) figure(2) zplane(b,a) elseif n>=6 & n<=10 disp('Chebychev type2 Highpass Filter') r = input('please enter the value of r between 20 to 50: ') [b,a] = cheby2(n,r,Wn,'high'); freqz(b,a) figure(2) zplane(b,a) elseif n>=11 & n<=15 disp('Chebychev type1 Bandpass Filter') Wn1 = input('Enter the value of Wn1: ') Wn2 = input('Enter the value of Wn2 which is greater than Wn1: ') Wn = [Wn1 Wn2]; r = input('please enter the value of r between 0 to 1: ') [b,a] = cheby2(n,r,Wn); freqz(b,a) figure(2) zplane(b,a) elseif n>=16 & n<=20 disp('Chebychev type2 Bandstop Filter') Wn1 = input('Enter the value of Wn1: ') Wn2 = input('Enter the value of Wn2 which is greater than Wn1: ') Wn = [Wn1 Wn2]; r = input('please enter the value of r between 20 to 50: ') [b,a] = cheby2(n,r,Wn,'stop'); freqz(b,a) figure(2) zplane(b,a) else disp('value of n not in range! please try again...') end Problem 2 function[mini, maxi, aver, r, ima, trans, cnt] = compman(x) %COMPMAN Manipulation of Complex Numbers n = length(x); disp('Minimum Value of the Elements') mini = min(x); disp('Maximum Value of the Elements') maxi = max(x); disp('Average of the Elements') aver = sum(x) / n; disp('Real Parts of the Elements') r = real(x); disp('Imaginary Parts of the Elements') ima = imag(x); disp('Transpose of the Vector') trans = transpose(x); disp('Number of Elements in the Vector') cnt = length(x); Questions: 1. The difference between a script file and a function file is the structural syntax, the function workspace, inputs and its outputs. 2. The importance of creating the script file in signal spectra and signal processing is to be able to know if the output corresponds to your desired output. CONCLUSION Based from the results of our experiment, I can say that I met all the objective. Because I learned and understand that: MATLAB has several flow controls such as IF, SWITCH, FOR loops, and lastly the WHILE loops. The IF statement can be used in testing a condition and execute a block of instructions if the condition is true. And the SWITCH-CASE testing whether an expression is equal to a number of different values. While the FOR LOOPS are used to execute a set of statements a known number of times. And lastly the WHILE LOOPS will repeat the statements an indefinite number of times. MATLAB’s extensive, device-independent plotting capabilities are one of its most powerful features. They make it very easy to plot any data at any time. To plot data set, just create two vectors containing the x and y values to be plotted, and use the plot function. MATLAB make very easy to plot any data at any time. It can also plot such as linear, bar, stem, stairs, and polar. To plot data set, just create two vectors containing the x and y values to be plotted, and use the plot function. It is also very easy to make a subplots or making a several plots in one figure. In MATLAB difference between scripts and functions is that functions have input and output parameters. Script files can only operate on the variables that are hard-coded into their m-file. The functions are more suitable for general purpose tasks that will be applied to different data. Unlike most computer languages, many MATLAB functions work correctly for both real and complex inputs. MATLAB functions automatically calculate the correct answer, even if the result is imaginary or complex. INTERPRETATION OF RESULTS There are several flow controls in MATLAB such as: IF statement, SWITCH statement, FOR loops and WHILE loops. The IF statement can be used to test a condition and execute a block of instructions if the condition is true. There are three forms of the IF statement: IF-END, IF-ELSE-END, and IF-ELSEIF-END. In IF-END statement, if the condition has a numeric value of 1, or is true, the statements between the IF and END keywords will be executed. If the condition has a numeric value of 0 or is false, then the program will skip the statements between the IF and END keywords and resume at the line after the END keyword. In IF-ELSE-END, a second form of the IF statement includes the ELSE clause. This allows the programmer to use a single IF statement to handle cases where the test in the IF statement either true or false. The second form of the IF statement is : IF condition statement t1; statement t2; statement t3; : statement tn; ELSE statement f1; statement f2; statement f3; : statement fn; END If the condition is true, statements t1 to tn are executed. After statements tn is completed, the program resumes operation at the statement following the END keyword. If the condition is false, statements f1 to fn are executed. When statement fn is completed, the program resumes operation at the statement following the END keyword. The IFELSE-END form of the IF statement replaces two IF-END statements. In IF-ELSEIFEND, a third form of the IF statement uses the ELSEIF keyword. The ELSEIF portion of the IF statement lets us check a large number of different conditions. The SWITCH statement is convenient for testing whether an expression is equal to a number of different values. It cannot be used to test a condition such as if a5. However it is very useful in applications such as if a=1, do something; if a=2, do something else; if a=3, do another thing; and so on. The syntax of the SWITCH–CASE statement is: SWITCH expression CASE value1 statement 1a; statement 1b; : statement 1n; CASE value2 statement 2a; statement 2b; : statement 2n; CASE valuei statement Ia; statement Ib; : statement In; OTHERWISE statement Oa; statement Ob; : statement On; In this statement, if the expression is equal to any of the values listed, statements a to n will be executed. FOR LOOPS are used to execute a set of statements a known number of times. The syntax of the FOR statement is: FOR variable=expression statement 1; statement 2; : statement n; END A WHILE LOOPS is a construction of the form: WHILE <condition>, <program>, end where condition is a MATLAB function, as with the branching construction. The program program will execute successively as long as the value of condition is not 0. While loops carry an implicit danger in that there is no guarantee in general that you will exit a while loop.