1

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:

enter image description here

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:

enter image description here

yarin Cohen
  • 995
  • 1
  • 13
  • 39
  • You are multiplying the data with a 100 Hz signal which is in the same frequency range as the signal itself, I'm not sure what you expected to get as a result. – mkrieger1 Jul 10 '21 at 14:53
  • Hint: what's the modulation depth in your system? (This isn't really a programming question, it's a question about how am modulation works. You might get better answers at dsp or electronics stackexchange) – The Photon Jul 10 '21 at 14:57
  • From my understanding, AM requires encoding the signal into bit (0s and 1s).... if the AM that you are talking about is AM/FM in radio context. After you convert the signal in bit, then, you transfer the bits to another station using amplitude modulation eg. amplitude 100 for bit 1 and amplitude 50 for bit 0. – laggyPC Jul 10 '21 at 14:52

2 Answers2

0

You are severely over-modulating your signal. If you want to see a nice envelope on your AM signal, you need to have a modulation depth less than 1. See this answer on Electrical Engineering Stackexchange for an explanation of over-modulation.

Put simply, if your AM signal is (1 - m(t)) cos( fc t ) where m(t) is the message signal and cos( fc t ) is the carrier, you want the magnitude of m(t) to be less than one at each point in time.

In your example, the magnitude of m(t) reaches nearly 5000 (The input signal reaches near -10000, and you scale it by 0.5).

You can adjust the value of ac in your code to scale the message signal to amplitudes less than 1. (You'll need a value less than 0.0001 or so)

As a secondary issue, the frequency range of the human voice is typically in the 10 - 8000 Hz range (with a more limited range needed for understandable speech), and you are modulating this signal onto a 100 Hz carrier. That will result in aliasing as the positive and negative frequency images of your AM signal overlap. Try increasing the carrier frequency to at least 10 kHz.

With a higher carrier frequency you might also have to increase your sample rate to make the plot look presentable. You'll also want to zoom the plot in on a just a few cycles of the message signal to make the AM signal appear as expected.

The Photon
  • 1,242
  • 1
  • 9
  • 12
  • Hey, I've changed the code according to what you said and added the output in my question can you please check it and give me a feedback on what do you think is happening because I still don't get what I'm expecting. – yarin Cohen Jul 10 '21 at 22:52
0

I would put this as a comment, but I do not have enought reputation.

I think @mkrieger1 got the point right!

You are using the same sampling rate for the modulating and carrier signals. The carrier signal should have a sampling frequency at least double the carrier frequency and this one should be considerable higher than the maximum expected audio frequency. However you are using a 10KHz carrier which is actually within audio band. If I am not mistaken longwave AM radio starts at 153kHz, so sampling should be done at least at 306kHz.

Jarosita
  • 31
  • 7