In [1]:
%pylab inline


Populating the interactive namespace from numpy and matplotlib

In [2]:
from ipywidgets import interact, interactive
from IPython.display import clear_output, display, HTML

from scipy import integrate

from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
from matplotlib.colors import cnames
from matplotlib import animation

In [3]:
import sys

Discrete sinusoids

A discrete sinusoid is a cosine or sine function evaluated at discrete values of its argument. The following is a general expression for a discrete sinusoid, $$ x[n] = A \cos \left(\omega_0 n + \phi \right) $$ Where, $n \in \mathbb{Z}$ presents the time instant, $A$ is the amplitude of the signal, $\omega_0$ is the frequency of the sinusoid, and $\phi$ is the phase.

Unlike its continuous time counterpart, the discrete sinusoid has a peculiar property. The frequency of a discrete sinusoid is restricted to values within a continuous finite interval of width $2\pi$, typically it is chosen to be $[0, \pi)$. Algebraically one can demonstrate that when one chooses $\omega_0$ to be greater than $\pi$, the expression reduces to a sinusoid with frequency within the internval $[0, \pi)$.

The following interactive visualization demonstrates this property.


In [4]:
def plot_discrete_sinusoid(A, w0, phi):
    n = np.arange(-10, 10, 1.0)
    t = np.arange(-10, 10, 0.01)
    x = A * np.cos(w0 * n + phi)
    xc = A * np.cos(w0 * t + phi)
    fig = plt.figure(figsize=(15, 4))
    plot(t, xc, color=(1, 0.85, 0.85), ls='-')
    stem(n, x)
    gca().axis('off')
    gca().set_ylim((-1.1 * A, 1.1 * A))
    gca().set_title("Frequency: ${0:1.3}\pi$".format(w0), fontsize=20)
    plt.show()

In [5]:
interactive(plot_discrete_sinusoid, A=(0.5, 2.0), w0=(0, 1 * np.pi, 0.01), phi=(-np.pi, np.pi))