@@ -203,7 +203,7 @@ def plot_phase():
203203
204204
205205
206- def make_phase_cirlce ():
206+ def make_phase_circle ():
207207 """Adapted from: https://commons.wikimedia.org/wiki/File:Phase_shifter_using_IQ_modulator.gif"""
208208 # for t in range(0, 356, 5):
209209 @gif .frame
@@ -220,13 +220,13 @@ def plt_set(t):
220220 y = 1 * np .sin (0.0174533 * t )
221221
222222 # creating I, Q, I+Q amplitude and Phase (0° to 720°) for WAVE DIAGRAM
223- x2 = np .linspace (0 , 721 , 400 ) # Pahse from 0° to 720° divided into 400 points
224- y2 = 1 * np .sin (0.0174533 * t ) * np .sin (0.0174533 * x2 ) # Q
225- z2 = 1 * np .cos (0.0174533 * t ) * np .cos (0.0174533 * x2 ) # I
226- q2 = ( y2 + z2 ) # (I+Q )
223+ x2 = np .linspace (0 , 721 , 400 ) # Phase from 0° to 720° divided into 400 points
224+ y2 = 1 * np .sin (0.0174533 * t + np . pi ) * np .sin (0.0174533 * x2 + np . pi ) # Q
225+ z2 = 1 * np .cos (0.0174533 * t + np . pi ) * np .cos (0.0174533 * x2 + np . pi ) # I
226+ q2 = np . sin ( 0.0174533 * ( x2 + t ) )
227227
228228 # creating text to show current phase t
229- text1 = " phase = " + str ( t ) + ' °'
229+ text1 = f' phase = { t } °'
230230
231231 # II) CREATING THE PLOT (phasor and wave diagram in one plot arranged 1 x 2)
232232
@@ -264,26 +264,26 @@ def plt_set(t):
264264
265265 # Setting the y axis ticks at (-1,-0.5,0,0.5,1)
266266 ax1 .set_yticks ([- 1 , - 0.5 , 0 , 0.5 , 1 ])
267+ ax1 .set_xticks ([- 1 , - 0.5 , 0 , 0.5 , 1 ])
268+ ax1 .set_ylim (- 1.1 , 1.1 )
269+ ax1 .set_xlim (- 1.1 , 1.1 )
267270
268271 # Creating Arrows and dashed lines
269272 ax1 .arrow (0 , 0 , x , y , length_includes_head = 'True' , head_width = 0.05 , head_length = 0.1 ,
270273 color = 'g' ) # I+Q
271- # ax1.arrow(0, 0, x, 0, length_includes_head='True', head_width=0.05, head_length=0.1,
272- # color='b') # I
273- # ax1.arrow(0, 0, 0, y, length_includes_head='True', head_width=0.05, head_length=0.1,
274- # color='r') # Q
275274 ax1 .arrow (x , 0 , 0 , y , length_includes_head = 'True' , head_width = 0 , head_length = 0 ,
276275 ls = '-.' ) # vertical dashed lines
277- ax1 .arrow (0 , y , x , 0 , length_includes_head = 'True' , head_width = 0 , head_length = 0 ,
278- ls = '-.' ) # Horizontal dashed lines
276+ # ax1.arrow(0, y, x, 0, length_includes_head='True', head_width=0, head_length=0,
277+ # ls='-.') # Horizontal dashed lines
279278
280279 # II-B) WAVE DIAGRAM
281280
282281 # setting the y axis limit
283- ax2 .set_ylim (- 1.5 , 1.5 )
282+ ax2 .set_ylim (- 1.1 , 1.1 )
284283
285284 # Setting the y axis ticks at (0, 180, 360, 540, 720) degree phase
286285 ax2 .set_xticks ([0 , 180 , 360 , 540 , 720 ])
286+ ax2 .set_yticks ([- 1 , - 0.5 , 0 , 0.5 , 1 ])
287287 # ax2.set_xlim(0, 720)
288288
289289 # Setting the position of the x and y axis
@@ -298,38 +298,16 @@ def plt_set(t):
298298 ax2 .set_xlabel ('Phase (degree)' , labelpad = 0 )
299299 ax2 .set_ylabel ('Amplitude' , labelpad = 0 )
300300
301- # Plotting I, Q and I+Q waves
302- # ax2.plot(x2, z2, 'b', label='I', linewidth=0.5)
303- # ax2.plot(x2, y2, 'r', label='Q', linewidth=0.5)
304- ax2 .plot (x2 , q2 , 'g' , label = 'I+Q' )
305-
306- # function for amplitude of I+Q green arrow
307- c1 = 1 * np .cos (0.0174533 * t ) * np .cos (0.0174533 * t ) + 1 * np .sin (0.0174533 * t ) * np .sin (
308- 0.0174533 * t )
309-
310- # plotting I+Q arrow that moves along to show the current phase
311- # ax2.arrow(t, 0, 0, c1, length_includes_head='True', head_width=10, head_length=0.07,
312- # color='g')
313-
314- # plotting I and Q amplitude arrows at position 180° and 90° respectively
315- # ax2.arrow(180, 0, 0, 1 * np.cos(0.0174533 * t) * np.cos(0.0174533 * 180),
316- # length_includes_head='True', head_width=10, head_length=0.07, color='b')
317- # ax2.arrow(90, 0, 0, 1 * np.sin(0.0174533 * t) * np.sin(0.0174533 * 90),
318- # length_includes_head='True', head_width=10, head_length=0.07, color='r')
319-
320- # Creating legend
321- # ax2.legend(loc='center', ncol=3, bbox_to_anchor=[0.5, 0.94])
301+ # plot sine wave
302+ ax2 .plot (x2 , q2 , 'g' )
322303
323304 # Adjusting the relative position of the subplots inside the figure
324305 fig .subplots_adjust (left = 0.07 , bottom = 0.15 , right = None , top = None , wspace = 0.3 , hspace = None )
306+ # plt.tight_layout()
325307
326- # # Saving the figure
327- # fig.savefig('0file%s.png' % t)
328-
329- # Clearing the figure for the next iteration
330- # fig.clf()
331-
308+ # plt.show()
332309
310+ # plt_set(90.0)
333311 frames = [plt_set (t ) for t in range (0 , 356 , 5 )]
334312 gif .save (frames , 'book/images/basics/circle_phase.gif' , duration = 5.0 )
335313
@@ -403,8 +381,8 @@ def main():
403381 # plot_lineary_spec()
404382 # plot_mely_spec()
405383 # plot_phase()
406- # make_phase_cirlce ()
407- phase_intersect ()
384+ make_phase_circle ()
385+ # phase_intersect()
408386
409387if __name__ == '__main__' :
410388 main ()
0 commit comments