@@ -203,7 +203,7 @@ def plot_phase():
203
203
204
204
205
205
206
- def make_phase_cirlce ():
206
+ def make_phase_circle ():
207
207
"""Adapted from: https://commons.wikimedia.org/wiki/File:Phase_shifter_using_IQ_modulator.gif"""
208
208
# for t in range(0, 356, 5):
209
209
@gif .frame
@@ -220,13 +220,13 @@ def plt_set(t):
220
220
y = 1 * np .sin (0.0174533 * t )
221
221
222
222
# 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 ) )
227
227
228
228
# creating text to show current phase t
229
- text1 = " phase = " + str ( t ) + ' °'
229
+ text1 = f' phase = { t } °'
230
230
231
231
# II) CREATING THE PLOT (phasor and wave diagram in one plot arranged 1 x 2)
232
232
@@ -264,26 +264,26 @@ def plt_set(t):
264
264
265
265
# Setting the y axis ticks at (-1,-0.5,0,0.5,1)
266
266
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 )
267
270
268
271
# Creating Arrows and dashed lines
269
272
ax1 .arrow (0 , 0 , x , y , length_includes_head = 'True' , head_width = 0.05 , head_length = 0.1 ,
270
273
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
275
274
ax1 .arrow (x , 0 , 0 , y , length_includes_head = 'True' , head_width = 0 , head_length = 0 ,
276
275
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
279
278
280
279
# II-B) WAVE DIAGRAM
281
280
282
281
# setting the y axis limit
283
- ax2 .set_ylim (- 1.5 , 1.5 )
282
+ ax2 .set_ylim (- 1.1 , 1.1 )
284
283
285
284
# Setting the y axis ticks at (0, 180, 360, 540, 720) degree phase
286
285
ax2 .set_xticks ([0 , 180 , 360 , 540 , 720 ])
286
+ ax2 .set_yticks ([- 1 , - 0.5 , 0 , 0.5 , 1 ])
287
287
# ax2.set_xlim(0, 720)
288
288
289
289
# Setting the position of the x and y axis
@@ -298,38 +298,16 @@ def plt_set(t):
298
298
ax2 .set_xlabel ('Phase (degree)' , labelpad = 0 )
299
299
ax2 .set_ylabel ('Amplitude' , labelpad = 0 )
300
300
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' )
322
303
323
304
# Adjusting the relative position of the subplots inside the figure
324
305
fig .subplots_adjust (left = 0.07 , bottom = 0.15 , right = None , top = None , wspace = 0.3 , hspace = None )
306
+ # plt.tight_layout()
325
307
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()
332
309
310
+ # plt_set(90.0)
333
311
frames = [plt_set (t ) for t in range (0 , 356 , 5 )]
334
312
gif .save (frames , 'book/images/basics/circle_phase.gif' , duration = 5.0 )
335
313
@@ -403,8 +381,8 @@ def main():
403
381
# plot_lineary_spec()
404
382
# plot_mely_spec()
405
383
# plot_phase()
406
- # make_phase_cirlce ()
407
- phase_intersect ()
384
+ make_phase_circle ()
385
+ # phase_intersect()
408
386
409
387
if __name__ == '__main__' :
410
388
main ()
0 commit comments