CS 472 Module 2: Simple Numpy Tunes Part 4

Module content developed by Professor Tralie. Module engine developed by Professor Tralie and Professor Mongan.


Please watch the video below, and be ready to be cold called on Monday to explain what chirps and beats are!

Part4

Chirps And Beat Frequencies

$y(t) = A \cos(2 \pi f(t) t + \phi)$

Ex) "Linear chirp" $f(t) = 440 + 440*t$

$y(t) = \cos(2 \pi (440 + 440t)*t)$

$y(t) = \cos(880\pi(t + t^2))$

In [1]:
import numpy as np
import matplotlib.pyplot as plt
import IPython.display as ipd
In [2]:
sr = 44100
t = np.linspace(0, 1, sr)
f = 440 + 440*t
y = np.cos(2*np.pi*f*t)
ipd.Audio(y, rate=sr)
Out[2]:
In [3]:
f1 = 5
f2 = 6
t = np.linspace(0, 4, 400*10)
y1 = np.cos(2*np.pi*f1*t)
y2 = np.cos(2*np.pi*f2*t)
y = y1 + y2
plt.figure(figsize=(10, 14))
plt.subplot(211)
plt.plot(y1)
plt.plot(y2)
plt.subplot(212)
plt.plot(y)
Out[3]:
[<matplotlib.lines.Line2D at 0x7f007fc42890>]
In [4]:
f1 = 440
f2 = 444
## Def. Beat frequency: f2 - f1
t = np.linspace(0, 2, sr*2)
y1 = np.cos(2*np.pi*f1*t)
y2 = np.cos(2*np.pi*f2*t)
y = y1 + y2
ipd.Audio(y, rate=sr)
Out[4]:
In [ ]: