#!/usr/bin/env python # coding: utf-8 # Amplitudová modulace # ====================== # In[1]: import matplotlib.patches as mpp # Konstanty fs=44100 Ts=1./fs length=1 # modulační vlna fm=500. Tm=1./fm # nosná vlna m=0.8 fc=6000. Tc=1./fc Uc=3 # časová osa t = arange(0,length,1./fs) # modulační signál um = 1*cos(2*pi*fm*t) # převod do frekvenční oblasti from scipy.fftpack import fft, ifft Ck= fft(um) absCk = 2./len(um) * numpy.abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) # Modulační signá fig=figure() subplot(211) plot(t,um) title(u'Modulační signál') grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('$\mathrm u_m$\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(um), 1.1*max(um)]) xlim([0,3*Tm]) subplot(212) title(ur'Modulační signál -- amplitudové spektrum') plot(f,absCk,'.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('$\mathrm U_m$\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,1.1*max(absCk)]); xlim([0,10e3]) grid(1) text(500,-0.2 , '$\mathbf{f_m}$', size=16) #figtext(0,1 , '$\mathrm f_m$', size=16) tight_layout() # In[2]: # Nosná vlna před modulací uc = Uc*cos(2*pi*fc*t) Ck= fft(uc) absCk = 2./len(uc) * abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) figure() subplot(211) plot(t,uc) title(u'Nosný signál') grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('$\mathrm u_c$\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(uc), 1.1*max(uc)]) xlim([0,3*Tm]) subplot(212) title(u'Nosný signál -- amplitudové spektrum') plot(f,absCk,'.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('$\mathrm U_c$\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,1.1*max(absCk)]); xlim([0,10e3]) text(6000,-0.6 , '$\mathbf{f_c}$', size=16) grid(1) tight_layout() # In[3]: # Nosná vlna po modulací m=0.8 uc = Uc*(1+m*um)*cos(2*pi*fc*t) Ck= fft(uc) absCk = 2./len(uc) * abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) figure() subplot(211) plot(t,uc) title(ur'Modulovaný signál m=80\%') grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('$\mathrm u_c$\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(uc), 1.1*max(uc)]) xlim([0,3*Tm]) subplot(212) title(ur'Modulovaný signál m=80\%-- amplitudové spektrum') plot(f,absCk,'.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('$\mathrm U_c$\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,1.1*max(absCk)]); xlim([0,10e3]) text(6000,-0.6 , '$\mathbf{f_c}$', size=16) text(6500,-0.6 , '$\mathbf{f_c+f_m}$', size=16) text(4800,-0.6 , '$\mathbf{f_c-f_m}$', size=16) grid(1) tight_layout() # In[4]: # Nosná vlna po modulací m=0.2 uc = Uc*(1+m*um)*cos(2*pi*fc*t) Ck= fft(uc) absCk = 2./len(uc) * abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) figure() subplot(211) plot(t,uc) title(ur'Modulovaný signál m=20\%') grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('u\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(uc), 1.1*max(uc)]) xlim([0,3*Tm]) subplot(212) title(ur'Modulovaný signál m=20\%-- amplitudové spektrum') plot(f,absCk,'.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('U\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,1.1*max(absCk)]); xlim([0,10e3]) text(6000,-0.6 , '$\mathbf{f_c}$', size=16) text(6500,-0.6 , '$\mathbf{f_c+f_m}$', size=16) text(4800,-0.6 , '$\mathbf{f_c-f_m}$', size=16) grid(1) tight_layout() # Hloubka modulace # ------------------- # # $$m=\frac{\Delta U_c}{U_c}$$ # In[5]: # Nosná vlna po modulací m=0.8 uc = Uc*(1+m*um)*cos(2*pi*fc*t) figure(figsize=(8,7)) ax=subplot(111) plot(t,uc, alpha=0.3) title(ur'Modulovaný signál m={:d}\%'.format(int(100*m))) grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('u\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(uc), 1.1*max(uc)]) xlim([0,3*Tm]) plot(t, 3+3*m*cos(2*pi*fm*t),'g--' ) #plot(t, -3-3*m*cos(2*pi*fm*t),'g--' ) axhline(y=3, xmin=0, xmax=1, linestyle='--', linewidth=1, color='g') ax.add_patch( mpp.FancyArrowPatch((0.003,0), (0.003,3), arrowstyle='<->',lw=2, linestyle='solid', mutation_scale=25, color='k', alpha=0.9, shrinkA=0, shrinkB=0 ), ) ax.add_patch( mpp.FancyArrowPatch((0.002,3), (0.002,3*(m+1)), arrowstyle='<->',lw=2, linestyle='solid', mutation_scale=25, color='k', alpha=0.9, shrinkA=0, shrinkB=0 ), ) bbox_props = dict(boxstyle="round,pad=0.2", fc="0.9", ec="k", lw=0.5) text(0.0025,4, "$\mathbf{\Delta U_c}$", ha="center", va="center", size=20, bbox=bbox_props) text(0.0033,1.5, "$\mathbf{U_c}$", ha="center", va="center", size=20, bbox=bbox_props) # Amplitudová modulace nesinusového modulačního napětí # ------------------------------------------------------- # In[6]: fm # In[7]: # modulační signál um = 1*cos(2*pi*500*t)+1.2*cos(2*pi*600*t)+0.8*cos(2*pi*700*t)+0.6*cos(2*pi*800*t)+0.4*cos(2*pi*900*t) um = um/max(um) # převod do frekvenční oblasti from scipy.fftpack import fft, ifft Ck= fft(um) absCk = 2./len(um) * numpy.abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) # Modulační signá figure() subplot(211) plot(t,um) title(u'Neharmonický modulační signál') grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('u\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(um), 1.1*max(um)]) xlim([0,6*Tm]) subplot(212) title(ur'Neharmonický modulační signál -- amplitudové spektrum') plot(f,absCk,'.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('U\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,2]); xlim([0,10e3]) grid(1) tight_layout() #text(400,-0.04, '$\mathbf{f_{min}}$', size=16) annotate('$\mathbf{f_{min}}$', xy=(500,0),size=16, xytext=(100,-0.5), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_{max}}$', xy=(900,0),size=16, xytext=(1000,-0.5), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) # In[8]: # Nosná vlna po modulací m=0.9 uc = Uc*(1+m*um)*cos(2*pi*fc*t) Ck= fft(uc) absCk = 2./len(uc) * abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) figure() subplot(211) plot(t,uc) title(ur'Neharmonicky modulovaný signál m=90\%') grid('on') xlabel(r't\,[s] $\rightarrow$', x=0.9) ylabel('u\,[V] $\uparrow$', y=0.9, rotation=0) ylim([-1.1*max(uc), 1.1*max(uc)]) xlim([0,6*Tm]) ax=subplot(212) title(ur'Neharmonicky modulovaný signál m=90\% -- amplitudové spektrum') plot(f,absCk,'.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('U\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,1.1*max(absCk)]); xlim([0,10e3]) grid(1,'major') minorticks_on() tight_layout() text(6000,-0.7,r'$\mathbf{f_c}$',size=16, horizontalalignment='center') annotate('$\mathbf{f_c-f_{max}}$', xy=(5100,0),size=16, xytext=(4200,-0.6), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_c+f_{max}}$', xy=(6900,0),size=16, xytext=(6800,-0.6), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_c-f_{min}}$', xy=(5500,0),size=16, xytext=(4700,-1.2), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_c+f_{min}}$', xy=(6500,0),size=16, xytext=(6300,-1.2), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) ax.add_patch( mpp.FancyArrowPatch((5100,1), (6900,1), arrowstyle='<->', lw=2, linestyle='solid', mutation_scale=25, color='green', alpha=0.9, shrinkA=0, shrinkB=0 ), ) text(6200,1.3, '$\mathbf{B=2 f_{max}}$',size=20) axvspan(5100, 6900, facecolor='g', alpha=0.2, ymax=0.3) # In[9]: # Nosná vlna po modulací m=0.9 uc = Uc*(1+m*um)*cos(2*pi*6000*t) uc1 = Uc*(1+m*um)*cos(2*pi*10000*t) Ck= fft(uc) absCk = 2./len(uc) * abs(Ck)[:len(Ck)/2] f = arange(0,fs/2,float(fs)/len(Ck)) Ck1= fft(uc1) absCk1 = 2./len(uc1) * abs(Ck1)[:len(Ck1)/2] figure() ax=subplot(212) title(ur'Neharmonicky modulovaný signál m=90\% -- amplitudové spektrum') plot(f,absCk,'b.-') plot(f,absCk1,'b.-') xlabel(r'f\,[Hz] $\rightarrow$', x=0.9) ylabel('U\,[V] $\uparrow$', y=0.9, rotation=0) ylim([0,1.1*max(absCk)]); xlim([0,15e3]) grid(1,'major') minorticks_on() tight_layout() text(6000,-0.7,r'$\mathbf{f_c}$',size=16, horizontalalignment='center') annotate('$\mathbf{f_c-f_{max}}$', xy=(5100,0),size=16, xytext=(4200,-0.6), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_c+f_{max}}$', xy=(6900,0),size=16, xytext=(6800,-0.6), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_c-f_{min}}$', xy=(5500,0),size=16, xytext=(4700,-1.2), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) annotate('$\mathbf{f_c+f_{min}}$', xy=(6500,0),size=16, xytext=(6300,-1.2), arrowprops=dict(arrowstyle="->",connectionstyle="arc3,rad=0", ),) ax.add_patch( mpp.FancyArrowPatch((5100,1), (6900,1), arrowstyle='<->', lw=2, linestyle='solid', mutation_scale=25, color='green', alpha=0.9, shrinkA=0, shrinkB=0 ), ) ax.add_patch( mpp.FancyArrowPatch((9100,1), (10900,1), arrowstyle='<->', lw=2, linestyle='solid', mutation_scale=25, color='green', alpha=0.9, shrinkA=0, shrinkB=0 ), ) text(6200,1.3, '$\mathbf{B=2 f_{max}}$',size=20) axvspan(5100, 6900, facecolor='g', alpha=0.2, ymax=0.3) text(10200,1.3, '$\mathbf{B=2 f_{max}}$',size=20) axvspan(9100, 10900, facecolor='g', alpha=0.2, ymax=0.3)