0% found this document useful (0 votes)
14 views11 pages

DSP Lect L6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views11 pages

DSP Lect L6

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 11

A/D & D/A

Conversion
LEARNING OBJECTIVES

$Develop the sample rate conversion process as the process for


mutlirate systems

þ Perform sample rate conversion


þ Use cascade equivalences for sample (rational) rate conversion

J Tutorial:
!Solve problems related to the above.
<MATLAB Exercises

&Chapters 10,’Digital Signal Processing’, Sanjit K. Mitra

AFMH Created: Last update: DSP_L6_T1


June 1999 July 2005

A/D & D/A Multirate Systems –


Conversion Sample Rate Conversion
• In many practical applications of DSP, there may be a need to change the
sampling rate of a signal. Examples:
– Digital audio: 32KHz in broadcasting, 44.1KHz in digital compact disk
(CD), and 48KHz in digital audio tape (DAT)
– Video:
Composite video: NTSC – 14.3181818MHz, PAL – 17.734475MHz.
Component video: 13.5MHz (luminance), 6.75MHz (chrominance)

• Two methods for sample rate conversion:

Œ 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 ]

This can be accomplished by taking every Mth sample of x[n] - down-sampler.

x[n ] x d [n ]
↓M
M=2

Ts 2 Ts

AFMH Created: Last update: DSP_L6_T3


June 1999 July 2005

A/D & D/A MATLAB Example


Conversion Sample Rate Reduction (by an integer factor, M)

% Illustration of Down-Sampling by an Integer Factor, M=3


Input Sequence
clf;
1
n = 0: 49;
m = 0: 50*3 - 1; 0.5
Amplitude

x = sin(2*pi*0.042*m); 0

y = x([1 : 3 : length(x)]); -0.5

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

stem(n, y); axis([0 50 -1.2 1.2]); -0.5


title('Output Sequence'); -1

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

Down-sampling generally results in aliasing.


Sampling period, T s is increased i.e. sampling frequency, Fs is decreased resulting in
spectral overlapping of the replicated spectrum.

Recall the DTFT of x[n]=xa[nT s ] is: X (e j ω ) = X s ( jΩ) Ω=ω = T1s
Ts
∑X
k= −∞
a ( j Tωs − j 2Tπsk )

X (e jω )

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ω )

... MTs
...
− 4π − 2π 0 2π 4π
ω
Spectrum stretches by factor M (amplitude scaled down by M) resulting in aliasing.

AFMH Created: Last update: DSP_L6_T5


June 1999 July 2005

A/D & D/A MATLAB Example


Conversion Effect of Down-Sampling in the Frequency Domain
% Effect of Down-sampling in the Frequency Domain, M=3
% Use fir2 to create a bandlimited input sequence
clf; Input Spectrum
freq = [0 0.42 0.48 1]; mag = [0 1 0 0]; 1

x = fir2(101, freq, mag); 0.8


Magnitude

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

M = input('Type in the down-sampling factor0.4= ');


y = x([1: M: length(x)]);
Magnitude

0.3

% Evaluate and plot the output spectrum 0.2


[Yz, w] = freqz(y, 1, 512); subplot(2,1,2); 0.1
plot(w/pi, abs(Yz)); 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('Output Spectrum');
Ref: Program P10_4, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T6
June 1999 July 2005

3
A/D & D/A Sample Rate Reduction (by an integer factor, M)
Conversion Decimator Design

Thus, in order to avoid aliasing, x[n] should be filtered prior to down-sampling


with a lowpass filter having a cut-off ωc = π/M rad. (or π/MT s rad/sec)

The cascade of a lowpass filter with a down-sampler is called a decimator.

ω
− π 0 π
M
ω = Ω Ts
M

x[n ] Lowpass filter x d [n ] discrete continuous


gain=1 ↓M frequency
variable
frequency
variable
cutoff=π/M

Decimator

X (e jω ) 2π
MTs
X d (e )

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

A/D & D/A MATLAB Example


Conversion Decimator Operation

% Illustration of Decimation Process, M=5


% decimation process filters the input data with a
lowpass filter and then resamples the resultant Input Sequence
smoothed signal at a lower rate. 2

clf; 1
Amplitude

M = input('Down-sampling factor = '); 0

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

xlabel('Time index n'); ylabel('Amplitude'); 0

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

title('Output Sequence'); Time index n

xlabel('Time index n');ylabel('Amplitude');


Ref: Program P10_5, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T8
June 1999 July 2005

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,...

This is done by inserting (L-1) zeroes between


each sample of x[n] - up-sampler.
L= 2 x[ 0 ] x[1 ]
x[n ] ~
xd [ n] x[ 2 ]
x[ 3 ] x[ 4 ]

n ↑L
0 1 0 L 2L 3L 4L n
Ts

The up-sampler expands the time scale by a factor of L.


In the frequency domain, the spectrum is simply scaled (compressed by factor L) in
frequency: ∞ ∞

∑ ~x [n]e ∑ x[n]e
~
X d ( e jω ) = d
− jnω
= − jnL ω
= X ( e jLω )
n= −∞ n =−∞

AFMH Created: Last update: DSP_L6_T9


June 1999 July 2005

A/D & D/A MATLAB Example


Conversion Sample Rate Increase (by an integer factor, L)

% Illustration of Up-Sampling by an Integer Factor


% Input Sequence
1
clf;
n = 0:50; 0.5
Amplitude

x = sin(2*pi*0.12*n); 0

y = zeros(1, 3*length(x)); -0.5


y([1: 3: length(y)]) = x;
-1
subplot(2,1,1) 0 5 10 15 20 25 30 35 40 45 50
Time index n
stem(n,x);
title('Input Sequence'); Output Sequence
1
xlabel('Time index n');
ylabel('Amplitude'); 0.5
Amplitude

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Ω )

In the frequency domain: − Ω0 0 Ω0 Ω

∞ ∞

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

X a(jΩ), except those that are at integer H (e jω )


L
multiples of 2π. ... ...
2π ω
− 2π
L
− π
L
0 π
L L

L
= 2π
~
This is accomplished by filtering xd [ n] X d ( e jω )
with a lowpass filter that has cutoff L/ Ts

frequency of π/L and a gain of L. In the ... ...


ω
time domain, the in-between zero- − 2π
L
− π
L
0 π
L

L

L
= 2π
samples are effectively interpolated. AFMH Created:
June 1999
Last update:
July 2005 DSP_L6_T11

A/D & D/A MATLAB Example


Conversion Effect of Up-Sampling in the Frequency Domain
% Effect of Up-sampling in the Frequency Domain
% Use fir2 to create a bandlimited input sequence
freq = [0 0.45 0.5 1]; mag = [0 1 0 0]; 1
Input Spectrum

x = fir2(99, freq, mag); 0.8

% Evaluate and plot the input spectrum


Magnitude

0.6

[Xz, w] = freqz(x, 1, 512); subplot(2,1,1); 0.4


plot(w/pi, abs(Xz)); axis([0 1 0 1]); grid 0.2

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

y([1: L: length(y)]) = x; 0.6

% Evaluate and plot the output spectrum 0.4


[Yz, w] = freqz(y, 1, 512); 0.2

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

As explained in the previous slide, the up-sampling process consists of an up-


sampler which inserts (L-1) zeros between each sample of x[n], followed by a
lowpass filter.

The cascade of an up-sampler and a lowpass filter is called an interpolator.


x[ 0 ] x[1 ] x[ 3 ] x[ 4 ]
x[ 2 ]

0 L 2L 3L 4L n

x[n ] x~d [ n ] Lowpass filter x d [n ]


↑L gain=L
cutoff=π/L

x[ 0 ] x[1 ] x[ 3 ] x[ 4 ]
x[ 2 ]
n
0 1
Ts
0 L 2L 3L 4L n

AFMH Created: Last update: DSP_L6_T13


June 1999 July 2005

A/D & D/A MATLAB Example


Conversion Interpolator Operation
% Illustration of Interpolation Process
clf;
L = input('Up-sampling factor = '); Input Sequence
2
% Generate the input sequence
n = 0:49; 1
Amplitude

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

title('Output Sequence'); Time index n

xlabel('Time index n'); ylabel('Amplitude');


Ref: Program P10_6, DSP Lab using Matlab, Mitra AFMH Created: Last update: DSP_L6_T14
June 1999 July 2005

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.

x[n ] Lowpass filter Lowpass filter x d [n ]


↑L gain=L gain=1 ↓M
cutoff=π/L cutoff=π/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 }

The sample rate convertor may be simplified:

x[n ] Lowpass filter x d [n ]


↑L gain=L ↓M
cutoff=min{π/L , π/M }

AFMH Created: Last update: DSP_L6_T15


June 1999 July 2005

A/D & D/A


Conversion
Examples

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

xCD [n] x DAT [n ]


↑L H (e jω ) ↓M

Find the smallest possible values for L and M and find the appropriate filter to
perform the conversion.

AFMH Created: Last update: DSP_L6_T16


June 1999 July 2005

8
A/D & D/A
Conversion
Examples

Solution App. Example #6

Given that 48000=27.3.53 and 44100=22.32.52.72, to change the sampling rate


we require 7 3 5
L
= 2 .3.5 = 2 .5 = 160
M 22 .32 .52.72 3 .7 2 147

Therefore if we up-sample by L=160 and then down-sample by M=147, we


achieve the desired sample rate conversion.

The lowpass filter we require must have a cut-off frequency

ωc = min{Mπ , πL } = 160
π

and the gain of the filter, L=160.

AFMH Created: Last update: DSP_L6_T17


June 1999 July 2005

A/D & D/A MATLAB Example


Conversion Fractional-Rate Sampling Rate Alteration

% Illustration of Sampling Rate Alteration by a Ratio of Two Integers


clf; Input Sequence

L = input('Up-sampling factor = '); 2

M = input('Down-sampling factor = '); 1


Amplitude

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π

(a) Determine the spectrum of w[n].


(b) Suppose that the d-t filter is described by the difference equation
y[n] = w[n] + 1/2{w[n-1] + w[n+1]}.
Find the frequency response of the filter and describe its effect on w[n].
(c) What is Ya(jΩ) in terms of S a(jΩ)? Does ya(t) correspond to slow-down
speech? AFMH Created: Last update: DSP_L6_T19
June 1999 July 2005

A/D & D/A


Conversion
Examples
S( e j ω )
Solution App. Example #7
A / Ts
(a) Since sa(t) is sampled at the
... ...
Nyquist rate, the DTFT of the ω
− 2π −π π 2π
sampled speech signal, s[n] is: W(e )jω

Up-sampling by a factor of 2 scales the A / Ts


frequency axis of S(e jw) by a factor two: ... ...
ω
−π −π π π
(b) The unit sample response of the d-t filter is: 2 2

h[n]=1/2 δ[n+1] + δ[n] + 1/2 δ[n-1]

which has a frequency H(e jω ) = 1 + cos ω

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

Solution App. Example #7


(c) The output of the D/A convertor, ya(t) has a Fourier transform W(e jω )

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

You might also like