@@ -37,8 +37,7 @@ def triangle_example(freq):
3737 thinkplot .subplot (2 )
3838 spectrum .plot ()
3939 thinkplot .config (ylim = [0 , 500 ],
40- xlabel = 'Frequency (Hz)' ,
41- ylabel = 'Amplitude' )
40+ xlabel = 'Frequency (Hz)' )
4241
4342 thinkplot .save (root = 'triangle-%d-2' % freq )
4443
@@ -70,27 +69,26 @@ def aliasing_example(offset=0.000003):
7069 """Makes a figure showing the effect of aliasing.
7170 """
7271 framerate = 10000
73- thinkplot .preplot (num = 2 )
7472
75- freq1 = 4500
76- signal = thinkdsp .CosSignal (freq1 )
77- duration = signal .period * 5
78- segment = signal .make_wave (duration , framerate = framerate )
79- thinkplot .Hlines (0 , 0 , duration , color = 'gray' )
73+ def plot_segment (freq ):
74+ signal = thinkdsp .CosSignal (freq )
75+ duration = signal .period * 4
76+ thinkplot .Hlines (0 , 0 , duration , color = 'gray' )
77+ segment = signal .make_wave (duration , framerate = framerate * 10 )
78+ segment .plot (linewidth = 0.5 , color = 'gray' )
79+ segment = signal .make_wave (duration , framerate = framerate )
80+ segment .plot_vlines (label = freq , linewidth = 4 )
8081
81- segment .shift (- offset )
82- segment .plot_vlines (label = freq1 , linewidth = 3 )
82+ thinkplot .preplot (rows = 2 )
83+ plot_segment (4500 )
84+ thinkplot .config (axis = [- 0.00002 , 0.0007 , - 1.05 , 1.05 ])
8385
84- freq2 = 5500
85- signal = thinkdsp .CosSignal (freq2 )
86- segment = signal .make_wave (duration , framerate = framerate )
87- segment .shift (+ offset )
88- segment .plot_vlines (label = freq2 , linewidth = 3 )
86+ thinkplot .subplot (2 )
87+ plot_segment (5500 )
88+ thinkplot .config (axis = [- 0.00002 , 0.0007 , - 1.05 , 1.05 ])
8989
9090 thinkplot .save (root = 'aliasing1' ,
91- xlabel = 'Time (s)' ,
92- axis = [- 0.00002 , duration , - 1.05 , 1.05 ]
93- )
91+ xlabel = 'Time (s)' )
9492
9593
9694def main ():
0 commit comments