I have a 4 seconds audio sample of someone saying "hello", I managed to load the wav file and show it in a time-amplitude spectrum, my next step was to calculate a AM (Amplitude Modulation) on this sound, I managed to do it on a sine wave I created but doing it on an actual sound is apparently different.
I am getting unexpected result, I am expecting a cos shape with amplitude changes according to the sound, but I'm getting back roughly the same sound!
Here is my full code:
def generateSignalAM(t,data):
TWO_PI = 2 * np.pi
fc = 100
ac = 0.5
carrier_wave = np.cos(t * fc * TWO_PI)
am = carrier_wave * (1 + data/ac)
plt.plot(t,am)
plt.plot(time,data)
plt.xlabel("Time(s)")
plt.ylabel("Amplitude")
plt.legend(['AM Signal', 'Original Signal'])
plt.show()
return am
samplerate, data = scipy.io.wavfile.read("hello.wav")
duration = len(data)/samplerate
time = np.arange(0,duration,1/samplerate) #time vector
generateSignalAM(time,data)
Here is the output:
Following @The Photon I've changed the code to this:
def generateSignalAM(t,data):
#sample rate is 44100 Hz
TWO_PI = 2 * np.pi
fc = 10000
ac = 0.00005
carrier_wave = np.cos(t * fc * TWO_PI)
am = carrier_wave * (1 + data/ac)
plt.plot(t,am)
#plt.plot(time,data)
plt.xlabel("Time(s)")
plt.ylabel("Amplitude")
#plt.legend(['AM Signal', 'Original Signal'])
plt.show()
return am
And got the following result: