波相乘

調變

簡介

波相乘(調變)廣泛應用在聲波和通訊領域。本文中,我們定義了 2 個不同頻率的波,用 python 計算和劃出波相乘後的波形。

定義 2 個不同頻率的波

wave1(波1), f1 = 1,000Hz, 在 1ms 區間內畫出波1
wave2(波2), f2 = 5,000Hz, 在 1ms 區間內畫出波2
wave(調變) = 波1 x 波2, 在 1ms  區間內畫出相乘波

導入函示庫 numpy 和 matplotlib

## Import library
import numpy as np
import matplotlib.pyplot as plt # library for plotting 

定義畫圖函式

def drawGraph(xp, yp, titleLabel = 'Draw Graph', xLabel = 'X Axis', yLabel = 'y Axis'):
    '''
    Draw graph
    Parameters:
        xp : x axis data
        yp : y axis data
    '''
    # Draw graph data
    fig, ax = plt.subplots(nrows=1, ncols=1) # create figure handle
    ax.plot(xp, yp)
    ax.set_title(titleLabel) # window title
    ax.set_xlabel(xLabel) # x-axis label
    ax.set_ylabel(yLabel) # y-axis label
    #fig.show()
    

Wave1(波1), f1 = 1kHz, 在 1ms 區間內劃出波1

樣品數 = F2(waves) ∗ 10(samples/wave) ∗ 0.001(s)

x 軸是一個時間陣列, [t0,t1,...,tn]
y 軸是時間 t 的正弦波函式頻率為 f1, [sin(2πf1t0),sin(2πf1t1),...,sin(2πf1tn)]
y=f(t)=sin(2πf1t)

f1 = 1000
f2 = 5000
nBlock = 10 # 10 points/wave
dt = 0.001 # 1ms
samples = f2 * nBlock * dt # samples in 5ms
# generate t array on x axis
xTime = np.arange(0, dt+(1/(f2*nBlock)), 1/(f2*nBlock)) # time base

# Draw point p(xt,yt) @ 1kHz
yValue1 = np.sin(2*np.pi*xTime*f1) # sine wave of f1
drawGraph(xTime, yValue1, "Draw wave at frequency 1kHz", "Time(s)", "Value")

 

Wave2(波2), f2 = 5,000Hz, 在 1ms 區間內劃出波2

樣品數 = F2(waves) ∗ 10(samples/wave) ∗ 0.001(s)

x 軸是一個時間陣列, [t0,t1,...,tn]
y 軸是時間 t 的正弦波函式頻率為 f2, [sin(2πf2t0),sin(2πf2t1),...,sin(2πf2tn)]
y=f(t)=sin(2πf2t)

# Draw point p(xt,yt) @ 5kHz
yValue2 = np.sin(2*np.pi*xTime*f2) # sine wave of f2
drawGraph(xTime, yValue2, "Draw wave at frequency 5kHz", "Time(s)", "Value")


wave(調變) = wave1(波1) x wave2(波2) in 1ms

wave = wave1 x wave2
y 軸是時間 t 的相乘波函式, [sin(2πf1t0)∗sin(2πf2t0),sin(2πf1t1)∗sin(2πf2t1),...,sin(2πf1tn)∗sin(2πf2tn)]
y=f(t)=sin(2πf1t)∗sin(2πf2t)

# Draw modulation point p(xt,yt)
yValue = yValue1 * yValue2 # modulation wave = wave1 x wave2
drawGraph(xTime, yValue, "Draw modulation wave", "Time(s)", "Value")
No description has been provided for this image


Start writing here...

Study