Introduction
Wave multiplication (modulation) is used in the domain of sound wave and communication. Here we define 2 waves of different frequency, then we calculate and draw the multiplied wave by python.
Define 2 waves
wave1, f1 = 1,000Hz, draw wave1 in 1ms
wave2, f2 = 5,000Hz, draw wave2 in 1ms
waveNew = wave1 x wave2, draw this new wave in 1ms
Import numpy and matplotlib
## Import library import numpy as np import matplotlib.pyplot as plt # library for plotting
Define drawing function
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, f1 = 1kHz, draw wave1 in 1ms
Samples=F2(waves)∗10(samples/wave)∗0.001(s)
x axis is a time array, [t0,t1,...,tn]
y axis is a sine wave of t, [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, freq2 = 5,000Hz, draw wave2 in 1ms
Samples=F2(waves)∗10(sampleswave)∗0.001(s)
x axis is a time array, [t0,t1,...,tn]
y axis is a sine wave of t, [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")
Modulation wave = wave1 x wave2 in 1ms
wave = wave1 x wave2
y axis is a sine wave of 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")
Start writing here...