Revision as of 15:05, 11 September 2008 by Zcurosh (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Part B. Find the Bug

The original code is displayed below.

F0 =13;

T0 =1/F0;

Ts = 0.07;

t  = 0:Ts:13*T0;

x = real(exp(j*(2*pi*F0*t-pi/2)));

plot(t,x)

This code is supposed to display the real part of the complex exponential, which is a sine wave. This code actually produces a distorted sine, since the step size, Ts, is not sufficiently small to get enough data points to produce a smooth curve.

Solution

In order to correct this, one simply must adjust the step size, Ts, to get smaller readings, producing a smoother curve. The smaller the step size one chooses, the smoother the output curve will be. A step size of Ts/100 or even Ts/1000 or Ts/10000 will produce a sufficiently smooth sine wave. The new code is displayed below.

F0 =13;

T0 =1/F0;

Ts = 0.07/10000

t  = 0:Ts:13*T0;

x = real(exp(j*(2*pi*F0*t-pi/2)));

plot(t,x)

Alumni Liaison

To all math majors: "Mathematics is a wonderfully rich subject."

Dr. Paul Garrett