the Technology Interface Journal/Fall
2008 
Volume 9 No. 1
ISSN#15239926 
by
Li Tan, Ph.D. Jean Jiang,
Ph.D.
lizhetan@pnc.edu jjiang@devry.edu
Department of ECET Department of
ECET
Abstract: In this paper, we present a simple laboratory project for teaching realtime sampling rate conversions of digital signals using lowcost digital signal processors. Usually, the topic of the sampling rate conversion is discussed in the second digital signal processing (DSP) course in undergraduate programs of engineering technology. The paper deals with a situation for teaching sampling rate conversions when the different sampling rates of analog to digital conversion (ADC) and digital to analog conversion (DAC) cannot be flexibly set during realtime processing. To overcome this barrier, we employ a compromised way in which we first request students to store audio segments sampled at different sampling rates in the processor memory and let students implement their designed DSP algorithm to covert each presampled audio segment to produce an output at the DAC sampling rate. The method could be applied as an alternative when the sampling rates for ADC and DAC devices in the DSP system cannot be freely changed for sampling rate conversions.
Index Terms: Realtime digital signal processing, sampling rate conversion, decimation, interpolation, antialiasing filter, antiimage filter
I. Introduction
Recent advancement of digital signal processing (DSP) technology has a dramatic impact on the disciplines of electrical, computer, and biomedical engineering technology programs. Technologists are often desirable to be familiar with digital signals and systems, and basic DSP techniques, and to possess DSP working knowledge towards applications in order to keep up with the industry trends. Many undergraduate programs in engineering technology not only offer a course to cover fundamentals of DSP, but also continue to provide a second elective DSP course in which realtime applications and corresponding advanced topics such as multirate signal processing and adaptive filtering are introduced [1]. In many DSP applications, there is often a requirement for lowering or rising of a sampling rate. Such applications include speech and audio systems where the sampling rate of original data in storage media does not match the sampling rate set in the DSP system. As an example in [1, 2], a DSP system may be required to convert an MP3 audio with a sampling rate of 48 kHz to a CD audio having a sampling rate of 44.1 kHz, or to digital voice at the 8 kHz sampling rate, vice versa.
Although we could teach basic principles of sampling rate conversions using MATLAB simulations, engineering technology students would prefer to have handson DSP coding experience for real time processing to enhance their understanding of the rate conversion principles. On the other hand, the sampling rate of a DSP processor may be set to be fixed along with the embedded analog antialiasing filter before analog to digital conversion (ADC) device and analog reconstruction filter after digital to analog conversion (DAC) device such as TX320TMS67C1x DSK [1, 3, 4, 5]. This limitation could render teaching realtime sampling rate conversions to be a challenging task due to the demand of one sampling rate required for ADC device and other different sampling rate for DAC device. To tackle this problem for teaching the subject, we employ a compromised approach described as follows. We first request students to store audio segments sampled at different sampling rates in memory of the DSP system and then let students implement their designed DSP algorithms to covert each presampled audio segment to a processed digital output at the DSP system sampling rate. Practical implementations of realtime sampling rate conversions in different cases such as sampling rate reduction using an integer factor, sampling rate increase with an integer factor, as well as sampling rate change by a noninteger conversion factor are illustrated. The teaching method can be adopted as an alternative when the sampling rates for ADC and DAC devices in the DSP system could not be flexibly changed for the sampling rate conversion processing. In this paper, Section II describes the principles of sampling rate conversions and laboratory considerations for realtime processing, Section III depicts a laboratory project dealing with practical realtime implementations, and finally, Section IV shows summaries and conclusions.
II. Sampling Rate Conversions and
Laboratory Considerations
A.
Sampling rate conversion schemes
Figure 1 shows three typical schemes of sampling
rate conversions. Reduction of a
sampling rate by an integer factor _{},
referred to downsampling process or decimation, is shown in Figure 1a, in
which a reduced sampling rate _{}can be obtained, where _{} is the original
sampling rate in Hz. Symbol _{} indicates
downsampling operation in which for every _{} samples, the operation
will keep the first sample and discard the rest of _{} samples. As an example of using the scheme, if the original
sampling rate and reduction integer factor are required to be _{} kHz and _{}, respectively, the scheme will produce a new sampling rate
as _{} kHz. Since the reduced
sampling rate of 2 kHz has a new Nyquist limit of 1 kHz, any components
with frequencies beyond 1 kHz in the original data samples will be aliased. In
order to prevent possible aliasing noise after downsampling process, a digital antialiasing filter with the lowpass type and stop frequency
edge of 1 kHz must be designed and applied prior to the downsampling
operation. Notice that in Figure 1a, _{} and _{} are the filter input and output, respectively,
and the filter operates at the original sampling rate _{}. Index _{} indicates the time index of the
original samples while index _{} is the time index of
the downsampled output_{}.
a. Sampling rate decrease by an integer factor _{}
b. Sampling rate increase by an integer factor _{}
c. Sampling conversion by a
noninteger factor _{}
Fig. 1 Block diagrams for
various sampling rate conversions.
Figure 1b depicts the second case for increasing a
sampling rate by an integer factor _{},
referred as upsampling process or interpolation. Symbol _{} designates the
upsampling operation in which for each input sample, the operation will append
it with _{} zeros. If the original sampling rate and increasing
integer factor are _{} kHz and _{}, an increased sampling rate will be _{} kHz. Since the Nyquist limit of the original
samples, in this case, is 4 kHz and the upsampling scheme results in a new
Nyquist limit of 12 kHz, the image signals between 4 kHz and 12 kHz will be
introduced, resulting in a distortion in the processed output. Hence, an antiimage filter (also
called interpolation filter) with the lowpass type and stop frequency edge at
4 kHz should be designed and applied after a upsampling operation removes the
image noise. Again, since the antiimage
filter is cascaded after the upsampling operation, it operates at the
increased rate, that is, _{}, with the filter input and
output designated as _{} and _{}, respectively. Note
that time indices _{} and _{} are the time indices
at the original sampling rate and upsampling rate, respectively.
The third case for changing a sampling rate with a
noninteger factor _{} is shown in Figure 1c in which if the original sampling rate _{}kHz, and integer
factors _{} and _{} are given, the
conversion scheme leads to a resultant sampling rate as _{} kHz. The process can be obtained via cascading the
downsampling scheme after the upsampling scheme. As shown in Figure 1c, we notice that the
antiimage filter (interpolation filter) _{} and antialiasing
filter _{} operate at the same
rate _{}. Hence, these two filters can be combined into a single
filter _{} to reduce the
implementation complexity. The combined
filter is also a lowpass type and designed by using the most demanding requirements
extracted from both antiimage and antialiasing filters. In this laboratory
project, all digital filters designed are FIR type for simplicity. Engineering technology students are capable
of designing various FIR filters using the MATLAB toolbox because they have
learnt digital filter design in the first required DSP course. Before starting
this laboratory project, the principles of sampling rate conversions associated
with FIR filters are taught using the textbook [1] at the engineering
technology level. We focus on presenting a laboratory technique for students to
experience realtime sampling rate conversions.
B. Laboratory
Considerations
For
some lowcost DSP systems such as the TMS320C6711 DSK, where ADC and DAC
sampling rates are set to be 8 kHz and analog antialiasing and reconstruction
filters are embedded, changing sampling rates for ADC and DAC is not
flexible. In order to let engineering
technology students concentrate on coding DSP algorithms, Figure 2 describes a
simple laboratory model. As shown in
Figure 2, the lab uses the existing DAC sampling rate _{} and analog reconstruction filter, and requires
students to convert each presampled audio segment sampled at different
sampling rates _{} and stored in DSP memory. After sampling rate
conversion, the processed output will be output at the existing sampling rate _{}, displayed, and played in
real time. In this way, we avoid the problem of changing different sampling rates
for ADC and DAC devices.
Fig. 2 Laboratory setup for sample rate conversions.
In
this laboratory project, MATLAB offers a tool to generate audio data segments
at different sampling rate _{} so that preprocessed audio data segments
could be loaded into processor memory for future realtime conversion. Students
also use MATLAB to design the antialiasing as well as antiimage filters used
in rate conversion systems.
III. Laboratory Implementations
The laboratory project requires three phases to
complete. First, students need to prepare audio data samples consisting of
sinusoids and preprocessed audio data. Each size of the audio segments is
limited to a size of 4 K bytes so that after loading data samples into the DSP
memory, there is still enough memory for program codes. Each audio sample is
encoded as 16 bits per sample and each audio segment is repetitively applied in
realtime conversion processing. Table 1 lists the parameters used for
generating the different sinusoidal waveforms used in this laboratory
project. Note that the first sinusoidal
segment contains frequency components of 1 kHz and 5 kHz sampled at 16 kHz. It
can be demonstrated that the 5 kHz signal must be filtered (antialiasing
filtering) before the downsampling operation due to a fact that the DSP system
at the 8 kHz sampling rate can only handle the component with the maximum
frequency up to 4 kHz (Nyquist limit), otherwise, the aliasing signal of 3 kHz
will be introduced instead. Segments 4 and 5 are the voice segments each
containing a word of “we” (we.wav) obtained as follows. Students use a voice segment (we.wav) with
duration of 0.5 second originally sampled at 48 kHz with each audio sample
encoded by 16 bits. This voice segment will be further downsampled to have
sampling rates of 2 kHz and 3.2 kHz for experiments, respectively. Students
will perform filter design and sampling rate conversion using MATLAB. The
fundamentals for sampling rate conversions are covered in class as shown in the
textbook [1].
Table 1: Data sets and conversion requirements
No.
Seg. 
Frequency (Hz) 
Original
sampling rate 
Size (samples) 
Conversion
type 
Converted
sampling rate 
1 
1
k and 5 k 
16000
Hz 
1600

M=2 
8000
Hz 
2 
400
Hz 
1600
Hz 
1600 
L=5 
8000
Hz 
3 
1
k and 5 k 
12000
Hz 
1200 
L=2,
M=3 
8000
Hz 
4 
“we” 
2000
Hz 
1000 
L=4 
8000
Hz 
5 
“we” 
3200
Hz 
1600 
L=5,
M=2 
8000
Hz 
The second phase begins with designing antialiasing
and antiimage digital filters for each sampling rate conversion to be
performed in real time. Students are required to design digital FIR (finite
impulse response) filters (antialiasing, antiimage, and the combined filter)
to meet passband ripples less than 0.1 dB,
stopband attenuation less than 45 dB,
transition bandwidth of 800 Hz for segment 1 and segment 3, and transition
bandwidth of 400 Hz for the rest of segments. Table 2 lists each FIR filter
specifications including designs with Hamming window, cutoff frequency,
and number of taps (coefficients).
Table
2: FIR Filter specifications
(All
filters are lowpass FIR filters and designed using Hamming windows; the converted
sampling rate is 8000 Hz)
No.
Seg. 
Original
sampling rate 
Transition band 
Filter
Operating frequency 
Filter
type, Cutoff frequency (fc) Number
of taps (N) 
1 
16 kHz 
3.2
 4 kHz 
16
kHz 
Antialiasing
filter, fc = 3.6 kHz, N=67 
2 
1.6
kHz 
400
 800 Hz 
8
kHz 
Antiimage
filter, fc= 600 Hz, N=67 
3 
12
kHz 
3.2
 4 kHz 
24
kHz 
Combined
filter, fc=3.6 Hz, N=99 
4 
2 kHz 
0.6
 1 kHz 
8
kHz 
Antiimage
filter, fc=800 Hz, N=67 
5 
3.2 kHz 
1.2
– 1.6 kHz 
16
kHz 
Combined
filter, fc=1.4 kHz, N=133 
According to the specifications listed in Table
2, students will complete each filter design using MATLAB functions. As an
example for converting the sampling rate for segment
»
b=firwd(67,1,2*pi*3600/16000,0,4); % obtain filter coefficients
» freqz(b,1,16000,16000);
%plot frequency responses
The obtained frequency responses of the above
designed antialiasing filter are displayed in Figure 3. As shown in Figure 4,
performance of the passband ranging from 0 to 3.2 kHz is satisfied while the attenuation
of stopband ranging from 4 to 8 kHz is 50 dB which satisfies the attenuation
requirement of 45 dB. The phase response is linear in passband, which is
preferred for audio applications. Other
filters could be designed accordingly. Furthermore, the designed filter
coefficients are recorded and will be ported to the DSP processor for future
realtime implementations in phase 3.
Fig. 3 Frequency
responses of the antiimage filter for converting segment 1.
Phase 3 is a stage of realtime implementation
and testing. Students will port each of the acquired data segment to an array
with 16 bit size per sample (short type), port the designed FIR coefficients
(floatingpoint format), and initialize input buffer (floatingpoint format) in
the header file. As an example, a partial list of the header file for
processing segment 1 is shown in Figure 4. Note that the objective in this
paper is to show the laboratory pedagogy for teaching sampling rate
conversions. Hence, the program listed here is made as more generic as possible
and the algorithm is coded in the way that engineering technology students
would be able to understand easily and perform coding. Hence, the advance
coding of the DSP algorithm using the pointer and circular buffer is not considered
in this paper. Although the DSP program here is written for TMS320C671X DSK
platform, the idea can be used for other DSP platforms.
#define
NUM_DATA 1600 // 1600 samples /*
sinusoids with 1000 Hz and 5000 Hz sampled at 16000 Hz */ short
xin[NUM_DATA]={
0,5226,0,2165,8000,2165,0,5226,0,5226,0,2165,8000,2165,0,5226, 0,5226,0,2165,8000,2165,0,5226,0,5226,0,2165,8000,2165,0,5226,
... (not continuously listed) /*
FIR filter coefficients */ float
b[67]={ 0.0004,0.0008,0.0001,0.0010,0.0002,0.0014,0.0008,0.0018,
0.0019, ... (not continuously listed) /*
input buffer initialization*/ float
x[67]={0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, ... (not continuously listed) 
Fig. 4 Partial list of
data, filter coefficients, and initialized input buffer in the header file.
Next, students will modify the interrupt routine
(AtoD() shown in Figure 5 for coding
their developed DSP algorithms. The
sample program for processing segment
interrupt
void AtoD() {
int i,j; float sum, tmp; for (j=0;j<M;j++) { for(i=66; i>0; i) // update input buffer { x[i]=x[i1]; } x[0]=(float) xin[cnt]; // load new sample cnt++; sum=0.0; for(i=0;i<67;i++) // FIR filtering { sum=sum+x[i]*b[i]; } if (j== 0) { tmp=sum; } // update DAC with processed sample
(decimation) if(cnt==NUM_DATA) {
cnt=0; } // repeat inputting data segment } sample= (int) tmp; // send downsampled data to DAC } 
Fig. 5 Downsampling conversion by an integer factor of_{}.
The sample program for implementing upsampling conversion for segment 2 is shown in Figure 6. As illustrated in the code, the program sets first _{} inputs to be zeros and loads the _{}th one from the data array. Next, FIR filtering is operated and the program sends each processed output sample to DAC. Note that variable Lcount is incremented and reset to zero to count for _{} inserted zeros during the interpolation process. Finally, the output sample is scaled up by a factor of _{} before it is sent to DAC.
interrupt void AtoD() {
int i; float sum; Lcount++; for(i=66; i>0; i) // update input buffer with zeros { x[i]=x[i1]; } x[0]=0; if (Lcount==L) { x[0]=(float) xin[cnt]; // load new sample for every L samples cnt++; Lcount =0; } if (cnt==NUM_DATA) //check the data in the
buffer { cnt=0; } sum=0.0; for(i=0;i<67;i++) // FIR filtering { sum=sum+x[i]*b[i]; } sum = ((float) L)*sum; // scaled up by a
factor L sample= (int) sum; // send the up sampled data to DAC } 
Fig. 6 Upsampling conversion by an integer
factor of_{}.
Figure 7
illustrates an implementation for the case of processing segment 3, which
requires upsampling and downsampling processes. Note that the combined
antialiasing and antiimage filter operates at 24 kHz rate. For each sample in
the interpolation process, whether it is a data sample from the array or from
an inserted zero, the filter continues process _{} times and keeps one of the _{} processed samples to achieve the sampling rate
_{}. As shown in the
code, the last sample for every processed _{} samples is sent to DAC. Variable Lcount
counts _{} inserted zeros in the upsampling process.
interrupt
void AtoD() {
int i,j; float sum; /*
implement interpolation*/ /*
process M times (at Lxfs kHz) and keep one to get the M/L kHz samples*/ for(j=0;j<M;j++) { Lcount++;
// count for input the new sample for(i=98; i>0; i) // update input buffer with zeros { x[i]=x[i1]; } x[0]=0; if (Lcount==1) { x[0]=(float) xin[cnt]; // load new sample for every L samples cnt++; } if (Lcount == L) { Lcount =0; // ensure load new sample for next sample
processing } if (cnt==NUM_DATA) //check the data in the
buffer { cnt=0; } sum=0.0; for(i=0;i<99;i++) // FIR filtering { sum=sum+x[i]*b[i]; } sum = ((float) L)*sum; // scaled up by a
factor L } /* down sampled by a factor of M */ sample= (int) sum; // send the upsampled data to DAC } 
Fig. 7 Sampling rate conversion by a noninteger factor of_{}.
Test of converting
segments 1, 2, and 3 can be conducted either by connecting the configured DAC
lineout to an oscilloscope or connecting the configured DAC voice output to a
speaker. Students should also use an oscilloscope to measure the frequency to
ensure the accurate sampling rate conversion. For segments 4 and 5, students
could listen to each converted voice segment from a speaker and compare
their listening to the original voice segment to ensure the sampling rate
conversions.
This laboratory project has been used in the
advance DSP course in the electrical and computer engineering technology
program at Purdue University North Central and DeVry University, Atlanta,
Georgia. Students find that the approach is very attractive and stimulating in
realtime implementation of sampling rate conversions. The realtime experiment also encourages
students to pursue advanced implementations such as implementing polyphase
structures, subband audio coding, ECG (electrocardiograph) signal decimation
and processing, and other related applications.
IV. Conclusions
We proposed a simple and efficient laboratory project for teaching realtime signal sampling rate conversions. The laboratory method employs a compromised approach in which the DAC output sampling rate is always fixed while the prestored audio data segments with the different sampling rates stored in the processor memory are converted, respectively. Each converted signal can be verified via measurement from its oscilloscope display meanwhile played using a speaker in real time. This method could be adopted as an alternative when the sampling rates cannot be flexibly changed in the lowcost DSP processors, or the DSP processor that has a limitation to set and run different sampling rates for its ADC and DAC devices.
References
[1] Tan, L., Digital Signal Processing: Fundamentals and Applications, Elsevier/Academics Press, 2007.
[2]
Li, Z. N., and Drew, M. S., Fundamentals of Multimedia, Prentice Hall, Upper
Saddle River, NJ 07458, 2004.
[3] Kehtaranavaz, N., Simsek, B.,C6xBased Digital
Signal Processing, Prentice Hall, Upper Saddle River, New Jersey
07458, 2000.
[4]
[5] Spectrum Digital, Inc., TMS320C6713 Technical
Reference,
2003.
[6]