2 Representing Signals and Systems
Signal processing is rich in representations for signals. Choosing an appropriate form for operating on a signal is essential to many signal processing tasks. Signals and Systems handles a variety of signal forms, including both continuous and discrete formulas. Systems that act on signals are represented in operator form.
2.1 Analog Signals
A variety of interesting types of analysis can be performed on analog signals. These signals are assumed to take on a value from a continuous range, over all time (or space). These signals are represented in traditional Mathematica notation, for instance, Sin[2 Pi t] for a sinusoidal signal.
Signals and Systems enhances Mathematica by allowing the user to employ a variety of functions common in signal processing that are not found in Mathematica proper.
Some common analog signal processing signals.
Functions such as Sinc and DirichletSinc correctly evaluate to the limit at zero, unlike a simple definition. Various rules to improve their behavior under numeric evaluation, differentiation, and integration are also implemented.
There is a general class of functions called unit singularity functions that involve discontinuities. These are actually functionals, but useful representations as functions have been devised, at least for realvalued input. UnitFunction[n][t] can be used to enter the order unit singularity function. It will automatically be rewritten in terms of the DiracDelta function (order singularity function) and the UnitStep function (order singularity function). DiracDelta and UnitStep are actually drawn from standard Mathematica functions. Signals and Systems also allows you to call these functions by ContinuousStep and ContinousImpulse, respectively.
The default definition at the discontinuities of the pulse and step functions used by Signals and Systems is that the value is 1 at the leading discontinuity and, for the ContinuousPulse function, 0 at the trailing step.
First, verify that the signal processing functions are available.
In[1]:=Needs["SignalProcessing`"]
Here we plot a signal that includes the DirichletSinc function, with an impulse at and at .
In[2]:=SignalPlot[ DirichletSinc[4, 10 omega] + DiracDelta[omega  1] + DiracDelta[omega + 1], {omega, 2, 2} ]
Out[2]=
Signals can be described by standard Mathematica functions, as well.
In[3]:=SignalPlot[ BesselJ[1, 3 t] + ContinuousPulse[0.5, t  1]/2, {t, 0, 3} ]
Out[3]=
While a signal's "time" variable is often restricted to the real domain for the purposes of Signals and Systems (for instance, when creating plots), the entire expression representing the signal may take on complex values. An example of this can be found in the result of transforms such as the Fourier transform.
A complexvalued function is displayed. The real part is represented by the solid line, while the dashed line is the complex part.
In[4]:=SignalPlot[ FourierTransform[Sinc[t]^2 + DiracDelta[t + 1]  DiracDelta[t  1], t, w], {w, 3, 3} ]
Out[4]=
Many functions in Signals and Systems can also handle multidimensional signals. Functions with multidimensional equivalents are called by placing the variables in a list in the case of transform functions, or by giving the additional dimensions as extra arguments, for instance, in .
Here is a twodimensional signal with Gaussian characteristics in the upperright quadrant.
In[5]:=SignalPlot3D[ Exp[(x1^2 + x2^2)] UnitStep[x1, x2], {x1, 1, 2}, {x2, 1, 2} ]
Out[5]=
The unit singularity functions are represented in terms of Dirac delta functions (for singularity functions of nonnegative order) and the unit step function (for singularity functions of negative order). These are particularly useful in representing continuous transforms of polynomials. Powers of these functions will automatically simplify to the function itself when appropriate.
Here is a list of the representations for some unit singularity functions.
In[6]:=Table[UnitFunction[n][t], {n, 2, 2}]
Out[6]=
Piecewise Representations
Representation for piecewisecontinuous function.
Piecewisecontinuous signals can also be specified, and many Signals and Systems functions can operate on signals given in this form. A piecewise function is given as a list of elements, each of the form where min and max give the range over which the signal takes the value given by fun. This list is wrapped in a data type called ContinuousPiecewiseData, allowing the independent variable to be tracked. The full syntax is thus ContinuousPiecewiseData[list, var]. Multidimensional signals are not supported with this notation.
Here is a plot of a function defined in piecewise form. Note that the function may be complex, that it takes the value zero where a segment is not defined, and that a segment may range to Infinity (or from Infinity).
In[7]:=SignalPlot[ ContinuousPiecewiseData[ {{Sqrt[x], 5, 3}, {Sin[x], 1.5, 2}, {BesselJ[2, x], 2, Infinity}}, x ], {x, 4, 4} ]
Out[7]=
Converting to and from the continuous piecewise data type.
ContinuousPiecewiseData effectively represents a sum of functions multiplied by ContinuousPulse functions. As a result, at the boundary of two pieces, the piecewise data type takes the value of the second piece (recall that the leading discontinuity of the ContinuousPulse is defined as , while the trailing edge is defined as ). You can convert between these representations with the functions ToContinuousPiecewiseData[expr, var] and Normal[expr] (the sumofpulses form is the canonical representation).
Here we convert a function from step form to piecewise form.
In[8]:=ToContinuousPiecewiseData[ a t^2 ContinuousPulse[4, t] + UnitStep[t  2], t ]
Out[8]=
The function is converted back into segments determined by the piecewise data structure, not the original step form.
In[9]:=Normal[%]
Out[9]=
The DeltaArea representation.
A Dirac delta function is an odd beast with infinite value at a point, but finite area under the curve. To retain the information about the area under a delta function, the DeltaArea object is introduced. It is used inside the piecewise representation for any function involving Dirac deltas.
Here is the representation for a function involving Dirac delta functions.
In[10]:=ToContinuousPiecewiseData[ 7 DiracDelta[t] + 3 DiracDelta[t + 3] + Sin[t], t ]
Out[10]=
2.2 Discrete Signals
A discrete signal is a signal defined only for integer values of the independent variable(s). Several representations, including explicit sequences of values, formulas, and piecewise formulas are available for use in Signals and Systems. Note that a discrete signal is differentiated from a digital signal in that the dependent variable can take on a continuous range of values, while for a digital signal, the dependent variable must also be discrete. Digital signals are thus a subset of discrete signals, and both are handled identically by Signals and Systems.
Signals as Discrete Data
Data object for discrete data in vector form.
In Mathematica we can represent an explicit sequence of data values as a list of numbers, using the form . For signals, information about the independent variable and the support is also required. We handle this by placing the list in a special data type called SampledData. We can display signals of this form very conveniently.
This is an arbitrary sequence of numbers representing a signal.
In[11]:=DiscreteSignalPlot[SampledData[ {0.1, 0.2, 0.4, 0.8, 0.3, 0.2, 0.4, 0, 0.1, 0.1, 0.3, 0.45, 0.1}, n], {n, 0, 12}]
Out[11]=
As is common in signal processing, we assume that the first item in the list corresponds to a value of for the independent variable when plotting or computing with sequences in Signals and Systems. Note that this is contrary to standard Mathematica usage where the first element in a list is given the index . You should take care to distinguish between structural manipulations on lists of numbers and computations with a signal expressed as sampled data.
Sequences of data most often correspond to sampled signals, possibly read from a file.
First we read in a data file of a digitized audio signal.
In[12]:=snd = ReadList[ToFileName[{"SignalProcessing", "Documentation", "English"},"snd1.dat"], Number];
We now display the first 5000 samples of the signal.
In[13]:=DiscreteSignalPlot[ SampledData[snd, t], {t, 0, 4999}, Frame > True ]
Out[13]=
Multidimensional data are represented on an array, with the values of the independent variables represented by the locations in the array. Several graphical representations can be made of multidimensional discrete data, including density plots and surfaces where the intersections of the polygons making up the surface correspond to the data points.
A multidimensional discrete data set can be displayed in a density plot by DiscreteSignalDensityPlot. The coloring is that used by DensityGraphics, which by default displays the smallest value in black and the largest in white.
In[14]:=DiscreteSignalDensityPlot[ SampledData[ {{1,2,3}, {2,1,4}, {6,3,1}}, {u, v} ], {u, 1, 3}, {v, 1, 3} ]
Out[14]=
Creating a SampledData object from a function.
It is often useful to work with discrete data generated from a function, rather than working with the function itself (as described in the next section). The function ToSampledData can be used to create the data object. It will make the object out of integer values of a variable between a specified starting value and endpoint.
Here is a continuous signal.
In[15]:=SignalPlot[ Sin[x] + ContinuousPulse[0.4 x], {x, 0, 8} ]
Out[15]=
We have created a SampledData object from the formula.
In[16]:=dat = N[ToSampledData[ Sin[x] + ContinuousPulse[0.4 x], {x, 0, 8} ]]
Out[16]=
This is a plot of the constructed data object.
In[17]:=DiscreteSignalPlot[ dat, {x, 0, 10} ]
Out[17]=
Signals in Formulas
Representation of a sequence in the form of a formula greatly expands the scope of signals that can be expressed. For instance, signals of infinite extent are easily manipulated as formulas.
Some useful discrete signals.
As with analog signals, several functions are provided for representation of discrete signals in the form of formulas. The DiscreteDelta can also be called DiscreteImpulse, to parallel the analog ContinuousImpulse.
Here is a discrete signal superposing a step and two impulses.
In[18]:=DiscreteSignalPlot[DiscreteStep[n  1] + DiscreteDelta[n  2]  2.5 DiscreteDelta[n  4], {n, 0, 8}]
Out[18]=
Signal generated as a result of signal processing operations.
Some signal processing operations result in signals that do not have a convenient closedform representation in terms of traditional functions. It is useful to have an object representing this sort of signal. The UpsampledLattice function is one such signal, representing a discrete signal that has been upsampled by the insertion of instances of some value in between each sample. Note that the function fun in the specification is one that has already been transformed by an upsampling operation, not the function before upsampling.
Multidimensional upsampling is also represented by UpsampledLattice, where m is a resampling matrix, and n is a vector of variables. Then where falls on the integer lattice, it takes on the value of the function at . UpsampledLattice takes on zero for all other points on the integer lattice.
This is a sinusoidal signal that has been upsampled by a factor of three, with zeros inserted.
In[19]:=DiscreteSignalPlot[ UpsampledLattice[3, 0, Sin[n/10], n], {n, 0, 30} ]
Out[19]=
Piecewise Signals
Representation for a piecewisedefined discrete function.
As with continuous signals, discrete signals can also be described in a piecewise form. The basic syntax is identical (with the exchange of DiscretePiecewiseData for ContinuousPiecewiseData), but simplified by nonoverlapping integer endpoints for the intervals.
Here is a plot of a discrete signal with a parabolic, a constant, and a linear segment. Note that the signal takes the value zero outside of the defined intervals.
In[20]:=DiscreteSignalPlot[ DiscretePiecewiseData[ {{t^2, 2, 5}, {2, 6, 8}, {t, 9, 10}}, t ], {t, 0, 10} ]
Out[20]=
Conversion to and from the piecewise data type.
Here is a discrete signal written as a formula converted to piecewise form.
In[21]:=ToDiscretePiecewiseData[ 2 t DiscretePulse[4, t  2] + Exp[t] UnitStep[t  8], t ]
Out[21]=
We can convert it back into a formula.
In[22]:=Normal[%]
Out[22]=
2.3 Windows
Windows are special signals of finite extent designed for modifying other signals to enhance various forms of analysis, such as spectral analysis. Signals and Systems provides a variety of continuous and discrete windows that can be incorporated into your computations. Of course, you can easily define a window as any weighting function multiplied by a pulse, but the window objects specified here have the additional advantage of allowing the functions to retain their identities as windows, which can assist you in understanding the computations later.
Specifications of windows.
These window objects can be manipulated much as you would any other signal.
A window can be plotted. Here we have a triangular window.
In[23]:=SignalPlot[ ContinuousWindow[Triangular, 4.5, t], {t, 2, 6} ]
Out[23]=
Here is a discrete window. Note that some window types have parameters controlling their shape. This parameterized Hanning window corresponds to the usual nonparametric definition when the parameter's value
is .
In[24]:=DiscreteSignalPlot[ DiscreteWindow[Hanning[1/2], 10, t], {t, 1, 11} ]
Out[24]=
Some window types implemented in Signals and Systems.
Some windows are implemented in terms of other windows, or are special cases of other windows.
In[25]:=ContinuousWindow[Blackman, 30, t]
Out[25]=
The formula for each window can be found by application of Normal.
In[26]:=Normal[%]
Out[26]=
Representations of transforms of discrete windows for frequency analysis.
Closed forms for the transforms of many types of windows are well known. The routines allow abstract specification of the discrete and discretetime Fourier transforms of discrete windows for manipulation of convolution and transform operations, for instance, as well as easy analysis of the windows themselves.
The rectangular window has particularly high sidelobes. These more than offset the ease of computation with this window in many applications.
In[27]:=MagnitudePhasePlot[ DiscreteTimeFourierWindow[ Rectangular, 22, w ], {w, 0, 2 Pi}, PlotPoints > 100 ];
Here is the frequency response of a triangular window, which has noticeably better sidelobe characteristics.
In[28]:=MagnitudePhasePlot[ DiscreteTimeFourierWindow[ Triangular, 22, w ], {w, 0, 2 Pi}, PlotPoints > 100 ];
2.4 Systems as Operators
A system essentially transforms one signal into another. Strictly speaking, standard mathematical functions such as those described in previous sections are systems, but it is convenient to think of functions as describing an initial signal. Systems can be manipulated as parameterized transformations, and can in principle be rewritten in useful ways that represent different hardware implementations.
We can take this behavior and implement it in Mathematica using an operator notation, in which the parameterized system description is written as a head that takes the signal (or in some cases, signals) as the argument, as in system[, , ... ][signal].
This represents a system that downsamples by , acting on a periodic signal.
In[29]:=Downsample[2, n][ Cos[Pi n/10] ]
Out[29]=
The EvaluateOperators function.
To find the output generated by passing the signal through the system, we apply the EvaluateOperators function.
In[30]:=EvaluateOperators[%]
Out[30]=
Note that the standard operator syntax in Signals and Systems is nonevaluating. This means that a system description is established in a form that allows easy cascading of operators. It also makes system rewriting to perform design tasks convenient. To evaluate a system applied to a signal, use EvaluateOperators to force the response of the systems to be generated. If you wish to immediately evaluate the system, you can usually use a functional form, where the signal becomes the first argument of the system description.
A system applied to a signal in functional form immediately returns the output signal.
In[31]:=Downsample[Cos[Pi n/10], 2, n]
Out[31]=
Signals and Systems provides many common signal processing operators. Some operators, because of equivalent definitions, can be used equally well on continuous or discrete signals. Other operators process only one of these types of signals.
Signal processing operators that act on both continuous and discrete signals.
The Shift operator is equivalent to adding an offset to the independent variable in the signal. ReverseSignal is equivalent to inverting the sense of the independent variable (multiplying it by ). The Periodic operator is generally applied to signals of limited duration, as it is formed of an infinite summation. These summations will often not converge for infinite signals. You can use these operators in multidimensional form by giving the parameters as lists (except for the period, which can be either a list or a matrix), where the list has a number of elements equivalent to the dimensionality of the operator.
This represents a triangular pulse.
In[32]:=tri = t ContinuousPulse[0.5, t] + (1  t) ContinuousPulse[0.5, t  0.5]
Out[32]=
Here is what the pulse looks like.
In[33]:=SignalPlot[tri, {t, 0, 2}]
Out[33]=
We can make the pulse periodic, with a period of 0.8. Note the effects of aliasing.
In[34]:=SignalPlot[Periodic[0.8, t][tri], {t, 0, 6}]
Out[34]=
Applying EvaluateOperators creates the signal resulting from the application of the operators, which consists of shifting and reversing the signal in this example.
In[35]:=EvaluateOperators[ ReverseSignal[t][Shift[4, t][t^2]] ]
Out[35]=
Signal processing operators for continuous signals.
RotateSignal is used with multidimensional signals. It rotates the signal in the plane corresponding to the two variables. The rotation occurs around the origin. The angle of the rotation is in the direction given by rotating from the axis specified by the second variable toward the first. The ScaleSignal operator effectively multiplies the specified variable by a constant factor. Both ScaleSignal and AliasSignal can also be used in multidimensional form.
This is a Gaussian curve that has been scaled and rotated.
In[36]:=SignalPlot3D[ RotateSignal[Pi/4, {x, y}][ ScaleSignal[3, y][ Exp[(x^2 + y^2)] ] ], {x, 2, 2}, {y, 2, 2}, PlotPoints > 25 ]
Out[36]=
AliasSignal is always rewritten in terms of the Periodic operator. It is shorthand for the aliasing of a signal representing a continuous frequency spectrum.
Signal processing operators that act on discrete signals.
The upsampling and downsampling functions operate on discrete signals. When the signal is multidimensional, the sampling factor should be an integer sampling matrix, and the variable should be replaced by a list of variables.
This is an example of how downsampling can cause aliasing problems. Information that the signal is sinusoidal has been lost.
In[37]:=DiscreteSignalPlot[ Downsample[4, n][Sin[Pi/2 n]], {n, 0, 8} ]
Out[37]=
CircularShift acts as a ring buffer of given length with a specified rotation value, so each sample at position is shifted by the formula Mod[n  value, length].
Here is a ramp that has had a circular shift applied to it.
In[38]:=DiscreteSignalPlot[ CircularShift[2, 6, n][n], {n, 0, 9}, Frame > True ]
Out[38]=
Here is the thirdorder backward difference of the signal Sin[n].
In[39]:=EvaluateOperators[Difference[3, n][Sin[n]]]
Out[39]=
The Interleave operator is unique in that it acts on multiple signals, multiplexing them by effectively taking one sample from each input signal in sequence. (This is performed algebraically, so the signals can be arbitrary discrete formulas.) The output may contain UpsampledLattice objects, since the general procedure is to upsample each signal by the total number of signals, shift each successive signal by its position in the sequence, and add together the resulting signals.
Interleave the two periodic signals. Note that the result is in terms of UpsampledLattice objects.
In[40]:=EvaluateOperators[ Interleave[n][Sin[n], Cos[n]] ]
Out[40]=
The various filter objects and transforms (Laplace, Fourier, Z, etc.) defined in Signals and Systems also have operator forms. These are documented further in Chapters 4 and 5.
Operatorlike objects in Signals and Systems.
Signals and Systems contains some other common operatorlike objects, though they do not have the same behavior as the preceding operators. It is useful for various signal representation and signal processing tasks to keep a summation in an unevaluated form. The operator Summation[index, min, max] represents the summation of a signal incrementing index from min to max. It does not transform a signal variable the way other operator functions do, but is instead a compact notation for a complicated signal expression.
Here is a summation, perhaps representing the frequency response of a filter. Note that if this were written with Sum, it would immediately evaluate because of the exact numeric limits.
In[41]:=expr = Summation[m, 1, 3][a[m] Exp[I d[m] w]]
Out[41]=
This is the evaluated summation. The result is not a signal in m, as it would be with other operators in Signals and Systems.
In[42]:=EvaluateOperators[expr]
Out[42]=
Representations of polyphase operations.
Signals and Systems also has the capability to represent polyphase operations, although at this time they are nonevaluating. Currently, these representations are solely for use when exporting to Ptolemy (see Section for more information). These polyphase systems use an operator syntax in the expectation that they will be evaluating in a future version of the routines.
2.5 Modified Standard Functions
The behavior of several standard functions has been modified somewhat for Signals and Systems. For the most part, these are extensions to existing functions so that they may operate properly on objects introduced in the application. However, a few other functions were adjusted to use assumptions common to signal processing and related fields.
Both Det and Dot have been extended to work with scalars. This is because of the parallels between onedimensional and multidimensional resampling operations.
For typical signals and systems manipulations in the continuous domain, we can make an assumption of analaticity. To improve this behavior, the Analytic option of Limit has been set to True by default, as opposed to the usual False value.
Calculus functions such as Integrate, Derivative, and Limit have been extended to cover many of the new functions introduced in Signals and Systems.
In Mathematica Version 4, the standard LaplaceTransform, FourierTransform, and ZTransform functions and their inverses have been overridden by the Signals and Systems versions. You can access the standard system versions via System`LaplaceTransform, etc.
In Mathematica Version 4, UnitStep and DiracDelta are system functions. Signals and Systems removes the Listable attribute from these functions for backward compatibility with earlier versions of Signals and Systems.
Improved TeX formatting has been added to several standard operators, such as Re and Im.
