70 likes | 159 Views
Date: 07 Feb 07. Lab2 (Signal & System) Instructor: Anan Osothsilp. Date: 07 Feb 07. Objective: Introduce Matlab script working environment Learn how to write simple Matlab routine Learn how to write simple Matlab function Learn how to manage function file in Matlab environment.
E N D
Date: 07 Feb 07 Lab2 (Signal & System) Instructor: Anan Osothsilp
Date: 07 Feb 07 Objective: Introduce Matlab script working environment Learn how to write simple Matlab routine Learn how to write simple Matlab function Learn how to manage function file in Matlab environment Anan Osothsilp Page 1 Lab2
Date: 07 Feb 07 Lab Instruction: Follow the video tutorial and do Lab exercises Anan Osothsilp Page 2 Lab2
Date: 07 Feb 07 Function Format Function [arg1, arg2, … , argn] = FunctionName (arg1,arg2,…,argN) %program code here Function [y1, y2] = Process_signal (x1, x2) y1 = 2*x1; y2 = 3*x2; Anan Osothsilp Page 3 Lab2
Date: 07 Feb 07 Exercise 1 • Create function find_average to calculate the average value of input vector • Input_Vector = [1,3,5,7,9,11,12]; • Average = find_average(Input_Vector); Function output = Find average (input) x = sum(input); x2 = X/length(input); output = x2; Note: sum function is used to calculate summation of all elements for input vector length function is used to find the total number of elements of input vector Anan Osothsilp Page 4 Lab2
Date: 07 Feb 07 Exercise 2: let t = 0:0.01:10; input = 3*sin(2*pi*t); • Create function find_peak to calculate the maximum value of input vector Function output = Find_peak (input) // your code go here Hints: use max() function to find maximum value inside input vector alternative: Instead of using max function to find maximum value, Use for loop to find maximum number temp = 0; for i = 1: length(input) %this will loop from first to last element of input vector if input(i) > temp %if current value > temp then temp = input; % put it into temp end end Anan Osothsilp Page 5 Lab2
x1 y1 x2 Process_signal y2 x3 Date: 07 Feb 07 Exercise 3 • Create function to process 3 input signal as depicted in by following figure t= 0:0.01:10; x1 = sin(2*pi*1*t); x2 = sin(2*pi*2*t); x3 = sin(2*pi*4*t); Anan Osothsilp Page 6 Lab2