signal

“msharpmath”, The Simple is the Best

[100] 014 Tutorial signal            ‘signal’

//———————————————————————————————————————
//  signal     for Digital Signal Processing
//———————————————————————————————————————

// signal

// may look like  n x 2 matrix
// the first column for time
// the second column for signal

//———————————————-
//  Syntax
//———————————————-
signal [ n = a:b,  functions of n ]
signal [ n = a:b ] ( functions of  n )
n = a:b ; signal [n] ( functions of n )

//———————————————-
//  Spokes
//———————————————-
.plot
.real
.imag
.abs
.even  // even signal
.odd   // odd signal
.fold  // folding
.copy(num)
.shift(k)

.len
.tmin
.tmax
.sum
.prod
.energy
.power

//———————————————-
//  behavior of signal
//———————————————-
#> tau = -2 : 1 ;
tau =  [            -2            -1             0             1 ]

#> X = signal [ tau, tau.*tau+1 ] ;
X = ‘signal’
[            -2             5 ]
[            -1             2 ]
[             0             1 ]
[             1             2 ]
// signal is shown not ‘matrix’

#> X.fold ;
ans = ‘signal’
[            -1             2 ]
[            -0             1 ]
[             1             2 ]
[             2             5 ]

#> X + 100 ;  // only the second column is changed
ans = ‘signal’
[            -2           105 ]
[            -1           102 ]
[             0           101 ]
[             1           102 ]

#> signal[ 1:2, 1:2 ] + signal [ 5:7, 5:7 ] ;
ans = ‘signal’
[             1             1 ]
[             2             2 ]
[             3             0 ]
[             4             0 ]
[             5             5 ]
[             6             6 ]
[             7             7 ]

//———————————————-
examples shown below are from
Digital Signal Processing using MATLAB
Vinay K. Ingle, John G. Proakis
2nd ed., Thomson (2007)
//———————————————-

%> dirac delta function,  d(n-a)

#> signal [ t = -5:5 ] ( 2*d(t+2)-d(t-4) ).plot;

%> unit step function u(n-a), example 2.1(b)
#> tau = 0:20 ;
#> X = tau * signal[tau]( u(tau)-u(tau-10) ) + 10*exp(-0.3*(tau-10)) *signal[tau] ( u(tau-10) -u(tau-20) );
X = ‘signal’
[             0             0 ]
[             1             1 ]
[             2             2 ]
[             3             3 ]
[             4             4 ]
[             5             5 ]
[             6             6 ]
[             7             7 ]
[             8             8 ]
[             9             9 ]
[            10            10 ]
[            11       7.40818 ]
[            12       5.48812 ]
[            13        4.0657 ]
[            14       3.01194 ]
[            15        2.2313 ]
[            16       1.65299 ]
[            17       1.22456 ]
[            18       0.90718 ]
[            19      0.672055 ]
[            20             0 ]

#> X.plot ;


%> periodic function, example 2.1(d)
#> tau = -10 : -6 ;
#> signal [ tau, 5:1 ] .copy(4) .plot ;

#> X = signal [ tau = -2 : 10, [ 1:7, 6:1 ] ];
#> ( 2*X(tau-5) – 3*X(tau+4) ) .plot ;  // example 2.2(a)


#> ( X(3-tau) + X(tau)*X(tau-2) ) .plot ;  // example 2.2(b)


#> X(3-tau) + X(tau)*X(tau-2) ;
ans = ‘signal’
[            -7             1 ]
[            -6             2 ]
[            -5             3 ]
[            -4             4 ]
[            -3             5 ]
[            -2             6 ]
[            -1             7 ]
[             0             9 ]
[             1            13 ]
[             2            19 ]
[             3            27 ]
[             4            37 ]
[             5            37 ]
[             6            35 ]
[             7            24 ]
[             8            15 ]
[             9             8 ]
[            10             3 ]
[            11             0 ]
[            12             0 ]

#> tau = -10 : 10 ;
#> X = signal [ tau, exp( (-0.1+0.3!)*tau ) ];

X = ‘signal’
[        -10                     -2.691 - i 0.3836      ]
[         -9                     -2.224 - i 1.051       ]
[         -8                     -1.641 - i 1.503       ]
[         -7                     -1.017 - i 1.738       ]
[         -6                     -0.414 - i 1.774       ]
[         -5                     0.1166 - i 1.645       ]
[         -4                     0.5406 - i 1.39        ]
[         -3                     0.8391 - i 1.057       ]
[         -2                      1.008 - i 0.6897      ]
[         -1                      1.056 - i 0.3266      ]
[          0                          1                 ]
[          1                     0.8644 + i 0.2674      ]
[          2                     0.6757 + i 0.4623      ]
[          3                     0.4605 + i 0.5803      ]
[          4                     0.2429 + i 0.6248      ]
[          5                     0.0429 + i 0.605       ]
[          6                    -0.1247 + i 0.5345      ]
[          7                    -0.2507 + i 0.4287      ]
[          8                    -0.3313 + i 0.3035      ]
[          9                    -0.3676 + i 0.1738      ]
[         10                    -0.3642 + i 0.05192     ]

#> X.real.plot ;


#> X.imag.plot ;


#> X.abs.plot ;


#> X.angle.plot ;

//———————————————————-
//  even and odd signal
//———————————————————-
// xe = 0.5 (x(n)+x(-n))
// xo = 0.5 (x(n)-x(-n))

// example 2.3

#> tau = 0:10 ;
#> X = signal [tau] ( u(tau) – u(tau-10) );

X = ‘signal’
[             0             1 ]
[             1             1 ]
[             2             1 ]
[             3             1 ]
[             4             1 ]
[             5             1 ]
[             6             1 ]
[             7             1 ]
[             8             1 ]
[             9             1 ]
[            10             0 ]

#> X.plot ;


#> X.even.plot ;


#> X.odd.plot ;


#>X.energy ;
ans =              10

#> X.power ;
ans =      0.90909091

Comments are closed.