Let's express the wave function as
$$
y(t) = A cos(\phi(t) + \phi_0)
$$
where \(A\) is the wave amplitude. \(\phi(t) = 2\pi \int_0^{t} f(t') dt'\) is the time-dependent phase angle. \(f(t')\) stands for the instantaneous frequency varying with time. \(\phi_0\) means the initial phase.
From the above equation, we know that the role of \(f(t')\) is to determine how the sinusoidal waves are modulated in frequency domain.
The following code example will demonstrate waves with different frequency-modulation.
Code example
In [1]:
%load_ext autoreload
%autoreload 2
%matplotlib inline
import numpy as np
import matplotlib.pyplot as plt
from scipy import signal
# Plot settings
plt.rcParams['figure.figsize'] = (20, 5) # set default size of plots
plt.rcParams['image.interpolation'] = 'nearest'
plt.rcParams.update({'font.size': 22})
Define a function to simulate waves¶
In [2]:
def simu_waves(f, dt, amp0=1, phi0=0):
"""
Return the simulated waves.
y(t) = amp0 * cos(phi(t) + phi0),
where phi(t) = 2 * pi * \int_0^t f(t) * dt.
f: Instantaneous frequencies.
dt: Time interval.
amp0: Amplitude.
phi0: Initail phase. When it is -pi/2, sin waves are produced.
"""
phi = 2 * np.pi * np.cumsum(f) * dt
y = amp0*np.cos(phi+ phi0)
return y
Parameter settings¶
In [3]:
T = 10 # Time duration in (second)
fs = 100 # Sampling rate (Hz)
fm = 0.2 # Modulation frequency (Hz)
B = 10 # Bandwidth (Hz)
# Time array
t = np.linspace(0, T, T*fs, endpoint=False)
dt = t[1] - t[0] # time duration
Square modulation¶
In [4]:
def simu_freq_square(t, fm=1, B=1, fd=0, duty=0.5):
'''
Simulated frequencies with square modulation.
t: Time array.
fm: Modulation frequency.
fd: Doppler frequency shift.
B: Bandwidth.
'''
f = B*0.5*(signal.square(2 * np.pi * fm * t, duty=duty) + 1)
f += fd
return f
# Fequency array
f = simu_freq_square(t, fm, B, fd=0)
# Signal amplitude
A = simu_waves(f, dt, amp0=1, phi0=0)
plt.subplot(2, 1, 1)
plt.plot(t, f)
plt.ylabel('Frequency (Hz)')
plt.ylim(0, B+0.5)
plt.subplot(2, 1, 2)
plt.plot(t, A)
plt.ylabel('Signal')
plt.xlabel('Time (seconds)')
Out[4]:
Linear frequency modulation:¶
In [5]:
def simu_freq_sawtooth(t, fm=1, B=1, fd=0, width=0.5):
'''
Simulated frequencies of sawtooth modulation.
t: Time array.
fm: Modulation frequency.
fd: Doppler frequency shift.
B: Bandwidth.
'''
f = B*0.5*(signal.sawtooth(2 * np.pi * fm * t, width=width) + 1)
f += fd
return f
# Fequency array
f = simu_freq_sawtooth(t, fm, B, fd=0, width=0.5)
# Signal amplitude
A = simu_waves(f, dt, amp0=1, phi0=0)
plt.subplot(2, 1, 1)
plt.plot(t, f)
plt.ylabel('Frequency (Hz)')
plt.subplot(2, 1, 2)
plt.plot(t, A)
plt.ylabel('Signal')
plt.xlabel('Time (seconds)')
Out[5]:
comments powered by Disqus