I'm trying to calculate Frequency Modulation (radio context) for a given audio file (12 seconds), I managed to do it on a sine wave with the following formula:
fm = np.sin(TWO_PI * (fc + b * data) * t)
Where fc is the Carrier Frequency, b is the Modulation index, data is the audio file and t is the time vector.
But I can't seem to get it to work on the audio file,
this is what I have so far:
As you can see, you can't really understand when the frequency changes, I can zoom in but that's not really reliable and confusing I would be happy to hear other ways.
Here is my full code:
import scipy.io.wavfile
import matplotlib.pyplot as plt
import numpy as np
def generateSignalFM(t,data):
TWO_PI = 2 * np.pi
fc = 10000
b = 5
fm = np.sin(TWO_PI * (fc + b * np.array(data)) * t) # calculaying frequency modulation
fig, axs = plt.subplots(nrows=2, ncols=1)
fig.tight_layout()
axs[1].plot(t,fm)
axs[1].set_xlabel("Time(s)")
axs[1].set_ylabel("Amplitude")
axs[1].set_title("Modulated Signal (FM)")
axs[0].plot(t,data)
axs[0].set_xlabel("Time(s)")
axs[0].set_ylabel("Amplitude")
axs[0].set_title("Original Signal")
plt.show()
samplerate, data = scipy.io.wavfile.read("musicSample.wav")
sample_for = 12
start_time = 30*samplerate # start from 30 seconds
end_time = start_time + (samplerate * sample_for) # sample for 1 second
split_data= data[start_time:end_time]
time = np.arange(0,sample_for,1/samplerate) #sample 1 second