Objective 2 Decimation
Objective 2 Decimation
Objective 2 Decimation
Objective 2 Decimation
The objective of this lab is to alter the sampling rate of The basic operation required in decimation is the
signal. downsampling of the high-rate signal into a low-
rate signal. MATLAB provides the function [y] =
downsample(x,D) that downsamples input array x into
output array y by keeping every Dth sample starting
1 Introduction with the first sample. An optional third parameter
“phase” specifies the sample offset which must be an
In many practical applications of digital signal pro- integer between 0 and (D-1). For example,
cessing, one is faced with the problem of changing the
sampling rate of a signal, either increasing it or decreas- ≫ x = [1,2,3,4,3,2,1]; y = downsample(x,2)
ing it by some amount. The process of converting a sig-
nal from a given rate to a different rate is called sampling y =
rate conversion. In turn, systems that employ multiple 1 3 3 1
sampling rates in the processing of digital signals are downsamples by a factor of 2 starting with the first
called multirate digital signal processing systems. sample. However,
Let us think of an underlying (or original) analog sig-
nal xa (t) that was sampled using the sampling rate of ≫ x = [1,2,3,4,3,2,1]; y = downsample(x,2,1)
Fs = T1 samples/second to produce a discrete signal
y =
x(n). The resulting digital signal x(n) is subsequently
2 4 2
filtered using a lowpass filter (LPF) with a cutoff fre-
quency of ωc . produces an entirely different sequence by down-
Thus, the output signal y(n) has all its energy in the sampling, starting with the second sample (i.e., offset
band 0 ≤ ω ≤ ωc = 2πfc . According to the sampling by 1).
theorem, such a signal may be represented by the rate
of 2fc/T samples/second instead of its existing rate of 2.1 Example
Fs = T1 . Note that |fc | ≤ 0.5. However, if fc ≪ 0.5, then
2fc/T ≪ Fs . Hence it would seem more advantageous to Let x(n) = cos(0.125πn). Generate a large number of
lower the sampling frequency to a value closer to 2fc/T samples of x(n) and decimate them using D = 2, 4, and
and perform signal processing operations at this lower 8 to show the results of decimation.
rate. MATLAB provides the function y = decimate(x,D)
Other applications include the need for an optimal that resamples the sequence in array x at 1/D times the
interpolation in computer tomography and efficient original sampling rate. The resulting resampled array
multistage designs of narrowband lowpass filters. y is D times shorter i.e., length(y) = length(x)/D.
The MATLAB Signal Processing toolbox may be used Designing an ideal lowpass filter is not possible in the
to carry out a variety of operations associated with MATLAB implementation; however, fairly accurate ap-
sampling rate conversion and multirate processing. The proximations are used. The default lowpass filter used
key functions are listed below, in the function is an 8th-order Chebyshev type-I low-
pass filter with the cutoff frequency of 0.8π/D. Using
additional optional arguments, the filter order can be
1. decimate % resample data at a lower rate after low- changed or an FIR filter of specified order and cutoff
pass filtering frequency can be used.
We will plot the middle segments of the signals to
2. resample % change the sampling rate of a signal avoid end-effects due to the default lowpass filter in
the decimate function. The following MATLAB script
3. interp % resample data at a higher rate using low- shows details of these operations
pass interpolation clc , clear all , close all
n = 0:2048; k1 = 256; k2 = k1 +32; m = 0:( k2 - k1 )
4. upfirdn % upsample, apply a specified FIR filter, ;
Hf1 = figure ( ’ units ’ , ’ inches ’ , ’ position ’
and downsample a signal ,[1 ,1 ,6 ,4] , ...
’ paperunits ’ , ’ inches ’ , ’ p a p e r p o s i t i o n ’
,[0 ,0 ,6 ,4]) ;
Use on line MATLAB help to find out more about % ( a ) Original signal
these functions. Following examples illustrate the use of x = cos (0.125* pi * n ) ;
these functions. subplot (2 ,2 ,1) ;
1/4
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES
ADVANCED DIGITAL SIGNAL PROCESSING
Lab 10: Multirate Digital Signal Processing
2/4
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES
ADVANCED DIGITAL SIGNAL PROCESSING
Lab 10: Multirate Digital Signal Processing
% ( a ) Original signal set ( gca , ’ xtick ’ ,[0 ,0.5 ,1]) ; set ( gca , ’ ytick ’
x = cos ( pi * n ) ; ,0:1: I ) ;
subplot (2 ,2 ,1) ; % ( b ) I n t e r p o l a t i o n by I = 4 , L = 5;
Ha = stem (m , x ( m + k1 +1) , ’g ’ , ’ filled ’ ) ; I = 4; [ y2 , h2 ] = interp (x , I ) ; H2 = freqz ( h2 ,1 , w
axis ([ -1 ,33 , -1.1 ,1.1]) ; set ( Ha , ’ markersiz e ’ ,2) ; ) ; H2 = abs ( H2 ) ;
ylabel ( ’ Amplitude ’) ; title ( ’ Original Sequence x subplot (2 ,2 ,2) ; plot ( w / pi , H2 , ’g ’ ) ; axis ([0 ,1 ,0 ,
( n ) ’) ; I +0.2]) ; ylabel ( ’ Magnitude ’) ;
set ( gca , ’ xtick ’ ,[0 ,16 ,32]) ; set ( gca , ’ ytick ’ title ( ’I = 4 , L = 5 ’ ) ;
,[ -1 ,0 ,1]) ; set ( gca , ’ xtick ’ ,[0 ,0.25 ,1]) ; set ( gca , ’ ytick ’
% ( b ) I n t e r p o l a t i o n by I = 2 ,0:1: I ) ;
I = 2; y = interp (x , I ) ; % ( c ) I n t e r p o l a t i o n by I = 8 , L = 5;
subplot (2 ,2 ,2) ; I = 8; [ y3 , h3 ] = interp (x , I ) ; H3 = freqz ( h3 ,1 , w
Hb = stem (m , y ( m + k1 * I +1) , ’ c ’ , ’ filled ’) ; axis ) ; H3 = abs ( H3 ) ;
([ -1 ,33 , -1.1 ,1.1]) ; subplot (2 ,2 ,3) ; plot ( w / pi , H3 , ’g ’ ) ; axis ([0 ,1 ,0 ,
set ( Hb , ’ markersize ’ ,2) ; ylabel ( ’ Amplitude ’) ; I +0.4]) ; ylabel ( ’ Magnitude ’) ;
title ( ’ I n t e r p o l a t e d by I = 2 ’) ; title ( ’I = 8 , L = 5 ’ ) ; xlabel ( ’\ omega /\ pi ’ , ’
set ( gca , ’ xtick ’ ,[0 ,16 ,32]) ; set ( gca , ’ ytick ’ fontsize ’ ,10)
,[ -1 ,0 ,1]) ; set ( gca , ’ xtick ’ ,[0 ,0.125 ,1]) ; set ( gca , ’ ytick ’
% ( c ) I n t e r p o l a t i o n by I = 4 ,0:2: I ) ;
I = 4; y = interp (x , I ) ; subplot (2 ,2 ,3) ; % ( d ) I n t e r p o l a t i o n by I = 8 , L = 7;
Hc = stem (m , y ( m + k1 * I +1) , ’ r ’ , ’ filled ’) ; axis I = 8; L = 7; [ y4 , h4 ] = interp (x ,I , L ) ; H4 =
([ -1 ,33 , -1.1 ,1.1]) ; freqz ( h4 ,1 , w ) ; H4 = abs ( H4 ) ;
set ( Hc , ’ markersize ’ ,2) ; ylabel ( ’ Amplitude ’) ; subplot (2 ,2 ,4) ; plot ( w / pi , H4 , ’g ’ ) ; axis ([0 ,1 ,0 ,
title ( ’ I n t e r p o l a t e d by I = 4 ’) ; I +0.4]) ;
set ( gca , ’ xtick ’ ,[0 ,16 ,32]) ; set ( gca , ’ ytick ’ ylabel ( ’ Magnitude ’) ;
,[ -1 ,0 ,1]) ; title ( ’I = 8 , L = 7 ’ ) ; xlabel ( ’\ omega /\ pi ’ , ’
xlabel ( ’ n ’) ; fontsize ’ ,10)
% ( d ) I n t e r p o l a t i o n by I = 8 set ( gca , ’ xtick ’ ,[0 ,0.125 ,1]) ; set ( gca , ’ ytick ’
I = 8; y = interp (x , I ) ; subplot (2 ,2 ,4) ; ,0:2: I ) ;
Hd = stem (m , y ( m + k1 * I +1) , ’ m ’ , ’ filled ’) ; axis
([ -1 ,33 , -1.1 ,1.1]) ; The first three frequency response plots are for L = 5
set ( Hd , ’ markersize ’ ,2) ; ylabel ( ’ Amplitude ’) ; and, as expected, the filters are all lowpass with pass-
title ( ’ I n t e r p o l a t e d by I = 8 ’) ; band edges approximately around π/I frequencies and
set ( gca , ’ xtick ’ ,[0 ,16 ,32]) ; set ( gca , ’ ytick ’
,[ -1 ,0 ,1]) ; the gain of I. Also note that the filters do not have sharp
xlabel ( ’ n ’) ; transitions and thus are not good approximations to the
ideal filter. The last plot shows the response for L = 7,
We observe that the interpolated sequences for all which indicates a more sharp transition, which is to be
three values of I are appropriate and represent the ori- expected. Any value beyond L = 7 results in an unstable
ginal sinusoidal signal x(n) at higher sampling rates. In filter design and hence should be avoided.
the case of I = 8, the resulting sequence does not appear
to be perfectly sinusoidal in shape. This may be due the
fact the lowpass filter is not close to an ideal filter. 4 Sampling Rate Conversion
Having discussed the special cases of decimation (down-
3.2 Example
sampling by a factor D) and interpolation (upsampling
Examine the frequency response of the lowpass filter by a factor I), we now consider the general case of
used in the interpolation of the signal in Example 3.1. sampling rate conversion by a rational factor I/D. Basic-
The second optional argument in the interp function ally, we can achieve this sampling rate conversion by first
provides the impulse response from which we can com- performing interpolation by the factor I and then decim-
pute the frequency response, as shown in the following ating the output of the interpolator by the factor D. In
MATLAB script. other words, a sampling rate conversion by the rational
clc , clear all , close all
factor I/D is accomplished by cascading an interpolator
n = 0:256; x = cos ( pi * n ) ; w = [0:100]* pi /100; with a decimator. We emphasize that the importance
Hf1 = figure ( ’ units ’ , ’ inches ’ , ’ position ’ of performing the interpolation first and the decimation
,[1 ,1 ,6 ,4] , ... second is to preserve the desired spectral characteristics
’ paperunits ’ , ’ inches ’ , ’ p a p e r p o s i t i o n ’
,[0 ,0 ,6 ,4]) ; of x(n).
% ( a ) I n t e r p o l a t i o n by I = 2 , L = 5;
I = 2; [ y1 , h1 ] = interp (x , I ) ; H1 = freqz ( h1 ,1 , w
4.1 Example
) ; H1 = abs ( H1 ) ;
subplot (2 ,2 ,1) ; plot ( w / pi , H1 , ’g ’) ; axis ([0 ,1 ,0 ,
Consider the sequence x(n) = cos(0.125πn) discussed in
I +0.1]) ; ylabel ( ’ Magnitude ’) ; Example 2.1. Change its sampling rate by 3/2, 3/4, and
title ( ’I = 2 , L = 5 ’ ) ; 5/8.
3/4
MEHRAN UNIVERSITY OF ENGINEERING & TECHNOLOGY, JAMSHORO
INSTITUTE OF INFORMATION & COMMUNICATION TECHNOLOGIES
ADVANCED DIGITAL SIGNAL PROCESSING
Lab 10: Multirate Digital Signal Processing
4/4