This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Page 1 function y = u(x) for n = 1: length(x) if (x(n) < 0) y(n) = 0; else y(n) = 1; end ; end function y = r(x) for n = 1: length(x) if (x(n) < 0) y(n) = 0; else y(n) = x(n); end ; end Lab 2 for ECES 302 - Piecewise-Linear Functions II First Name …………………….. Last Name …………………….. Grade …… / 5 Review. Building Blocks for Piecewise Functions in Matlab. Reenter the following m-files which enable Matlab to work with the unit step and unit ramp functions just as you would in your textbook. Open Matlab. To create a new M-file, select the menu sequence: File >> New >> M-File (or use the keyboard shortcut (Control +N) Save this file as u.m in the default workspace. Save this file as r.m in the default workspace. Universal Representation Theorem for Piecewise Linear Functions We repeatedly use the following universal construction for piecewise-linear functions. Assume that all the discontinuities in value and slope for a piecewise-linear function f(t) occur at the points t 1 , t 2 , … , t n and denote the discontinuities in value and slope as b 1 , b 2 , … , b n and m 1 , m 2 , … , m n respectively. Then f(t) can be written: f ( t ) = b + m t + b k u ( t – t k )+ m k r ( t – t k ) ! k = 1 n where (b +m t) gives the leftmost linear portion of f(t) before the first discontinuity. Unit step function u(t). Ramp function r(t). Jumps in value. Jumps in slope. Leftmost linear piece. Page 2 Exercise 1. Generating a Square wave from a Sine Wave using the Step Function Create a simultaneous plot of y ( t ) = u ( sin(2 π t ) ) and x ( t ) = sin(2 π t ) from 0 to 4 to obtain a square wave function. Plot the sine wave in blue and the square wave in red. Adjust the Axes Properties so that the font has size 24, and the curves both have a thickness of 2. >> t = 0 : 0.01 : 4; >> x = sin(2*pi*t); y = u(x); >> figure(1), plot( t,x,'b', t,y,'r') Above you can see how the unit step function acts like a comparator , returning +1 if the input exceeds zero. Exercise 2. Rectified Sine Wave using a Ramp Function Adjust the above code to create a simultaneous plot (in figure 2) of the above sine wave x ( t ) = sin(2 π t ) from 0 to 4 and its rectified form. Use the ramp function to rectify the sine wave. You only need to change the definition of y ( x )....
View Full Document
- Spring '08
- ........., Double click, Piecewise linear function