The Stanford Computer-Music Theory Package for Mathematica (SCMTheory.m) contains functions to help visualize and manipulate signals in the time and frequency domains. In particular, many functions are provided for spectral visualization and for the handling of complex numbers. The table below lists most of the functions defined in the package. A short description of each function can be found in the source code for the package.
Amplitude CartesianForm RectForm ComplexSinusoidPlot Convolution Correlation Decimate DFTAnalyze EvenPart EvenOddPlot |
EvenOddSinusoidPlot Flip HermitianQ InnerProduct Interpolate MagnitudePhasePlot MagnitudePlot NumericIDFT NumericDFT OddPart |
ParabolaFit ParabolaPeak ParabolaFitPlot Phase PhasePlot PolarForm RealImaginaryPlot ReImPlot Repeat SampleFunction |
SeqPlot Shift ShiftToCausal ShiftToNonCausal SignalFunction Sinc Stretch SymbolicDFT SymbolicIDFT ZeroPad |
Moduolo sequences are very important with dealing with the transformation of sound signals to frequency. Suppose you have the sequence {0, 1, 3, 2, 4} which represents an infinitely repeating periodic sequence. The SCMTheory package has a set of functions to manipulate that sequence and also a special plotting function, SeqPlot[] which handles mod sequences. Standard mod sequence manipulators include: Flip, Shift, Decimate, and Interpolate. See the notebook entitled Modulo Sequences for more indepth descriptions (nb.gz, .pdf).
The following plots demonstrate uses of SeqPlot. More examples can be found in the function example notebook for SeqPlot (.nb.gz, .pdf).
The default style of SeqPlot:
SeqPlot[{0, 1, 3, 2, 4}]; |
Examining more periods of the mod sequence {0, 1, 3, 2, 4} :
|
SeqPlot can also sample continuous functions:
|
|
|
Complex numbers can be represented in two forms: (1) in rectangular or Cartesian form, and (2) in polar form. In rectangular form, a complex number has the form z = a + b i (where i = square root of -1). The real part of that number is a, and the imaginary part of that number is b. In polar form, a complex number has the form z = r exp(i θ) , where r is the absolute value, or magnitude of the number, and &theta is the angle of that number. Two functions: RectForm and PolarForm are provided in the SCMTheory package for conversion between these two equivalent forms of complex numbers:
PolarForm[1+1 I] = Sqrt[2] Exp[I Pi/4] RectForm[3 Exp[I π/2]] = 3 I
For the plots below define sequence to be:
sequence = SampleFunction[E^(-t/2) E^(I 2π t), {t, 0, 5.5, 0.1}];
Show[Graphics3D[{Map[Point,Transpose[{times, Re[sequence], Im[sequence]}]]}], ViewPoint->{1.3, -2.4, 1}]; |
|
|
|
|
|
|
Here is the signal and spectrum of a sinewave. Note that a sinewave only real. Note that real signals have symmetric spectra magnitudes (first half of the spectrum magnitude below is the mirror image of the second half). Note that the sinewave has two spectral components, (one at frequency 2, and one at frequency 8 (or -2)).
DFTAnalyze[sig, Causal->True, SpectrumOptions->{LeftOptions->{PlotRange->{{0,10},{-5,15}}}}, FrameTicks->{Automatic, {-5, 0, 5, 10, 15}, None, None} ]; |
Here is the same sinusoid, except that this time the signal is shifted three samples a head in time. Also note that the style for the magnitude plot has changed from decibels to linear units.
DFTAnalyze[sig, SpectrumOptions->{LeftOptions->{LogScale->False}} ]; |
In contrast to a real sinusoid, a complex sinusoid with the same frequency has only one frequency component. Also, with only one frequency component you can see more clearly the linear phase of the spectrum's phase (a constant slope with discontinuities when then magnitude is 0).
DFTAnalyze[sig3, SpectrumOptions->{LeftOptions->{LogScale->False}} ]; |
Here is a plot of an exponentially growing complex sinusoid shown in black. The real part of the sinusoid is shown in red at the bottom of the plot. The imaginary part of the sinusoid is shown in blue above the plot. The projection of the complex sinusoid onto the complex plane is shown at the left in green. This plot was created with the function call ComplexSinusoidPlot[0, 8, Decay->-2.8];