(New page: ==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 =1...)
 
(Find the Bug)
 
(One intermediate revision by the same user not shown)
Line 3: Line 3:
 
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.
 
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.
 
   
 
   
 +
<pre>
 
F0 =13;  
 
F0 =13;  
 
T0 =1/F0;  
 
T0 =1/F0;  
Line 10: Line 11:
 
plot(t,x)  
 
plot(t,x)  
 
   
 
   
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 wave.
+
</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.
  
 
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).
 
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==
 +
 +
<pre>
 +
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)
 +
 +
</pre>

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

Correspondence Chess Grandmaster and Purdue Alumni

Prof. Dan Fleetwood