0% found this document useful (0 votes)
82 views

Pengolahan Sinyal Digital: Adhi Harmoko Saputro

Here is a MATLAB function to generate the unit sample (impulse) sequence: function x = unit_sample(n, no, n1, n2) x = zeros(1,n2-n1+1); x(no-n1+1) = 1; end To generate the sequence from n1=0 to n2=10 with no=5: n1 = 0; n2 = 10; no = 5; x = unit_sample(n1:n2, no, n1, n2); This creates a vector x of zeros with a 1 at the index corresponding to no.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
82 views

Pengolahan Sinyal Digital: Adhi Harmoko Saputro

Here is a MATLAB function to generate the unit sample (impulse) sequence: function x = unit_sample(n, no, n1, n2) x = zeros(1,n2-n1+1); x(no-n1+1) = 1; end To generate the sequence from n1=0 to n2=10 with no=5: n1 = 0; n2 = 10; no = 5; x = unit_sample(n1:n2, no, n1, n2); This creates a vector x of zeros with a 1 at the index corresponding to no.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 56

1

Pengolahan Sinyal Digital


Adhi Harmoko Saputro

DSP - Fisika UI
2

Sampling of Continuous-Time Signals


Adhi Harmoko Saputro

DSP - Fisika UI
3

Signal Types
• Analog signals: continuous in time and amplitude
• Example: voltage, current, temperature,…
• Digital signals: discrete both in time and amplitude
• Example: attendance of this class, digitizes analog signals,…
• Discrete-time signal: discrete in time, continuous in amplitude
• Example: hourly change of temperature in Jakarta

DSP - Fisika UI
4

Signal Types
• Theory for digital signals would be too complicated
• Requires inclusion of nonlinearities into theory
• Theory is based on discrete-time continuous-amplitude signals
• Most convenient to develop theory
• Good enough approximation to practice with some care
• In practice we mostly process digital signals on processors
• Need to take into account finite precision effects
• Our text book is about the theory hence its title
• Discrete-Time Signal Processing

DSP - Fisika UI
5

Periodic (Uniform) Sampling


• Sampling is a continuous to discrete-time conversion

-3 -2 -1 0 1 2 3 4

• Most common sampling is periodic

x [ n ] xc ( nT ) −∞ < n < ∞
=

• T is the sampling period in second


• fs = 1/T is the sampling frequency in Hz

DSP - Fisika UI
6

Periodic (Uniform) Sampling


• Sampling frequency in radian-per-second Ωs=2πfs rad/sec
• Use [.] for discrete-time and (.) for continuous time signals
• This is the ideal case not the practical but close enough
• In practice it is implement with an analog-to-digital converters
• We get digital signals that are quantized in amplitude and time

DSP - Fisika UI
7

Periodic Sampling
• Sampling is, in general, not reversible
• Given a sampled signal one could fit infinite continuous signals through the
samples

0.5

-0.5

-1
0 20 40 60 80 100

DSP - Fisika UI
8

Periodic Sampling
• Fundamental issue in digital signal processing
• If we loose information during sampling we cannot recover it
• Under certain conditions an analog signal can be sampled without loss so that it
can be reconstructed perfectly

0.5

-0.5

-1
0 20 40 60 80 100

DSP - Fisika UI
9

Representation of Sampling
• Mathematically convenient to represent in two stages
• Impulse train modulator
• Conversion of impulse train to a sequence

s(t)
Convert impulse
train to
xc(t) x discrete-time x[n]=xc(nT)
sequence

xc(t)
s(t) x[n]

t n
-3T-2T -T 0 T 2T 3T 4T -3 -2 -1 0 1 2 3 4

DSP - Fisika UI
10

Discrete-Time Signals and Systems


Adhi Harmoko Saputro

DSP - Fisika UI
11

Discrete-Time Signals: Sequences


• Discrete-time signals are represented by sequence of numbers
• The nth number in the sequence is represented with x[n]

x[n]
= x[n]} { , x [ −1] , x [ 0] , x [1] ,}
{=
• Often times sequences are obtained by sampling of continuous-time signals
• In this case x[n] is value of the analog signal at xc(nT)
• Where T is the sampling period

DSP - Fisika UI
12

Discrete-Time Signals: Sequences


10

-10
0 20 40 60 80 100 t (ms)
10

-10
0 10 20 30 40 50 n (samples)

DSP - Fisika UI
13

Discrete-Time Signals: Sequences


• In MATLAB we can represent a finite-duration sequence by a row vector of
appropriate values
• A vector does not have any information about sample position n.
• A correct representation of x(n) would require two vectors, one each for x and n.

[ n]
x= {2,1, −1,0,1, 4,3,7}

• represented in MATLAB

>> n=[-3,-2,-1,0,1,2,3,4]; x=[2,1,-1,0,1,4,3,7];

DSP - Fisika UI
14

Basic Sequences and Operations


• Delaying (Shifting) a sequence 1.5

y[=
n] x[n − no ] 1

0.5
• Unit sample (impulse) sequence
0
-10 -5 0 5 10
0 n ≠ 0 1.5
δ [ n] = 
1 n = 0 1

• Unit step sequence 0.5

0
0 n < 0 -10 -5 0 5 10
u[n] =  1

1 n ≥ 0
• Exponential sequences 0.5

0
x[n] = Aα n -10 -5 0 5 10

DSP - Fisika UI
15

Sinusoidal Sequences
• Important class of sequences
= x [ n ] cos (ωo n + ϕ )
• An exponential sequence with complex
= e jωo and A
α α= A e jϕ

[ n] A= α e= A α e j (ω n +ϕ )
jϕ n jωo n n
x= α n
Ae o

x [ n] A α cos (ωo n + ϕ ) + j A α sin (ωo n + ϕ )


n n
=

• x[n] is a sum of weighted sinusoids

DSP - Fisika UI
16

Sinusoidal Sequences
• Different from continuous-time, discrete-time sinusoids
• Have ambiguity of 2πk in frequency
cos ( (ωo + 2π k ) n +=
ϕ ) cos (ωo n + ϕ )
• Are not necessary periodic with 2π/ωo

2π k
cos (ωo n +=
ϕ ) cos (ωo n + ωo N + ϕ ) only if
= N is an integer
ωo

DSP - Fisika UI
17

MATLAB Example 1
• Create sequence
0 n ≠ 0
δ [n − no ] =

1 n = 0
• over the 0 ≤ n ≤ 10 interval, with no = 5

n0 = 5;
n1 = 0;
n2 = 10;
n = n1:n2;
x = (n-n0) == 0; stem(n, x);

DSP - Fisika UI
18

MATLAB Example 1_1


• Create a function for following sequence
0 n ≠ 0
δ [n − no ] =

1 n = 0
• over the n1 ≤ n0 ≤ n2 interval
function [x,n] = impseq(n0,n1,n2)
% Generates x(n) = delta(n-n0); n1 <= n <= n2
% ----------------------------------------------
% [x,n] = impseq(n0,n1,n2)
%
n = n1:n2; x = (n-n0) == 0;

n0 = 5;
n1 = 0;
n2 = 10;
[x,n] = impseq(n0,n1,n2); stem(n, x);

DSP - Fisika UI
19

MATLAB Example 2
• Create sequence
0 n < 0
u[n − no ] =

1 n ≥ 0
• over the 0 ≤ n ≤ 10 interval, with no = 5

n0 = 5;
n1 = 0;
n2 = 10;

n = n1:n2; x = (n-n0) >= 0;


stem(n, x);

DSP - Fisika UI
20

MATLAB Example 2_1


• Create a function for following sequence
0 n < 0
u[n − no ] =

1 n ≥ 0
• over the n1 ≤ n0 ≤ n2 interval
function [x,n] = stepseq(n0,n1,n2)
% Generates x(n) = u(n-n0); n1 <= n <= n2
% ------------------------------------------
% [x,n] = stepseq(n0,n1,n2)
%
n = n1:n2; x = (n-n0) >= 0;

n0 = 5;
n1 = 0;
n2 = 10;
[x,n] = stepseq(n0,n1,n2); stem(n, x);
DSP - Fisika UI
21

MATLAB Example 3
• Create sequence
x [ n ] = ( 0.9 )
n

• over the 0 ≤ n ≤ 10 interval

n = 0:10;
x = (0.9).^n;

stem(n,x);

DSP - Fisika UI
22

MATLAB Example 4
• Create sequence

x [ n ] = exp ( 2 + j 3) n 

• over the 0 ≤ n ≤ 10 interval

n = 0:10;
x = exp((2+3j)*n);

subplot(211); stem(n,imag(x));
subplot(212); stem(n,real(x));

DSP - Fisika UI
23

MATLAB Example 5
• Create sequence

x [ n ] 3cos ( 0.1π n + π / 3) + 2sin ( 0.5π n )


=

• over the 0 ≤ n ≤ 10 interval

n = 0:10;
x = 3*cos(0.1*pi*n+pi/3)+2*sin(0.5*pi*n);

stem(n,x);

DSP - Fisika UI
24

Operations on Sequences
• Signal addition: { x [ n]} + { x [ n]} ={ x [ n] + x [ n]}
1 2 1 2

function [y,n] = sigadd(x1,n1,x2,n2)


% implements y(n) = x1(n)+x2(n)
% -----------------------------
% [y,n] = sigadd(x1,n1,x2,n2)
% y = sum sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
%
n = min(min(n1),min(n2)):max(max(n1),max(n2));
% duration of y(n)
y1 = zeros(1,length(n)); y2 = y1;
% initialization
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
% x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
% x2 with duration of y
y = y1+y2; % sequence addition
DSP - Fisika UI
25

Operations on Sequences
• Signal multiplication: { x [ n]}.{ x [ n]} = { x [ n] x [ n]}
1 2 1 2

function [y,n] = sigmult(x1,n1,x2,n2)


% implements y(n) = x1(n)*x2(n)
% -----------------------------
% [y,n] = sigmult(x1,n1,x2,n2)
% y = product sequence over n, which includes n1 and n2
% x1 = first sequence over n1
% x2 = second sequence over n2 (n2 can be different from n1)
n = min(min(n1),min(n2)):max(max(n1),max(n2));
% duration of y(n)
y1 = zeros(1,length(n)); y2 = y1; %
y1(find((n>=min(n1))&(n<=max(n1))==1))=x1;
% x1 with duration of y
y2(find((n>=min(n2))&(n<=max(n2))==1))=x2;
% x2 with duration of y
y = y1 .* y2; % sequence multiplication

DSP - Fisika UI
26

Operations on Sequences
• Scaling:
α { x [ n ]} = {α x [ n ]}

DSP - Fisika UI
27

Operations on Sequences
• Shifting: each sample of x[n] is shifted by an amount k to obtain a shifted
sequence y[n].
[ n]
y= { x [ n − k ]}
• If m = n−k, then n = m+k and the above operation is given by

{ x [ m]}
y [m + k ] =

function [y,n] = sigshift(x,m,k)


% implements y(n) = x(n-k)
% -------------------------
% [y,n] = sigshift(x,m,k)
%
n = m+k; y = x;

DSP - Fisika UI
28

Operations on Sequences
• Folding: In this operation each sample of x(n) is flipped around n = 0 to obtain a
folded sequence y(n).

y [ n=
] { x [ −n]}
function [y,n] = sigfold(x,n)
% implements y(n) = x(-n)
% -----------------------
% [y,n] = sigfold(x,n)
%
y = fliplr(x); n = -fliplr(n);

• Sample summation: This operation differs from signal addition operation. It adds
all sample values of x(n) between n1 and n2.
n2

∑ x [ n=] x [ n ] +  + x [ n ]
n = n1
1 2

DSP - Fisika UI
29

Operations on Sequences
• Sample products: This operation also differs from signal multiplication operation.
• It multiplies all sample values of x(n) between n1 and n2.

n2

∏ x [ n=] x [ n ] ×  × x [ n ]
n1
1 2

• Signal energy: The energy of a sequence x(n) is given by

∞ ∞
2
=εx x [ n] x * [ n] ∑ x [ n]
∑=
−∞ −∞

DSP - Fisika UI
30

Operations on Sequences
• Signal power: The average power of a periodic sequence x[n] with fundamental
period N is given by
1 N −1 2
Px = ∑ x [ n ]
N 0

DSP - Fisika UI
31

MATLAB Example 6
• Generate and plot each of the following sequences over the indicated interval

x(n) = 2δ(n + 2) − δ(n − 4), −5 ≤ n ≤ 5

n = -5:5;
x = 2*impseq(-2,-5,5) - impseq(4,-5,5);
stem(n,x); title(’Sequence in MATLAB Example 6’)
xlabel(’n’); ylabel(’x(n)’);

DSP - Fisika UI
32

MATLAB Example 6
• Generate and plot each of the following sequences over the indicated interval

x(n) = 2δ(n + 2) − δ(n − 4), −5 ≤ n ≤ 5


Sequence in MATLAB Example 6
2

1.5

0.5
x(n)

-0.5

-1
-5 -4 -3 -2 -1 0 1 2 3 4 5
n

DSP - Fisika UI
33

MATLAB Example 7
• Generate and plot each of the following sequences over the indicated interval

x(n) = n[u(n)−u(n−10)]+10e −0.3(n−10)[u(n−10)−u(n−20)],


0 ≤ n ≤ 20

n = [0:20];
x1 = n.*(stepseq(0,0,20)-stepseq(10,0,20));
x2 = 10*exp(-0.3*(n-10)).*(stepseq(10,0,20)- ...
stepseq(20,0,20));
x = x1+x2;
stem(n,x);
title(’Sequence in MATLAB Example 7’)
xlabel(’n’); ylabel(’x(n)’);

DSP - Fisika UI
34

MATLAB Example 7
• Generate and plot each of the following sequences over the indicated interval
x(n) = n[u(n)−u(n−10)]+10e −0.3(n−10)[u(n−10)−u(n−20)],
0 ≤ n ≤ 20
Sequence in MATLAB Example 7
10

5
x(n)

0
0 2 4 6 8 10 12 14 16 18 20
n

DSP - Fisika UI
35

MATLAB Example 8
• Generate and plot each of the following sequences over the indicated interval
x(n) = cos(0.04πn) + 0.2w(n), 0 ≤ n ≤ 50
w(n) is a Gaussian random sequence with zero mean and unit variance

n = 0:50;
x = cos(0.04*pi*n)+0.2*randn(size(n));
stem(n,x);
title('Sequence in MATLAB Example 8')
xlabel('n'); ylabel('x(n)');

DSP - Fisika UI
36

MATLAB Example 8
• Generate and plot each of the following sequences over the indicated interval
x(n) = cos(0.04πn) + 0.2w(n), 0 ≤ n ≤ 50
w(n) is a Gaussian random sequence with zero mean and unit variance
Sequence in MATLAB Example 8
1.5

0.5

0
x(n)

-0.5

-1

-1.5
0 5 10 15 20 25 30 35 40 45 50
n

DSP - Fisika UI
37

MATLAB Example 9
• Generate and plot each of the following sequences over the indicated interval

x [ n ] {,5, 4,3, 2,1,5, 4,3, 2,1,5, 4,3, 2,1,};



− 10 ≤ n ≤ 9

• Note that over the given interval, the sequence ˜x (n) has four periods

>> n = [-10:9]; x = [5,4,3,2,1];


>> xtilde = x’ * ones(1,4); xtilde = (xtilde(:))’;
>> subplot(2,2,4); stem(n,xtilde);
>> title(’Sequence in MATLAB Example 10’)
>> xlabel(’n’); ylabel(’xtilde(n)’);

DSP - Fisika UI
38

MATLAB Example 10
• Let

{ }
x [ n ] = 1, 2,3, 4,5,6,7,6,5, 4,3, 2,1

• Determine and plot the following sequences.


• x1[n] = 2x(n − 5) − 3x(n + 4)
• x2[n] = x(3 − n) + x(n) x(n − 2)

DSP - Fisika UI
39

MATLAB Example 10
{ }
x [ n ] = 1, 2,3, 4,5,6,7,6,5, 4,3, 2,1

• The sequence x(n) is nonzero over −2 ≤ n ≤ 10.

>> n = -2:10; x = [1:7,6:-1:1];

DSP - Fisika UI
40

MATLAB Example 10a


• x1[n] = 2x[n − 5] − 3x[n + 4]
• The first part is obtained by shifting x[n] by 5 and the second part by shifting x[n] by
−4.
• This shifting and the addition can be easily done using the sigshift and the sigadd
functions.

>> [x11,n11] = sigshift(x,n,5);


>> [x12,n12] = sigshift(x,n,-4);
>> [x1,n1] = sigadd(2*x11,n11,-3*x12,n12);
>> subplot(2,1,1); stem(n1,x1);
>> title(’Sequence in MATLAB Example 10a’)
>> xlabel(’n’); ylabel(’x1(n)’);

DSP - Fisika UI
41

MATLAB Example 10b


• x2[n] = x[3 − n] + x[n] x[n − 2]
• The first term can be written as x[−[n − 3]]. Hence it is obtained by first folding x[n]
and then shifting the result by 3.
• The second part is a multiplication of x[n] and x[n−2], both of which have the same
length but different support (or sample positions).

DSP - Fisika UI
42

MATLAB Example 10b


• x2[n] = x[3 − n] + x[n] x[n − 2]
• These operations can be easily done using the sigfold and the sigmult functions

>> [x21,n21] = sigfold(x,n);


>> [x21,n21] = sigshift(x21,n21,3);
>> [x22,n22] = sigshift(x,n,2);
>> [x22,n22] = sigmult(x,n,x22,n22);
>> [x2,n2] = sigadd(x21,n21,x22,n22);
>> subplot(2,1,2); stem(n2,x2);
>> title(’Sequence in MATLAB Example 10b’)
>> xlabel(’n’); ylabel(’x2(n)’);

DSP - Fisika UI
43

MATLAB Example 11
• Generate the complex-valued signal
x[n] = e[−0.1+j0.3]n, −10 ≤ n ≤ 10
• and plot its magnitude, phase, the real part, and the imaginary part in four separate
subplots.

>> n = [-10:1:10]; alpha = -0.1+0.3j;


>> x = exp(alpha*n);
>> subplot(2,2,1); stem(n,real(x));
>> title(’real part’);xlabel(’n’)
>> subplot(2,2,2); stem(n,imag(x));
>> title(’imaginary part’);xlabel(’n’)
>> subplot(2,2,3); stem(n,abs(x));
>> title(’magnitude part’);xlabel(’n’)
>> subplot(2,2,4); stem(n,(180/pi)*angle(x));
>> title(’phase part’);xlabel(’n’)

DSP - Fisika UI
44

MATLAB Example 11
x[n] = e[−0.1+j0.3]n, −10 ≤ n ≤ 10
real part imaginary part
2 1

0.5
1

-0.5

-1

-1

-2
-1.5

-3 -2
-10 -8 -6 -4 -2 0 2 4 6 8 10 -10 -8 -6 -4 -2 0 2 4 6 8 10

n n

magnitude part phase part


3 200

150
2.5

100

2
50

1.5 0

-50
1

-100

0.5
-150

0 -200
-10 -8 -6 -4 -2 0 2 4 6 8 10 -10 -8 -6 -4 -2 0 2 4 6 8 10

n n

DSP - Fisika UI
45

Discrete-Time Sinusoidal
• Basis for Fourier transform and in system theory as a basis for steady-state
analysis
=x [ n ] A cos (ωo n + θ o )

• Conveniently related to the continuous-time sinusoid

( t ) A cos ( Ωot + θo )
xa =

DSP - Fisika UI
46

Periodicity in time
• the sinusoidal sequence is periodic if

x [ n=
+ N ] A cos (ωo n + ωo N= + θo ) x [ n]
+ θ ) A cos (ωo n=

• This is possible if and only if ωoN = 2πk, where k is an integer

DSP - Fisika UI
47

Unit sample synthesis


• Any arbitrary sequence x[n] can be synthesized as a weighted sum of delayed and
scaled unit sample sequences, such as

=x [ n] ∑ x [ k ]δ [ n − k ]
k = −∞

DSP - Fisika UI
48

Even and odd synthesis


• A real-valued sequence xe[n] is called even (symmetric) if

xe [ − n ] =xe [ n ]

• A real-valued sequence xo[n] is called odd (antisymmetric) if

xo [ − n ] =− xo [ n ]

DSP - Fisika UI
49

Even and odd synthesis


• Then any arbitrary real-valued sequence x[n] can be decomposed into its even and
odd components

x [ n ] xe [ n ] + xo [ n ]
=

• where the even and odd parts are given by

1 1
[ n]  x [ n] + x [ −n]
xe= [ n]  x [ n] − x [ −n]
xo=
2 2

DSP - Fisika UI
50

Even and odd synthesis


• MATLAB function to decompose a given sequence into its even and odd
components

function [xe, xo, m] = evenodd(x,n)


% Real signal decomposition into even and odd parts
% -------------------------------------------------
% [xe, xo, m] = evenodd(x,n)
%
if any(imag(x) ~= 0)
error(’x is not a real sequence’)
end
m = -fliplr(n);
m1 = min([m,n]); m2 = max([m,n]); m = m1:m2;
nm = n(1)-m(1); n1 = 1:length(n);
x1 = zeros(1,length(m)); x1(n1+nm) = x; x = x1;
xe = 0.5*(x + fliplr(x)); xo = 0.5*(x - fliplr(x));

DSP - Fisika UI
51

MATLAB Example
• Let x[n] = u[n] − u[n − 10].
• Decompose x[n] into even and odd components.

DSP - Fisika UI
52

MATLAB Example 12
• Let x[n] = u[n] − u[n − 10].
• Decompose x[n] into even and odd components.
• The sequence x[n], which is nonzero over 0 ≤ n ≤ 9, is called a rectangular pulse

>> n = [0:10]; x = stepseq(0,0,10)-stepseq(10,0,10);


>> [xe,xo,m] = evenodd(x,n);
>> subplot(131); stem(n,x);
>> title(’Rectangular pulse’)
>> xlabel(’n’); ylabel(’x(n)’); axis([-10,10,0,1.2])
>> subplot(132); stem(m,xe); title(’Even Part’)
>> xlabel(’n’); ylabel(’xe(n)’);
>> axis([-10,10,0,1.2])
>> subplot(133); stem(m,xo); title(’Odd Part’)
>> xlabel(’n’); ylabel(’xe(n)’);
>> axis([-10,10,-0.6,0.6])

DSP - Fisika UI
53

MATLAB Example 12
• Let x[n] = u[n] − u[n − 10].
• Decompose x[n] into even and odd components.
• The sequence x[n], which is nonzero over 0 ≤ n ≤ 9, is called a rectangular pulse
Rectangular pulse

0.5

x(n)
0
-10 -8 -6 -4 -2 0 2 4 6 8 10

Even Part

0.5
xe(n)

0
-10 -8 -6 -4 -2 0 2 4 6 8 10

Odd Part
0.5

0
xe(n)

-0.5

-10 -8 -6 -4 -2 0 2 4 6 8 10

DSP - Fisika UI
54

The geometric series


• A one-sided exponential sequence of the form
{ αn , n ≥ 0 }
• where α is an arbitrary constant

• The convergence and expression for the sum of this series are used in many
applications

DSP - Fisika UI
55

Correlations of sequences
• Measure of the degree to which two sequences are similar
• the crosscorrelation of x[n] and y[n] is a sequence rxy[l] defined as


=rxy [  ] ∑ x [ n] y [ n − ]
n = −∞

DSP - Fisika UI
56

Terima Kasih
Adhi Harmoko Saputro

DSP - Fisika UI

You might also like