DSP Basics

advertisement
DSP Basics
Hsiao-Lung Chan
Dept. Electrical Engineering
Chang Gung University
chanhl@mail.cgu.edu.tw
Tuning fork example

A sinusoid signal at 440 Hertz (Hz)
A cos(2 (440)t   )
amplitude
frequency
phase
• Another representation of frequency
  (2 ) f
radians/sec
• Period
1 2
T 

f
seconds
DSP Basics 2
An example of sinusoid
5 cos(0.3 t  1.2 )
  203  
DSP Basics 3
Analog and digital systems

Analog/electronics
x(t)

Electronics
y(t)
Digital/Microprocessor

x(t)
Convert x(t) to numbers stored in memory
A-to-D
x[n]
Computer
y[n]
D-to-A
y(t)
DSP Basics 4
Continuous- and discrete-time signals

Sampling rate (fs)


fs =1/Ts number of samples per second
Ts = 125 microsecsec (10-3 sec)  fs = 8000 samples/sec
x(t)
C-to-D
x[n]=x(nTs)
DSP Basics 5
f s  2kHz
f s  500Hz
DSP Basics 6
Sampling and reconstruction
 sampling
reconstructed signal
 aliasing occurs
DSP Basics 7
Sampling and reconstruction (con2dis_simulation.m)
% specification of sinusoid
f0=8;
a=5;
phi=0;
% Using 200-Hz sampling rate
fs=200;
t=0:1/fs:0.5;
x=a*cos(2*pi*f0*t+phi);
subplot(3,2,1)
stem(t,x)
ylabel('x(n)')
title('fs = 200 Hz')
axis([min(t) max(t) -6 6])
DSP Basics 8
Sampling and reconstruction
% Recosntruct signal using a high sampling rate
fs_r=2000;
new_t=min(t):1/fs_r:max(t);
x_r=zeros(1,length(new_t));
for k=1:length(t)
x_r=x_r+x(k)*sinc((new_t-t(k))*fs);
End
subplot(3,2,2)
plot(new_t,x_r)
ylabel('xr')
title('Reconstructed signal')
axis([min(new_t) max(new_t) -6 6])
DSP Basics 9
DSP Basics 10
Sampling theorem
DSP Basics 11
Over-sampling (fs > 2 fmax)
-fs/2 ~ fs/2
-1/2 ~ 1/2
DSP Basics 12
Under-sampling (fs < 2 fmax)
-fs/2 ~ fs/2
-1/2 ~ 1/2
DSP Basics 13
Critical-sampling (fs = 2 fmax)
-fs/2 ~ fs/2
-1/2 ~ 1/2
DSP Basics 14
Critical-sampling (fs = 2 fmax)
-fs/2 ~ fs/2
-1/2 ~ 1/2
DSP Basics 15
Spectrum after sampling
From A.Ambardar, Analog and Digital Signal Processing, 2nd Edition, Brook/Cole, 1999.
DSP Basics 16
Spectrum after sampling
• Nyquist frequency = critical sampling rate ( = 2B)
• Under-sampling (S<2B) causes aliasing
From A.Ambardar, Analog and Digital Signal Processing, 2nd Edition, Brook/Cole, 1999.
DSP Basics 17
Sampling Theorem
From A.Ambardar, Analog and Digital Signal Processing, 2nd Edition, Brook/Cole, 1999.
DSP Basics 18
Sampling Theorem (Cont.)
• Nyquist frequency
• Critical sampling rate ( = 2B)
• Undersampling (S<2B) causes aliasing
From A.Ambardar, Analog and Digital Signal Processing, 2nd Edition, Brook/Cole, 1999.
DSP Basics 19
Block Diagram of DSP System
Analog
Signal
Anti-Aliasing
Filter
Lowpass
Filter
Analog
Signal
Reconstruction
Filter
ZOH
A/D
Digital Signal
Zero-Order
Hold
ZOH
Processor
D/A
DSP Basics 20
Z transform
z plane
Imaginary
z = e jω
f0
0
fs/2
Real
fs
Frequency domain
-f0
-f0
-fs
-fs/2
f0
0
fs/2
fs
DSP Basics 21
Z transform
Delay
x(n)
Z -1
Linear Combination
x(n-1)
x(n)
a
Multiply
x(n)
a
Σ
a x(n) + b y(n)
b
a x(n)
y(n)
Digital signal
z transform
Analog signal
Input signal
x(n)
X(z)
x(t)
Delay one sample
x(n-1)
Z -1 X(z)
x(t-Ts)
Multiply
a x(n)
a X(z)
a x(t)
Linear combination
a x(n) + b y(n)
a X(z) + b Y(z)
a x(t) + b y(t)
DSP Basics 22
Transfer function
impulse response
convolution
x(n)
Digital System
y(n)
y ( n)  x ( n)  h( n)
h(t)
Inverse
Z-Transform
Z-Transform
X(z)
Digital System
Y(z)
Y ( z)  X ( z)  H ( z)
H(z)
transfer function
DSP Basics 23
Example 1: Perform the running average of last six
digital sample
y (n) 
x ( n )  x ( n  1)  x ( n  2)  x ( n  3)  x ( n  4)  x ( n  5)
6
X ( z )  z 1 X ( z )  z 2 X ( z )  z 3 X ( z )  z 4 X ( z )  z 5 X ( z )
Y ( z) 
6
Y ( z ) 1  z 1  z  2  z  3  z  4  z 5
H ( z) 

X ( z)
6
DSP Basics 24
Example 2: Perform the average of current data
and last filter output
y ( n  1)  x ( n)
y (n) 
2
z 1Y ( z )  X ( z )
Y ( z) 
2
Y ( z)
1
H ( z) 

X ( z ) 2  z 1
DSP Basics 25
Frequency Response of Transfer Function
X(z)
H(z)
Y(z)
Imaginary
z = e jω
X
Real
If the poles of H(z) are
located with unit circle
X
z plane
Frequency Response of H(z)
H ( j  )  H ( z ) z  e j
DSP Basics 26
Frequency Response (Cont.)
Imaginary
fs/ 2
Magnitude



| Z || Z || Z |
| H ( j ) | 1  2  3
| P1 |  | P2 |
Phase
 H ( j )   Z 1   Z 2   Z 2   P 1   P 2
P1

Z3

Z1
X

Z2

P1

P2
z = e jω
Real
X
  
Z1  Z 2  Z 3
H ( j )   
P1  P2
z plane
DSP Basics 27
Frequency Response of Example 1 and 2
Magnitude
From Jonathan W. Valvano, Embedded Microcomputer Systems, real time interfacing, Brooks/Cole, 2000.
DSP Basics 28
Frequency Response of Example 1 and 2
Phase
Linear Phase
From Jonathan W. Valvano, Embedded Microcomputer Systems, real time interfacing, Brooks/Cole, 2000.
DSP Basics 29
Linear Phase
sin

30
n
sin(

30
n

15
)  sin[

30
( n  2)]
Linear phase
φ(ω) =-2 ω
 sin

10
n
sin(



n  )  sin[ ( n  2)]
10
5
10
Delay 2 samples
Modified from L.Ludeman, Fundamentals of digital signal processing,Harper & Row, 1986.
DSP Basics 30
Nonlinear Phase
sin

30
n
sin(

30
n

15
)  sin[

30
( n  2)]
Quadratic phase
Signal distortion !
Delay 2 samples
 ( ) 
 150
 sin

10
n

 2  3
sin(

10
n

18
)  sin[ ( n  12)]
15
10
Delay 12 samples
Modified from L.Ludeman, Fundamentals of digital signal processing,Harper & Row, 1986.
DSP Basics 31
FIR (Finite Impulse Response) Filter
N
y ( n )   bk x ( n  k )
H ( z) 
k 0
Y ( z)
 b0  b1 z 1  b2 z  2   bN z  N
X ( z)

b0
x(n)
b1
Z-1
y(n)
b2
bN
Z-1
x(n-1)
Z-1
x(n-2)
x(n-N)
• FIR posses linear-phase property if filter coefficients
are symmetry or anti-symmetry around the center
DSP Basics 32
IIR (Infinite Impulse Response) Filter
q
b
z
q0 q
M
N
a
p 0
M
p
y ( n  p )   bq x ( n  q )
q 0
Y ( z)
 N
H ( z) 
X ( z)  a p z  p
p 0

x(n)
b0
Z-1
b1
-a1
Z-1
Z-1
b2
-a2
Z-1
Z-1
bN
-a3
y(n)
Z-1
DSP Basics 33
Reference


J.H. McClellan, R.W. Schafer, M.A. Yoder, Signal
Processing First, Prentice Hall, 2003.
M.J. Roberts, Signals and Systems: Analysis of Signals
Through Linear Systems, McGraw-Hill, 2003.
DSP Basics 34
Download