Transformations on Continuous Signals

Mathematica definitions

Load needed packages for this notebook

<< Graphics`Colors`;

Set up defaults

Turn off annoying warning messages

Off[General::spell];
Off[General::spell1];

Set default options for specific functions

SetOptions[Plot, Frame -> True];
SetOptions[ListPlot, Frame -> True,  PlotJoined -> True,  
        Axes -> {True, False}];
SetOptions[Fourier, 
        FourierParameters -> {1, -1}];
SetOptions[InverseFourier, 
        FourierParameters -> {1, -1}];

Visualization functions

Fix time variable for sampled signals

FixTime[signal_, 
          sampleRate_] := 
Module[{time, 
            data}, 
time = 
            Table[i/sampleRate, {i, 1, 
                Length[signal]}]; 
data  =  {time, 
                signal} // Transpose
];

Generate periodic waveform from one period

PeriodicSignal[f, {dmin, dmax}, {t, min, max}] generates a periodic waveform for the interval [min, max]. It is assumed that one period of the function f(t) is defined over the interval [dmin, dmax].

PeriodicSignal[
          f_, {dmin_, dmax_}, {t_, min_, 
            max_}] := 
Module[{T, imin, 
            imax}, 
T  =  
            dmax  -  dmin; 
imin = 
            Floor[(min - dmin)/T]; 
imax = 
            Ceiling[(max - dmax)/T];  
Sum[
            f[t - i T] (UnitStep[t - dmin - i T]  -  
                  UnitStep[t - dmax - i T]), {i, imin, 
              imax}]
];

Plot periodic waveforms

PeriodicPlot[f, {dmin, dmax}, {t, min, max}, opts] plots a a periodic waveform for the interval [min, max]. It is assumed that one period of the function f(t) is defined over the interval [dmin, dmax]. The 'opts' argument passed plotting options to the Mathematica function Plot[ ].

PeriodicPlot[f_, {dmin_, dmax_}, {t_, min_, max_}, 
          opts___] := 
Module[{fnc}, 
fnc = PeriodicSignal[f, {dmin, dmax}, {t, min, max}]; 
Plot[
            fnc, {t, min, max}, opts]
];

Plot discrete-time signal as sequence of amplitude lines

DiscreteListPlot[signal_, color_:  Black, 
          opts___] := 
Module[{data, g1, 
            g2}, 
If[
            Length[signal[[1]]]  ==  2, 
data = 
              signal, 
data = 
              FixTime[signal, 
                1]
]; 
g1 = Line[{{#[[1]], 0}, {#[[1]], #[[2]]}}] &  /@  
              data; 
g2 = {PointSize[ .015], 
                  Point[#]} &  /@  data; 
Show[
            Graphics[{color, g1, g2}], 
            opts]
];

Basic continuous signal transformations: example #1

Sample signal

x[t_] := (UnitStep[t + 2] - UnitStep[t]) (t + 2) + 
        2*(UnitStep[t] - UnitStep[t - 2])

range = {t, -5, 5};

g1 = 
        Plot[x[t], Evaluate[range],  Frame -> True, 
          PlotRange -> {- .1, 4.1},  
          PlotStyle -> {Blue, Thickness[ .01]}];

Reflection

g2 = 
        Plot[x[-t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-scaling (compression)

g2 = 
        Plot[x[2  t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-scaling (stretching)

g2 = 
        Plot[x[1/2  t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-shifting (to the right)

g2 = 
        Plot[x[t - 2],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-shifting (to the left)

g2 = 
        Plot[x[t + 2],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Amplitude scaling

g2 = 
        Plot[2  x[t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Compound transformation

g2 = 
        Plot[x[2  t - 1],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Basic continuous signal transformations: example #2

Sample signal

x1[t_] := 
        D[1/(1 + Exp[-tt]), {tt, 2}]  /.  tt -> t;
x2[t_] := 
        D[1/(1 + Exp[-tt]), {tt, 2}]  /.  tt -> t;
x[t_] := x1[t] t/3  +  x2[t] (2 - t);

range = {t, -10, 10};

g1 = 
        Plot[x[t], Evaluate[range],  Frame -> True, 
          PlotRange -> All,  
          PlotStyle -> {Blue, Thickness[ .01]}];

Reflection

g2 = 
        Plot[x[-t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-scaling (compression)

g2 = 
        Plot[x[2  t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-scaling (stretching)

g2 = 
        Plot[x[1/2  t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-shifting (to the right)

g2 = 
        Plot[x[t - 5],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Time-shifting (to the left)

g2 = 
        Plot[x[t + 5],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Amplitude scaling

g2 = 
        Plot[1/2  x[t],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];

Compound transformation

g2 = 
        Plot[x[-t + 5],  Evaluate[range],  Frame -> True, 
          Evaluate[AbsoluteOptions[g1, PlotRange][[1]]],  
          PlotStyle -> {Red, Thickness[ .01]}];