1

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:

enter image description here

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
martineau
  • 119,623
  • 25
  • 170
  • 301
yarin Cohen
  • 995
  • 1
  • 13
  • 39

1 Answers1

0

You can see your signal's PSD after modulation by using "welch" algorithm. You can do it by scipy.signal.welch and something like this will be shown: enter image description here

This is the example for fc = 100 and sampleRate=1000

To see this, you should use the following context in your code:

import scipy.signal as ss
FM = ss.welch(fm, fs=sampleRate, nperseg=2048, noverlap=1024, nfft=2048)
axs[0].plot(FM[0],FM[1])