hmw2_sol_sp08

# hmw2_sol_sp08 - i ECE220 Homework Assignment#2 Solutions...

This preview shows pages 1–3. Sign up to view the full content.

i ECE220 Homework Assignment #2 Solutions Problem 3.18. For safety reasons, electrical devices limit the output voltage v out ( t ) to a maximum allowed value A , regardless of the value of the input voltage v in ( t ) . Mathematically, we can represent such devices via the function v out ( t ) = f ( v in ( t )) , where f ( v ) = v, - A v A , A, v > A , - A, v < - A . (a) Writea function clip(v,A) to simulate this device. (b) Write a script that calls this function with a sinusoidal input voltage v in ( t ) = 10cos(2 πt ) . Use A = 2 . Plot both the input and output on the same graph, for t [ - 5 , 5] . (c) Repeat part (b) for the input voltage v in ( t ) = 10 t . Solution (a) Here is one way to write the clip(v,A) function in Matlab; it codes the definition of the device operations directly. function y = clip(v, A) % v: vector of input voltage values % A: clipping threshold % The intuitive (beginner’s) approach would be to use a for loop % % Find out how many elements are in the input vector v N = length(v); % work on each element individualy for k = 1 : N if( v(k) > A ) y(k) = A ; elseif ( v(k) < - A ) y(k) = -A ; else y(k) = v(k) ; end end

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
ii This is slow in Matlab; moreover, it assumes that v is a row or a column vector. It would not allow v to be a matrix which stores, say, two signals in two columns. Here is a more experienced Matlab programmer’s code; it makes use of the “vectorized" commands we discuss in section 3.6, page 134 of the textbook. function y = clip(v, A) % v: vector of input voltage values % A: clipping threshold % Set the output as a vector similar to the input vector % and initialize to v. y = v ;
This is the end of the preview. Sign up to access the rest of the document.

## This note was uploaded on 03/01/2011 for the course ECE 220 taught by Professor Nilson during the Spring '08 term at N.C. State.

### Page1 / 9

hmw2_sol_sp08 - i ECE220 Homework Assignment#2 Solutions...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online