DSP Lect L6
DSP Lect L6
Conversion
LEARNING OBJECTIVES
J Tutorial:
!Solve problems related to the above.
<MATLAB Exercises
Œ The sampled signal may be converted back into an analog signal and
then resampled.
• The signal may be resampled in the digital domain.
• The second approach will be discussed. This approach offer the advantage
of not introducing additional distortion in passing the signal through an
additional D/A and A/D conversion.
AFMH Created: Last update: DSP_L6_T2
June 1999 July 2005
1
A/D & D/A Sample Rate Reduction
Conversion (by an integer factor, M)
Reducing the sampling rate by an integer factor, M:
With a new sampling period, Ts' = MTs , the resampled signal is:
xd [ n ] = xa [nTs' ] = x a [ nMTs ] = x[ nM ]
x[n ] x d [n ]
↓M
M=2
Ts 2 Ts
x = sin(2*pi*0.042*m); 0
subplot(2,1,1) -1
stem(n, x(1:50)); 0 5 10 15 20 25 30 35 40 45 50
Time index n
axis([0 50 -1.2 1.2]);
Output Sequence
title('Input Sequence');
1
xlabel('Time index n');
0.5
ylabel('Amplitude');
Amplitude
subplot(2,1,2) 0
ylabel('Amplitude'); 0 5 10 15 20 25 30 35 40 45 50
Time index n
xlabel('Time index n');
Ref: Program P10_2, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T4
June 1999 July 2005
2
x[n] xd [n ]
A/D & D/A Sample Rate Reduction ↓M
Conversion (by integer factor, M) M =2
Ts 2T s
X (e jω )
2π
Ts
... ...
− 4π − 2π 0 2π 4π
ω
∞
Similarly the DTFT of xd[n]=x[nM]=xa[nMT s ] is: X d (e jω ) = 1
M Ts ∑X
r =−∞
a ( j MωTs − j M2πTrs )
X (e jω )
2π
... MTs
...
− 4π − 2π 0 2π 4π
ω
Spectrum stretches by factor M (amplitude scaled down by M) resulting in aliasing.
0.6
% Evaluate and plot the input spectrum
0.4
[Xz, w] = freqz(x, 1, 512); subplot(2,1,1); 0.2
plot(w/pi, abs(Xz)); grid 0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
xlabel('\omega/¹'); ylabel('Magnitude'); ω/¹
title('Input Spectrum');
% Generate the down-sampled sequence 0.5 Output Spectrum
0.3
3
A/D & D/A Sample Rate Reduction (by an integer factor, M)
Conversion Decimator Design
ω
− π 0 π
M
ω = Ω Ts
M
Decimator
jω
X (e jω ) 2π
MTs
X d (e )
2π
Ts
... ... ...
... 4π 2π 2π 4π
ω
ω − − 0
Ts
4π 2π
− − 2π 4π
0 MT s MT s MTs MTs
Ts Ts Ts Ts Ts π
MTs
AFMH Created: Last update: DSP_L6_T7
June 1999 July 2005
clf; 1
Amplitude
n = 0:99; -1
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n); -2
0 10 20 30 40 50 60 70 80 90 100
Time index n
y = decimate(x,M,'fir'); Output Sequence
subplot(2,1,1); stem(n,x(1:100)); 2
title('Input Sequence'); 1
Amplitude
subplot(2,1,2); -1
m = 0:(100/M)-1; stem(m,y(1:100/M)); -2
0 2 4 6 8 10 12 14 16 18 20
4
A/D & D/A Sample Rate Increase
Conversion (by an integer factor, L)
Increasing the sampling rate by an integer factor, L
With a new sampling period, Ts = Ts / L ,the resampled signal is:
'
~
x d [ n ] = x a[ nTs' ] = xa [ nTs / L] = x[ n / L] n = 0,± L ,±2 L,...
n ↑L
0 1 0 L 2L 3L 4L n
Ts
∑ ~x [n]e ∑ x[n]e
~
X d ( e jω ) = d
− jnω
= − jnL ω
= X ( e jLω )
n= −∞ n =−∞
x = sin(2*pi*0.12*n); 0
subplot(2,1,2) 0
stem(n,y(1:length(x))); -0.5
title('Output Sequence');
-1
xlabel('Time index n'); 0 5 10 15 20 25 30 35 40 45 50
Time index n
ylabel('Amplitude');
Ref: Program P10_1, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T10
June 1999 July 2005
5
A/D & D/A Sample Rate Increase
Conversion (by an integer factor, L)
X a ( jΩ )
∞ ∞
jω
X (e )
∑ ~x [n]e ∑ x[n]e
~
X d ( e jω ) = d
− jnω
= − jnL ω
= X ( e jLω ) 1 / Ts
n= −∞ n =−∞ ... ...
− 2π − π 0 π 2π ω
Spectrum is scaled ~
X d ( e jω ) L=2
or compressed 1 / Ts
... ...
After up-sampling, it is necessary to ω
− 2π
− π 0 π 2π 4π
= 2π
remove the frequency scaled images of L L L L L
0.6
xlabel('\omega/¹'); ylabel('Magnitude'); 0
0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/¹
title('Input Spectrum'); subplot(2,1,2);
% Generate the up-sampled sequence
Output Spectrum
L = input('Type in the up-sampling factor = 1');
y = zeros(1, L*length(x)); 0.8
Magnitude
0
plot(w/pi, abs(Yz)); axis([0 1 0 1]); grid 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1
ω/¹
xlabel('\omega/¹'); ylabel('Magnitude');
title('Output Spectrum');
Ref: Program P10_3, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T12
June 1999 July 2005
6
A/D & D/A Sample Rate Increase (by an integer factor, L)
Conversion Interpolator Design
0 L 2L 3L 4L n
x[ 0 ] x[1 ] x[ 3 ] x[ 4 ]
x[ 2 ]
n
0 1
Ts
0 L 2L 3L 4L n
x = sin(2*pi*0.043*n) + sin(2*pi*0.031*n); 0
% Generate the interpolated output sequence -1
y = interp(x,L); -2
0 5 10 15 20 25 30 35 40 45 50
% Plot the input and the output sequences Time index n
subplot(2,1,1);
stem(n,x(1:50)); 2
Output Sequence
title('Input Sequence'); 1
xlabel('Time index n'); ylabel('Amplitude');
Amplitude
0
subplot(2,1,2);
m = 0:(50*L)-1; -1
stem(m,y(1:50*L)); -2
0 50 100 150 200 250
7
A/D & D/A Fractional-Rate Sampling Rate Alteration
Conversion (by a rational factor)
The cascade of a decimator that reduces the sampling rate by a factor M with
an interpolator that increases the sampling rate by a factor L results in a
system that changes the sampling rate by a rational factor of L/M.
Because the cascade of two lowpass filters with roll-off frequencies π/M and
π/L is equivalent to a single lowpass filter with cut-off frequency
ωc = min {Mπ , πL }
Application Example #6
Digital audio tape (DAT) drives have a sampling frequency of 48 kHz, whereas
a compact disk (CD) player operates at a rate of 44.1 kHz. In order to record
directly from a CD onto a DAT, it is necessary to convert the sampling rate
from 44.1 to 48 kHz. Therefore, consider the following system for performing
this sample rate conversion
Find the smallest possible values for L and M and find the appropriate filter to
perform the conversion.
8
A/D & D/A
Conversion
Examples
ωc = min{Mπ , πL } = 160
π
n = 0:29; 0
-1
x = sin(2*pi*0.43*n) + sin(2*pi*0.31*n);
-2
y = resample(x,L,M); subplot(2,1,1); 0 5 10 15 20 25
Time index n
stem(n,x(1:30));axis([0 29 -2.2 2.2]);
title('Input Sequence'); Output Sequence
2
xlabel('Time index n'); 1
Amplitude
ylabel('Amplitude'); 0
subplot(2,1,2); -1
m = 0:(30*L/M)-1; -2
0 5 10 15 20 25 30 35 40 45
stem(m,y(1:30*L/M));axis([0 (30*L/M)-1 -2.2 2.2]); Time index n
title('Output Sequence');
xlabel('Time index n'); ylabel('Amplitude');
Ref: Program P10_7, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T18
June 1999 July 2005
9
A/D & D/A
Conversion
Examples
Application Example #7
Suppose that we are required to slow a segment of speech to one-half its
normal speed. The speech signal sa(t) is assumed to have no energy outside of
5 kHz, and its sampled at a rate of 10 kHz, yielding the sequence
s[n] = sa[nT s].
The following system is proposed to create the slowed-down speech signal.
s a (t) s[n] w[n] Interpolation y[n] ya (t )
A/D ↑2 Filter
D/A
S a ( j Ω)
Ts Ts
A
Assume that S a(jΩ) is as shown:
− 10000π Ω
10000π
To see the effect of this filter on w[n], note that due to the up-sampling,
w[n] = 0 for n odd. Therefore with y[n] = w[n] + 1/2 w[n-1] + 1/2 w[n+1]
it follows that w[n] n even
y[n ] = 1
2 w[ n − 1] + 2 w[n + 1]
1
n odd
Thus, the even-index values of w[n] are unchanged, and the odd-index values are the
average of the two neighbouring values, i.e. h[n] performs a linear interpolation
between the values of w[n]. AFMH Created: Last update: DSP_L6_T20
June 1999 July 2005
10
A/D & D/A
Conversion
Examples
T Y (e ) | Ω |< π / Ts
jΩTs A/ Ts
Ya ( jΩ) = s ... ...
ω
0 otherwise −π −π π
2
π
2
Since Y ( e ) = H (e jω )W (e jω ) = (1 + cos ω )W (e j ω )
jω (1 + cosω )
and W (e j ω ) = S (e j 2 ω )
−π −π π π ω
then T (1 + cos ΩTs )S ( e j 2 ΩTs ) | Ω |< 10000 π 2 2
Ya ( jΩ) = s
0 otherwise
which is the product of (1+cos ΩT s) and T s S(ej2ΩTs ) as illustrated:
Thus, ya(t) does not correspond to slowed-down Ya ( j Ω)
speech due to the images of sa(t) that occur 2A
in the frequency range 5000π<|W|<10000π and
the nonideal linear interpolator. Ω
−10000 π − 5000 π 5000 π 10000 π
Note a better approximation - use a DC convertor
with sampling rate of 2T s to eliminate images. AFMH Created: Last update: DSP_L6_T21
June 1999 July 2005
11