[ Log On ]
  • Home
  • Tst
  • Cha
  • Enc
  • Code
  • IP
  • Fun
  • Sub
  • DigF
  • Cis
  • Com
  • Db
  • About
  • Netsim

AM and FM

 

[Back] This page shows different modulation methods (AM and FM). A page which outlines a range of waverforms is here.

Modulation types

Select a type:

[AM:] [FM:]

Options

Carrier Frequency (Hz):
Signal Frequency (Hz):
m (0-1):

m level goes from 0 (minimum) to 1 (maximum)

Try an example

  • AM, Carrier Freq=5Hz, m=0.5. Calc
  • AM, Carrier Freq=10Hz, Signal=1Hz m=0.5. Calc
  • FM, Carrier Freq=10Hz,Signal Freq=5Hz, m=0.5. Calc

View image [SVG] View image [PNG]

Source code

The following outlines the Python code used:

import matplotlib.pyplot as plot
import numpy as np
import sys
from scipy import signal

file ='1111'
m=0.2
type='am'
freq=10
freqs=2

if (len(sys.argv)>1):
        file=str(sys.argv[1])

if (len(sys.argv)>2):
        m=float(sys.argv[2])

if (len(sys.argv)>3):
        type=(sys.argv[3])

if (len(sys.argv)>4):
        freq=int(sys.argv[4])

if (len(sys.argv)>5):
        freqs=int(sys.argv[5])


Fs = 150.0;  # sampling rate
Ts = 1.0/Fs; # sampling interval

t = np.arange(0,2,Ts)

if (type=='fm'):
	y= np.sin(2 * np.pi * freq * t + m*np.sin(2 * np.pi * freqs * t))
else:
	y= (1+m*np.sin(2 * np.pi * freqs * t))* np.sin(2 * np.pi * freq * t)

n = len(y) # length of the signal
k = np.arange(n)
T = n/Fs
frq = k/T # two sides frequency range
frq = frq[range(n/2)] # one side frequency range
Y = np.fft.fft(y)/n # fft computing and normalization
Y = Y[range(n/2)]

fig,myplot = plot.subplots(2, 1)
myplot[0].plot(t,y)
myplot[0].set_xlabel('Time')
myplot[0].set_ylabel('Amplitude')

myplot[1].plot(frq,abs(Y),'r') # plotting the spectrum
myplot[1].set_xlabel('Freq (Hz)')
myplot[1].set_ylabel('|Y(freq)|')

plot.savefig(file)
plot.show()