(Find the Bug)
 
Line 12: Line 12:
 
   
 
   
 
</pre>
 
</pre>
 +
 +
==Solution==
  
 
This code is sampling at far to slow of a rate, in fact it is sampling at approximately the same time intervals as the period of the signal.
 
This code is sampling at far to slow of a rate, in fact it is sampling at approximately the same time intervals as the period of the signal.

Latest revision as of 14:14, 10 September 2008

Find the Bug

The following MATLAB program attempts to plot 13 cycles of a 13 Hz sinusoid, but it has a bug. Explain what the bug is, and modify the above code to fix this bug.

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) 
 

Solution

This code is sampling at far to slow of a rate, in fact it is sampling at approximately the same time intervals as the period of the signal.

My solution is to significantly increase the sampling rate of (t) by decreasing the time intervals it samples at (Ts) by at least a factor of 10 (more if you want more precise results).

Corrected Code

F0 =13; 
T0 =1/F0; 
Ts = 0.007; 
t  = 0:Ts:13*T0; 
x = real(exp(j*(2*pi*F0*t-pi/2))); 
plot(t,x) 
 

Alumni Liaison

Ph.D. on Applied Mathematics in Aug 2007. Involved on applications of image super-resolution to electron microscopy

Francisco Blanco-Silva