SAIDTHESIS.DOC

advertisement
2
Reconstruction of Nonuniformly Sampled Signals Using Multirate
Filter Banks
Said M. Said
MSc Project
King’s COllege London
October 1999
3
TABLE OF CONTENTS
ACKNOWLEDGEMENTS
iii
1 GENERAL DISCIPTION OF THE PROJECT
1
1.1 Introduction
1.2 Review of Sampling Theorem
1.3 Concept of Multirate Signal Processing
1
3
6
2 POLYPHASE FILTERS
2.1 Polyphase Representation
2.2 Polyphase Implementation
2.3 Practical Implementation for Signal Reconstruction
3 FILTER DESIGN TECHNIQUE
3.1 Mth Band Filter
3.2 Filter Design Specification
4 HILBERT TRANSFORM WITH Mth BAND
4.1 Description of Synthesis Bank
4.2 Implementation of Synthesis Filter
4.2.1 Filter Specification
5 REAL TIME IMPLEMENTATION
5.1 The Architecture of TMS320C30
5.2 The Analog Interface Chip (AIC)
5.3 AIC Control
5.4 Interrupts
5.5 AIC Communication Routines with Serial Port 0
5.6 Results Obtained
5.6.1 Calculating Values A & B for Desired Sampling
and Cutoff Frequencies
6 CONCLUSION
6.1 Memory Saving of Polyphase Filters
6.1.1 Estimation of Computational Complexity
7
7
9
12
13
13
15
20
20
22
23
27
27
28
28
31
32
33
39
41
44
45
APPENDIX A Signal Reconstruction (in simulation) using 3rd band
Filter Coefficients
47
APPENDIX B Signal Reconstruction (in simulation) using 5th band
Filter Coefficients
52
4
APPENDIX C Kaiser Window Program
57
APPENDIX D Hilbert Transform Program
60
APPENDIX E Signal Reconstruction using Hilbert Transform and Mth band
60
APPENDIX F Communication Routines with AIC and Serial Port 0
66
APPENDIX G Comparison of Quantized and Unquantized coefficients
67
APPENDIX H Ploting Program of Quantized Coefficients
69
APPENDIX I Generated Input Signal for Real Time Implementation
70
APPENDIX J Signal Reconstruction (in real time) using 5th Band Filter Coeffs.
71
APPENDIX K Signal Reconstruction (in real time) using 3rd Band Filter Coeffs. 75
APPENDIX L Command File for Linking
79
REFERENCES
80
5
ACKNOWLEDGEMENTS
I would like to express many thanks to my supervisor Dr F. Marvasti for all his advice
and sacrifice of his precious time throughout the course of this project.
I am indebted to many of my colleagues at the King’s College to their helpful
comments to the project.
1
GENERAL DISCRIPTION OF THE PROJECT
1.1 INTRODUCTION
This project is based on reconstructing a nonuniformly sampled signal using Multirate
filter banks. The sampling was performed by decimation at the analysis bank. It is
then transmitted to the synthesis bank (receiving end), where it is interpolated and
filtered for reconstruction purpose. The received signal is corrupted by:
a- Aliasing
b- Amplitude distortion
c-Phase distortion
Thus, inorder to reconstruct the signal to its original form all of the above factors
should be eliminated. At present this is achieved by the use of Polyphase filter banks.
It offers direct means of controlling distortion, that my occur to the reconstructed
signal, by an appropriate design of Mth band low pass filter. The filter coefficients
where obtained by the use of Kaiser window.
6
After developing a reconstruction method by simulation, the real time implementation
will be performed using TMS320C30. The process adopted for signal recovery is
illustrated in fig1.
Acquire data
nnn
Perform nonuniform
decimation
Develop Reconstruction
Method Based on Multirate
Signal Processing
Write Analysis Programs in
C
Obtain Results
Compare The Result With The
Original Signal
No
Signal
Reconstructed
Implement Texas Instruments
7
Yes
Fig.1 Project Layout
1.2 REVIEW OF SAMPLING THEOREM
Since sampling is fundamental to this project , it is beneficial to review the principle
of sampling theorem, and its signal recovery technique.
The sampling theorem for continuous time signals states that, if a continuous-time
signal xa(t) is band-limited   , it can be reconstructed from equally spaced
samples x(n)=xa(nT) (fig 2 a), provided that the sampling frequency 2  T exceeds
the so called Nyquist rate =2. Under this condition, the transform X(ejw) is a
periodic repetition of Xa(j) properly scaled which can be expressed as:
X(ejw) =
1
T

 X  j 
k 
a
j 2k
T

w = T
The signal xa(t) can be recovered from x(n) merely by low pass filtering the impulse

train
 x n t  nT  , which results in elimination of the unwanted copies of the
n
basic spectrum Xa(j) in fig 2 (b).
Xa(j
8



(a)
X(ejw)



w
(b)
fig 2 (a) Signal recovery. (b) Lowpass filtering
The Second family of sampling is the so-called nonuniform sampling theorem [7].
The basic idea is that the samples of xa(t) can be spaced in an entirely nonuniform
manner (fig 3), provided that the sampling rate averaged over a sufficiently long
period exceeds the Nyquist rate . More precise statements of this theorem can be
found in [7] and the references therein. This result is called the nonuniform sampling
theorem and less formally, the “folk theorem”.
Xa(t)
t
Fig. 3 Demonstration of nonuniform sampling
One of the difficulties of nonuniform sampling is their analysis in time and frequency
domain [9]. For instance, the spectrum of a periodic impulse train is given as :


  t  nT    e
n 
n 
jwnT

1 
   f  Tn 
T n 
where f 
w
2
9
This shows that the Fourier transform of a periodic impulse train is another periodic
impulse train in the frequency domain. However, in general the spectrum of a
nonuniform impulse, is another set of nonuniform impulse i.e.


t  t    e
n 
n
jw
tn  X  f 
n 
Now the value of X(f) is not known in general. It may look like white noise or it may
not be convergent at all [9].
Another problem with a nonuniform discrete system is that the convolution of its
impulse response with an input discrete signal yields a nonuniform set of samples
which is different in nonuniform positions from both the input and the system impulse
response. This indicates that there is no simple reconstruction method as opposed to
lowpass filtering into the uniform sampling case. However, one may ask, why we
consider nonuniform samples of a signal or a system? The answer is that, there are
some applications where there is no choice but to process nonuniform data. For
instance, loss of uniform samples due to channel impairment or noise.
10
1.3 CONCEPT OF MULTIRATE SIGNAL PROCESSING
Multirate processing is basically an efficient technique for changing the sampling
frequency of a signal digitally. Its main attraction is that it allows the strengths of
conventional DSP to be exploited. For example, the implementation of narrow-band
digital FIR filters using conventional DSP poses a serious problem, because such
filters require a very large number of coefficients to meet their frequency response
specification. The use of multirate techniques leads to very efficient implementation
by allowing filtering to be performed at much lower rate, which greatly reduces the
filter order.
The process of decimation and interpolation are the fundamental operations of
multirate signal processing, and they allow the sampling frequency to be decreased or
increased without significant, undesirable effects of errors such as quantization and
aliasing. This has been reported by Rabiner and Croucher [8].
11
One of the applications of multirate processing is digital audio which takes advantage
of multirate techniques to avoid the use of anti-aliasing analogue filters, and to handle
efficiently signals of different bandwidths, which require different sampling
frequencies.
2
POLYPHASE FILTERS
Polyphase filters are used in Multirate signal processing, and generally they are
known as polyphase networks. This chapter will highlight its representation and
implementation techniques.
2.1 POLYPHASE REPRESENTATION
To explain the basic idea, consider a filter

H ( z) 
 h( n) z
n
(1)
n 
By separating the above equation into even and odd parts, we can rewrite it as

H ( z) 
 h( 2n) z
n 
2n
z
1

 h(2n  1) z
n
(2)
n 
The first element on right hand side of (2) is the even coefficients of h(n) and the
second element is the odd coefficients of h(n). This is defined as:
12

E
0
 h( 2n) z
( z) 

n
E ( z)   h(2n  1) z
;
1
n 
n
(3)
n 
We can therefore write H(z) as
H ( z) 
1
2
2
E (z )  z E (z )
0
(4)
1
The quantities of E0(z) and E1(z) are called the polyphase components of H(z). Now,
representing H(z) in the M-component polyphase form yields
M 1
H ( z) 
 z E (z
k
M
K
k 0
)
(5)
Once again E K ( z) are called the polyphase components and the coefficients of E k ( z )
are given by
e (n)  h(nM  k ) ,
0  k  M 1
k

where
E
k
( z) 
 e ( n) z
n 
(6)
n
(7)
k
In other words, the impulse response h(n) has now been grouped into M-sub
sequences
e (n) . The kth sub sequence e (n)
k
k
is merely the M-fold of decimated
version of h(n+k).
The above representation in (5) is called “type 1” Polyphase (with respect to M) [1].
There is second type of polyphase called “ type 2” polyphase. This is a variation of
(5) and is given by
13
M 1
H ( z) 
z
 ( M 1 k )
k
k 0
R
k
R (z
( z) is related to
E
k
M
)
( z ) by
(8)
R
k

E
(9)
M 1 k
For this project type 1 will be used.
2.2 POLYPHASE IMPLEMENTATION
Consider fig 5 where the input signal x(n) is a low pass signal band limited to
0  w  L M , where L and M are the integers with L< M. It is then possible to
perform a nonuniform decimation of x(n). This can be achieved as follows: divide the
time axis into segments of lengths M, and retain only L samples in each segment. In
other words we discard ML samples. Thus the retained samples are
x (nM  k ),0  k  L  1 . This can be demonstrated as follows (fig. 4): Let M =3 and
L=2.
x(n)

n
0 1 2 3 4 5
(a) Input data
6 7
8
14

n
0
2
3 5
6
8
(b) Output from analysis bank
Fig. 4 Nonuniform sampling mechanisation process.
From the above example illustrates that the analysis bank transmits the following
samples of x(n): x(0) x(2) x(3) x(5) x(6) x(8), which means that for every three
samples two are retained.
The decimators and interpolators create aliasing and imaging respectively. This is
because decimating of a signal causes compression in time domain, which results a
stretching in the frequency domain. On the other hand, interpolating a signal is
stretching in time domain, which results a compression in the frequency domain.
~
Therefore the reconstructed signal X ( z) is a linear combination of the original signal
l
X(z) as well as alias components X ( zW ) , i.e.
~
X ( z) 
M 1
 A ( z) X ( zW
l 0
l
l
)
(10)
where [2]
1
Al ( z)  M
L 1
z W F
k
kl
k 0
k
( z ),0  l  M  1
(12)
If we choose the filter banks F k ( z ) to cancel the aliasing terms , then we have
~
X ( z)  T ( z) X ( z) , where
15
L 1
1
k
T ( z )  A0 
  z F k ( z)
M k 0
(13)
is called the “distortion function” or the overall transfer function of the system.
Ideally T(z) is preferred to be a delay , i.e. T(z) = z  n0 so that the reconstructed signal
is a delay version of the input signal. But generally is not a delay, it represents a
distortion, that is why it is called distortion function.
Once the aliasing errors have been eliminated by the choice of synthesis filters, the
reconstructed signal will suffer from two other errors: amplitude distortion |T(ejw)| and
phase distortion arg |T(ejw)|. How these errors can be eliminated will be discussed in
section 2.3.
Input signal
Coding, transmission and decoding
x(n)
Zn0
M
Zn
M
ZnL
M
Analysis Bank
 
X(nM)
X(nM)
X(nML)
L
F  z
L
Fz
L
FLz
Synthesis Bank
x(n)
output
signal
Fig. 5 Nonuniform Decimation and Reconstruction Scheme
16
2.3 PRACTICAL IMPLEMENTATION FOR SIGNAL RECONSTRUCTION
If H(z) has the ideal response (see fig.6) , then aliasing is completely eliminated and
x (n) =x(n). But in real time H(z) is a non-ideal
the distortion function T(z) =1, i.e. ~
filter, therefore aliasing is cancelled by approximation. T(z) not equal to one (T(z)1)
will result an amplitude and phase distortion.
The phase distortion can be eradicated easily by choosing H(z) to be FIR linear phase
filter with symmetry impulse response. As for the amplitude distortion, it is directly
governed by the passband ripple of H(z). For this reason it is preferred to design a
filter with minimum passband ripple. The design technique for such a filter will be
discussed in chapter 3.
However, the set of the synthesis filters which results in perfect recovery (i.e.
~
x (n) =x(n)) for all inputs x(n) band limited to w  L M is given by the following
equation.
f ( z) 
1
M
 F ( z) z
0
1
F ( z).... z
1
 ( L 1)
F
L 1
( z)

(14).
17
H(ejw)
1
L


L
w

Fig. 6 Ideal lowpass prototype.
3
FILTER DESIGN TECHNIQUE
Since the aim of the project is signal reconstruction, it is important to choose the most
efficient filters that will fulfil the objective. Mth band filters was chosen for this task.
Thus, in this chapter will be discussed design procedure of the filter and its
implementation.
3.1 Mth BAND FILTER
Mth band filter is extension of half band filter and is used to M-band filter banks. It is
a linear phase FIR filter with symmetric impulse response satisfying


1
n=0
(18)
h( Mn)  
M
 0
This means that the impulse response of the filter should be constant for h(0)= 1/M,
and should be zero when ever a nonzero of n is multiple of M  e.g. for M=3: h(3)=0,
h(6)=0, h(9)=0,…..h(3n)). These are the characteristics of Mth band filter.
18
Representing the filter in polyphase format yields:
M 1
H ( z) 
 z G (z
k 0
k
M
k
)
(19)
We can rewrite (19) as
H(z)= c + z G1 (zM) + z2 G (zM) +……+ z(M1) G (zM)
(20)
where c=1/M is constant.
It was found that one of the simplest Mth band design method which guarantees its
property, is the windowing technique (Kaiser window) in which coefficients are
obtained as
 n 
h(n)  sin M  w(n)
 n 


(21)
where w(n) is the finite duration of Kaiser window.
The desired stopband attenuation and transition bandwidth for H(z) can be obtained
by the choice of the window length and a window parameter called beta  [4].
Alternatively, the value of  is determined by the stopband attenuation requirements
and may be estimated from one of the following relationships [15]:
=0
 = 0.5842(A  21) + 0.07886(A  21)
 = 0.1102(A  8.7)
if A< 21 dB
if 21 dB < A < 50 dB
if A > 50 dB
(22a)
(22b)
(22c)
19
where A = 20 log() is the stopband attenuation, and  represents the stopband  and
the passband ripples . Because both p and s are equal for window design. The
number of filter coefficients N, is given by
N > A  7.95/ 14.36 f
(22)
where f is the normalised transition width.
The advantage of this window method is that the condition (18) is automatically
satisfied, because [sin ( n/M)]/n is zero when ever n is nonzero multiple of M.
3.2 FILTER DESIGN SPECIFICATION
M=3, L=2 and M=5, L=3 will be used for analysis and synthesis banks. Mth band
lowpass filter with following specifications will be used for signal reconstruction,
both in simulation and real time.
Filter Parameters
3rd Band
5th Band
1- Sampling frequency fs
8000 Hz
8000 Hz
2- Passband edge frequency fp
1333.333 Hz
800 Hz
3- Stopband ripple
0.00178
0.00316
4- Passband ripple
0.00178
0.00316
5- Beta
5.1
4.55
6- Stopband attenuation
55 dB
50 dB
7- Transition width
425 Hz
250 Hz
8- Filter length
61
93
20
The filter coefficients, have been obtained using Kaiser window (see appendix C).
The filter responses are shown on page 17 (fig. 7). It illustrates lowpass filters with
minimum passband ripples. This is the advantage of using Kaiser window, because it
provides a direct control of the passband ripples by choosing suitable value of .
For perfect signal recovery, the filter banks should be capable of eliminating: the
aliasing, amplitude and phase distortions. These are the main factors that the output
signal from the synthesis bank suffers.
The input signal x(n) to the analysis bank is shown in fig 8. It is the form of integer
(discrete) format used only for simulation purpose. The nonuniformly decimated and
reconstructed signals are illustrated on page 18. The programs used were shown in
appendices A and B. A simplified flow chart for the software implemented is
illustrated on page 19.
21
22
Fig. 7 Filter responses for 3rd and 5th bands.
(a) Nonuniform decimation of the input signal
23
(b) Reconstructed signal.
Fig 8. Plots for analysis and synthesis banks of the system.
Start
Read New Input Data
Update The Delay Line
With New Input Data
Perform Nonuniform
Decimation
M Samples
Obtained
No
Yes
Interpolate
Perform Polyphase Filtering
Compute Output Samples
No
Signal
Reconstructed
24
Yes
END
Fig 9. Software implementation of signal reconstruction
4
HIlLBERT TRANSFORM WITH Mth BAND
For the purpose of comparison a Hilbert transform with Mth band filter [12] will be
used to reconstruct the signal. The analysis bank (nonuniform decimation) is similar
to the previous case. Thus we should concentrate only the synthesis bank.
4.1 DESCRIPTION OF SYNTHESIS BANK
x ( n ) can be
The relationship between the input signal x(n) and reconstructed signal ~
expressed [12]:
1
~
X ( z) 
M
M 1
M 1
 X ( zW )  H k ( zW ) F k ( z)
m
m 0
m
(1)
k 0
Which means the reconstructed signal consists of linear combination of X(z) (original
signal) and alias components X(zWM).
The right hand side of equation (1) can be expressed in matrix format shown in (2) to
cancel out the alias components.
25
 H 0 H 1 ...... H M 1 ( z )



 H 0 ( zW ) H 1 ( zW ).... H M 1 ( zW )



.

.



M 1
M 1
M 1
 H 0 ( zW ) H 1 ( z W ).... H M 1 ( z W ) 
Where W  e
j
L
M
 F 0 ( z)   M
( z)

  T0 
 F 1 ( z )  0

.
 = .


 

.
 .


 


 F L 1 ( z )  0
(2)
and T(z) is the distortion function.
The matrix H(z), is formulated in [5] and it is commonly called alias-component
matrix (AC matrix). If Hk(z) and Fk(z) are chosen such that T(z) is equal to a delay,
x ( n ) = cx(n – n0) then the system has perfect reconstruction property [2], [6].
then ~
Inorder to compare with the polyphase reconstruction technique, discussed in chapter
3, we choose M=3 L=2. Then equation 2 yields:
H(z)F(z) + H1(z)F1(z) = 3
(3)
H0(zW)F0(z) + H1(zW)F1(z) = 0
H0(zW2 )F0(z) + H1(zW2)F1(z) =0
Because of the band limited nature of X(z), the quantity of X(zW m) only occupies the
region of 0<w<L2/M. Then (3) yields, after some mathematical manipulation [12]:
1
1
F(ejw)
1
W
ejw F(ejw)
1
1
F0 (ejw)
1
W
ejw F1 (ejw)
2
3
(4a)
2
w0
3
(4b)
0 L
= 3
0
and
= 3
0

26
Solving the two equations and multiplying the solution with ejw to avoid
noncausality, we get
F0 (ejw) = ejw (1  c  js)
ejw(1 c + js)
0
0<W<2/3
-2/3<W<0
otherwise
(5a)
F1 (ejw) = (1  c  js)
(1 c + js)
0
0<W<2/3
-2/3<W<0
otherwise
(5b)
where c = cos(2/3)
s= sin(2/3)
4.2 IMPLEMENTATION OF SYNTHESIS FILTER
The above solution can be expressed practically by lowpass GL and Hilbert transform
GH filters, which can be expressed ideally ( fig. 10) as:
GL(z)= 1
0
w< 2/3
otherwise
(6)
GH (z)= +j
-j
0< w < 
- < w < 0
(7)
Then the synthesis filters in (5a) and (5b) yields
F0 (z)= z (1 - c + sGH (z))GL(z)
(8)
F1 (z)= (1- c – sGH (z)) GL(z)
(9)
The Hilbert transform GH controls the extent to which aliasing has been cancelled in
the range w< 2/3 where as the lowpass filter suppresses the aliasing in the range
w  > 2/3. The lowpass filter was chosen to be the 3rd band with zero phase and
distortion was controlled by the passband ripple. Fig. 11 represents the
implementation for nonuniform decimation and reconstruction of the signal.
27
GL(ejw)
GH(ejw)
1
j
0



w
w
j
Fig. 10 Ideal filters of GL(ejw) and GH (ejw)
x(n)
M
M
M
M
1 c
z
zk
z
GH(z)

~
x (n)
s
Analysis Bank
GL(L)
Synthesis Bank
Fig. 11 Nonuniform decimation and reconstruction using Hilbert and Mth band
filters.
4.2.1 FILTER SPECIFICATION
As mentioned in the previous section the lowpass filter was chosen to be 3rd band
filter, thus the specification is similar to the one described in section 3.2. The Hilbert
transform ( fig 12) has following features implemented in Matlab (see appendix D):
Passband edge wp
0.035
Stopband edge ws
0.29
Filter order N
93
28
The coefficients generated by the Matlab with the lowpass 3rd band filter, were used
for signal reconstruction (see appendix E). The result is shown in fig 14.
GH(z)
0
w
wp
ws

Fig. 12 Definition of bandedges for real Hilbert transformer.
The combination of Hilbert transform with Mth band lowpass filter are not the best
way for signal recovery. Because they require more computation and memory, than
using only Mth band lowpass filter for signal reconstruction. Also they are more
complex. Therefore, it is not the first choice.
A simplified flowchart for the lowpass and Hilbert transform software implementation
is shown on page 25.
29
Start
Read New Input Data
Update The Delay Line
With New Input Data
Perform Nonuniform
Decimation
No
M Samples
Obtained
Yes
Interpolate
Perform Hilbert Transform
Filtering
Perform Mth Band Filtering
Compute Output Samples
30
No
Signal
Reconstructed
Yes
END
Fig. 13 Software Implementation of Mth Band & Hilbert Transformer Filters.
(a)
Hilbert transform filter response
(b) Comparison
of input signal with the reconstructed signal
31
Fig. 14 Hilbert transform with lowpass Mth band filter used for signal reconstruction.
5
REAL TIME IMPLEMENTATION
This chapter will deal with all the necessary mechanisms which enable us to
transform the simulation work into real time implementation using Texas instrument
(TMS320C30) DSP card.
5.1 THE ARCHITECTURE OF TMS320C30
The TMS320C30 is a 32 bit digital signal processor, capable of performing floating
point, integer and logical operations. Its architecture allows four levels of pipelining.
While an instruction is being executed, the next three instructions are being
consequently fetched, decoded, and read. Many instructions can be executed in
parallel, such as load with store, multiply with add and so on [13].
Two serial ports, two timers, and a on-chip direct memory access (DMA) controller
for I/O are available on the TMS320C30. These features are controlled through
memory-mapped registers, to communicate or to interface with the outside world.
The two serial ports available, serial port 0 and serial port 1, are totally independent,
each with a set of control registers. Serial port 0 is used for the on-board Analog
Interface Chip (AIC), and serial port 1 is available through the EVM, where it can be
used to connect to an alternative I/O devices.
32
5.2 THE ANALOG INTERFACE CHIP (AIC)
The AIC is the TLC32044, a member of the TLC32040 family of voice band analog
interface circuits, which is on the evaluation module (EVM).The AIC supports two
input channels and one output channel. However, the specific AIC on board the EVM
has one of its input connected to ground [14]. The functional block diagram of the
AIC is shown in fig 15 (see page 30).
The AIC includes analog-to-digital converter, digital-to-analog converter, switched
capacitors antialiasing input, and reconstruction output filters, constructed on a single
C-MOS chip. Both A/D and D/A converters have 14 bits of resolution. The lowpass
and highpass input filters of the AIC are programmable. The output filter is related to
the lowpass input filter settings. Its function is to smooth out the step level signals
from the D/A and reconstructs an equivalent analog signal based on the step levels.
5.3 AIC CONTROL
The data transmission occurs through two of the AIC serial ports registers, the data
receive register (DR) and data transmit register (DX). The AIC is controlled through
the data transmit register. The two least significant bits are used for communication
function. The normal transmission occurs with the two LSB being 0s, and secondary
is initiated with the two LSB being 1s.
33
The secondary communication mode initialises and controls the AIC, allowing one
secondary transmission before switching back to the communication mode. Control
functions are initialised by writing to several registers in the AIC.
The control registers specifies the input port, the input filter, the input voltage level,
and the activation of a loopback test.
The AIC has internal timing configuration [10]. The letters A and B designate the
location of control, with A representing a filter control register and B the analog-todigital (A/D) and digital -to-analog (D/A) control. The TA and RA registers divide the
system clock to the switched capacitor filter frequency, and TB and RB further divide
the switched capacitor filter frequency down to the sampling rate frequency.
The bit locations for the transmit and receive registers are:
0,0
bits 0 and 1
RA
bits 2 -6
don’t care (x)
bits 7-8
TA
bits 9-13
don’t care (x) bits 14-15
The bit locations for the transmit and receive TB and RB are:
0,1
bits 0 and 1
RB
bits 2-7
don’t care(x)
bits 8
TB
bits 9-14
don’t care (x)
bit 15
34
The AIC can be configured for a specific sampling rate and filter bandwidth (filter
cut-off) by requesting AIC secondary communication and loading a 1 in the first two
LSBs. The technique to implement will be discussed in following sections.
5.4 INTERRUPTS
The TMS320C30 supports a nonmaskable external reset signal, as well as internal and
external interrupts, which can be used to interrupt the CPU or the DMA. Interrupt
handlers in C are such that no arguments should be passed to or from a function. An
interrupt function should be declared with the following format so that the C compiler
can use a specified register preservation requirement: c_intnm, where nm is two digit
number between 00 and 99 [13].
On the other hand, an interrupt function should not be called directly. Instead, the
address of address of the function should installed in the appropriate interrupt vector
location. The following function can be used to install an interrupt function:
1. #define VEC_ADDR (volatile int *) 0x00;
2. volatile int *INTVEC = VEC_ADDR;
3. INTVEC[5] = (volatile int) c_int05;
where the beginning address of the vectors is defined in the instruction. The second
instruction uses a pointer to install the function, and the third instruction is to install
the address of the function at 0x05. These instruction are shown in the real time
software.
35
5.5 AIC COMMUNICATION ROUTINES WITH SERIAL PORT 0
This section will be outline the program “aiccom.c” (see appendix F) used for
initialisation, configuration of the AIC, and communication routines with serial port 0.
The TMS320C30 AIC data configuration list shown in table 1 [14] are used to build
the structure of the file “aiccom.c”. From the table we note the following :
1- The timer period register 0x808028 is set to 1, the timer global register is set with
the control value 0x2C1. Bit 2 of the IOF flag register is set to 1. The wait loop is
used to keep the IOF low for some period of time (recommended by the Texas
Instrument).
2- The transmit, receive, and serial port global control register at 0x808042,
0x808043, and 0x808040, respectively are initialised.
3- The serial port data transmit register at 0x808048 is initialised to zero. The AIC is
enabled by setting the IOF register high.
4- The AICSET function is accessed to initialise the AIC, where the AICSET_I
function is accessed to configure the AIC at the interrupt driven.
5- For input and output, the data receive register at 0x80804C and the data transmit
register at 0x808048 are used.
ADDRESS
0x808028
0x808020
IOF
0x808042
0x808043
REGISTER
Timer 0 period
Timer 0 global control
I/O flag
SP0 transmit port control
SP0 receive port control
COMMAND
Load 0x00000001
Load 0x000002C1
Load 0x00000002
Load 0x00000111
Load 0x00000111
36
0x808040
0x808048
IOF
IF
IE
ST
SP0 global control
SP0 data transmit
I/O flag
Interrupt flag
Interrupt enable
Status register
Load 0x0E970300
Load 0x00000000
Load 0x00000006
Load 0x00000000
OR with 0x00000010
OR with 0x00002000
Table 1 AIC data configuration
5.6 RESULTS OBTAINED
In real time implementation one needs to consider coefficient quantization errors,
which cause the frequency response to deviate from the desired response. This
deviation will mean that the specification is no longer met. To maintain the
specification, we need to study the filter response after coefficient quantization,
although it has been suggested [15] that the filter coefficients obtained by the Remez
exchange (optimal) or window method are usually very accurate to several place of
decimal. This can be achieved by multiplying each coefficient by 231, since
TMS320C30 is 32 bits, and rounding up to the nearest integer. To check the
frequency response has not been deviated from the desired response, both the
quantized and unquantized coefficients obtained for the 5th band lowpass filter, with
the specification obtained in section 3.2, are listed in appendix G. The frequency
response for both cases ( see fig.16  appendix H) shows no difference between the
two.
Alternatively, we can estimate theoretically the increase in passband ripple and
reduction in stopband attenuation for the quantized filter response. Using the upper
bound for error estimation [15], | E(w) | = N 2B , the worst case of passband ripple
increase yields:
37
Pass_ripplemax = 20 log(1 + p + | E (w) | = 20 log(1 + 0.00316 + 2x10) = 0dB
that is zero increase of passband ripple.
Amax = 20 log ( s + | E(w) | ) =  20 log (0.00316 + 2x10) = 50 dB
that is no reduction of stopband attenuation.
Therefore, the filter coefficients (Mth band) obtained by the Kaiser window perform
equally well in real time application and simulation.
The process adopted for real time software development and its implementation are
illustrated in flowcharts (fig 17 & 18).
During the practical implementation we wished to apply an input signal, using Pseudo
random generator, to the input of the Evaluation mode (EVM C30), for the purpose of
signal reconstruction. Unfortunately the department of Electronic engineering did not
have such machine. An alternative approach was adopted to generate a known signal
with bandwidth of 3800 Hz (see fig. 18  appendix I), and apply in to the EVM as an
internal input signal. Knowing the shape of the input signal, enabled a comparison to
be made with the output signal from the DSP card.
However, since there is no external input signal into A/D converter on board the
EVM, still we had to set the bandwidth and the sampling rate frequencies for the
A/DD/A converters for reconstruction purpose. This is achieved by calculating the
register values A and B (see section 5.6.1), where A is representing filter control
register and B represents A/D  D/A control register.
38
39
Fig. 16 Comparison of quantized and quantized filter responses.
Write implementation
program
Compile & Link
Create memory map
for debugger
Load the files with .out extention
on debugger and run.
No
Program is
running OK
Yes
40
Develop communication
routine programs between
the AIC and the DSP card
Fig. 16 Software development for real time implementation.
Initialize AIC
Configure AIC
Setup secondary
communications
Load programs
on DSP card
Load data
Read data, x(n) and
update data memory
Perform signal
reconstruction
41
Investigate
No
Yes
END
Fig 17 Real time implementation approach.
42
Fig 18 The generated input signal with the frequency spectra.
5.6.1 CALCULATING THE VALUES A & B FOR DESIRED SAMPLING
AND CUTOFF FREQUECIES
TMS320C30 has 30MHz input clock which can generate a maximum frequency of
7.5 MHz master clock (MCLK)  i.e.
MCLK = CLKIN / 4 = 7.5 MHz
(1)
The specified maximum frequency for the AIC is 10MHz. Thus, 7.5MHz is within
the range of maximum performance. Also, there is switched capacitor filter (SCF)
related to the filter control register A, which can be calculated as:
SCF = MCLK / (2 x TA)
(2)
The desired sampling frequency is related to the registers A and B as shown in (3).
Fs = MCLK / (2 x TA x TB)
(3)
43
Note, the lowpass filters of the AIC is set to 3600 Hz bandwidth (Fc) and its switched
capacitor filter (SCF) is set to 288 kHz [10]. These settings will be taken into account
to calculate the register values A and B, for the desired sampling and cutoff
frequencies of 8 kHz and 4 kHz respectively. Hence, the new SCF yields:
SCF = Fc (set SCF / set Fc) = 4000 (288 kHz / 3600 Hz) = 320 kHz
From (2) & (3) we calculate registers TA and TB respectively as:
TA = MCLK / 2 x SCF = 7.5 MHz / 2 x 320 kHz = 12 =(01100)b
TB = MCLK / (2 x TA x Fs ) = 7.5 MHz / 2 x 12 x 8000 = 39 = (100111)b
The next step is to find the values for the secondary communications. This is
accomplished by setting TA = RA with five bits for TA, six bits for TB = RB, and x
for don’t care bits  see section 5.3 for bit locations.
Hence,
00 01100 00 01100 00
xx | TA | xx | RA |
Separating the bits and grouping into 4 bits, A = 1830h.
Similarly, B yields:
0 100111 0 100111 10
x | TB | x | RB |
Now we group the bits into four, thus B = 4E9Eh
The calculated register values (A&B) have been used for AIC configuration in signal
reconstruction programs  see appendixes J and K. The second value 0x1, set in
44
AICSEC array in the program, is used for fine tuning the sampling frequency through
the registers TA and RA available on the AIC [10]. Also the last value 0x67 in
AICSEC, specifies the primary input (IN) to the AIC.
The output signal was displayed on oscilloscope, and is identical to the input signal
(fig 18). This means that the signal was reconstructed to its original form. Due to lack
of printing mechanism of the oscilloscope, the output signal cannot be shown in the
report.
6
CONCLUSION
The use of polyphase filter banks has provided an efficient reconstruction of the bandlimited signal at the cost of Mth band filters. This has offered direct control over the
amplitude distortion by control of the passband ripple for the reconstructing filter. The
polyphase also has reduced the amount of the computation required compare to the
conventional FIR  see section 6.1. On the other hand, the structural arrangements
provided by this system may be compared with the well known “fractional sampling
rate alteration”  see fig 19. This would have been more computationally complex
than the present system for signal reconstruction. Because it would have required
analysis as well as synthesis filter banks, using conventional FIR.
45
The draw back of this system is that it does not offer direct control over the
attenuation introduced by the alias component transfer function Al(z) (12), even
though the attenuation improves as the desired filter gets to the ideal one. This is
because it is not clear how the prescribed specification on this attenuation can be
satisfied optimally during the design of the filter H(z).
The combination of lowpass Mth band and Hilbert transform (chapter 4) performs the
elimination of alias terms hand-in-hand. That is the low pass filter eliminates the outof-band alias terms, where as the Hilbert transformer cancels the in band aliasing
terms. To illustrate how the Hilbert transformer cancels the in band aliasing, I
designed a poor Hilbert transform with N=12, wp=0.04 and ws=0.26 (see fig. 20),
with the same 3rd band filter specified on section 3.2. The reconstructed signal shows
how the alias terms affect the signal due to the imperfect Hilbert transform. We can
also deduce that imperfection of the Hilbert transform does not affect the distortion
function, which is controlled by the Mth band filter.
The overall advantage of this system is that it provides a compression technique based
on nonuniform subsampling with very a simple computation. The only price paid is
that the implementation of filters Fk(z), at the synthesis bank, for signal reconstruction
stage. This could provide an attractive application where a transmitter requires low
computation, where as the receiver (e.g. ground station) has more resources for signal
retrieval.
46
x(n)
L
H(z)
M
M
y(n)
Fig 19 Fractional Decimation and reconstruction
(a) Poor Hilbert Transform.
H(z)
L
V(n)
47
(b) Comparison of input and output signals.
Fig. 20 Performance of poor Hilbert transform
6.1 MEMORY SAVING OF POLYPHASE FILTERS
Suppose if we have
implemented H(z) as a conventional FIR of length N, to
reconstruct the input signal ,say with M=2 (fig 21 (a)), then the system has to compute
the even numbered output samples. For each computed sample we require N
multiplication and N-1 additions.
Now, assume that x(n) is arriving in real time at the rate of one sample per unit time.
The scheme of fig (a) would then require that the N multiplications and N-1 additions
to be performed in one unit of time. Because as the next sample arrives, the internal
delay elements z are updated to new set of values. So whenever y(2n) is being
computed, the system is working at the rate of MPU (multiplication per unit time) and
N-1 APU (addition per unit time).Where a unit of time is the separation between the
samples of the input signal x(n).At odd intervals the system is sitting idle, because
y(2n+1) need not to be computed. This is clearly an inefficient use of computing
resources.
On the other hand, if we implement the system in polyphase decimation form, (fig.
21(b) ), where E(z) and E1(z) are receiving the sample at a half rate (i.e. one sample
in two units of time). We therefore need to perform only N/2 MPUS and (N-1)/2
APUs on the average. Thus the polyphase representation is a neat tool which enables
us to rearrange the computation of the filtering operation, so as to minimise the
computational load per unit. Looking at it in another way, each multiplier in fig (a) is
48
required to complete its operation in one unit of time, where as in fig(b), two units of
time are available for the same job.
x(n)
h(0)
h(N )
h(1)
y(2n)
2
(a) conventional FIR.
x(n)
2
E1(z)
z
2
y(2n)
E1(z)
(b) Polyphase structure.
Fig 21 Comparison of conventional FIR and polyphase filters.
6.1.1 ESTIMATION OF COMPUTATIONAL COMPLEXITY
Another way of measuring the complexity of the system is to compute its multiplies
per second (MPS). This can be shown by comparing the conventional FIR with the
polyphase implementation.
The computational complexity for FIR is defined [8]:
CFIR = N x F MPS
(1a)
Where N is the number of filter coefficients and F is the input sampling rate. For
symmetry:
CFIR = (N/2) x F MPS
(1b)
49
In the case of polyphase [8]:
CPoly = 2 x N x (F/M) MPS
(2a)
Where M is the decimation rate.
For symmetry :
CPoly = 2 x (N/2) x (F/M) MPS
(2b)
Calculating the MPS for M=5 and N = 93 using (1b) and (2b) yields:
CFIR = (93/2) x 8000 = 372,000 MPS
CPoly = 2 x (93/2) x (8000/5) = 148,800 MPS
Similarly for M=3 N= 61
CFIR = (61/2) x 8000 = 244,000 MPS
CPoly = 2 x (61/2) x (8000/3) = 162,667 MPS
The above calculations shows how polyphase networks are more efficient than the
conventional method.
50
APPENDIX A
/*------------------------------------------------*/
/*
Nonuniform sampling and reconstruction
*/
/*
using 3rd band filter coefficients
*/
/*------------------------------------------------*/
#include
#include
#include
<stdio.h>
<math.h>
<dos.h>
#define
npt
void
void
void
void
void
100
init_arrays();
read_coeffs();
decimator_interpolator_spec();
analy_synth_channel1();
analy_synth_channel2();
float y1[npt], y2[npt],y3[npt],b[npt],w[npt];
float
x1[npt], x2[npt],x3[npt],x4[npt],h[npt];
long m,l,n1,mm=0;
long M,L, ndata=0;
int xn;
FILE *in,*out, *fopen();
char din[30], fname1[30];
main()
{
clrscr();
init_arrays();
/* initialise coeffs and data arrays */
read_coeffs();
decimator_interpolator_spec(); /* ask user for decimation and*/
/* interp. Specification */
while(fscanf(in,"%d",&xn)!=EOF)
{
analy_synth_channel1();
analy_synth_channel2();
++ndata;
}
printf("number of data points in input file \t%ld \n",ndata);
printf("number of data points stored in output file\t%ld\n”,mm);
fclose(in);
fclose(out);
printf(" PRESS ANY KEY TO EXIT\n");
getch();
exit(0);
}
51
/*----------------------------------------------------------------*/
/*
DATA AND COEFFICIENT ARRAYS INITIALISATION FUNCTION
*/
/*----------------------------------------------------------------*/
void
{
init_arrays()
long i;
for(i=0; i < npt; ++i){
x1[i]=0;
h[i]=0;
x2[i]=0;
b[i]=0;
x3[i]=0;
w[i]=0;
x4[i]=0;
y1[npt]=0;
y2[npt]=0;
y3[npt]=0;
}
}
/*-----------------------------------------------------------------*/
/* FUNCTION CALLING THE FILTER COEFFICIENTS
*/
/*----------------------------------------------------------------*/
void read_coeffs()
{
n1=0;
printf("Enter the filter coefficients file name 3rd.DAT\n");
scanf("%s",fname1);
if((in=fopen(fname1,"r"))==NULL)
{
printf("Filter coeffs file not found\n");
getch();
exit(1);
}
while(fscanf(in,"%f", &h[n1])!=EOF){
++n1;
}
printf("Filter length is %ld\n",n1);
--n1;
fclose(in);
}
/*-----------------------------------------------------------------*/
void
decimator_interpolator_spec()
{
printf("Enter name of file holding data DTEST2.DAT ");
printf("for nonuniform sampling and reconstruction \n");
scanf("%s",din);
52
printf("\n");
printf("The reconstructed data will be stored in **OUT.DAT2\n”);
printf("\n");
printf("Enter decimation factor\n");
scanf("%ld",&m);
printf("Enter the expanding factor\n");
scanf("%ld",&l);
M=m;
L=l;
/* decimation factor */
/* expanding factor */
if(L>=M){
printf(" Out of range for signal reconstruction\n");
printf(" Pleas try again\n");
getch();
exit(1);
}
if((in=fopen(din,"r"))==NULL)
{
printf("error reading input data file\n");
exit(1);
}
if((out=fopen("out.dat2","w"))==NULL)
{
printf("cannot open output data file\n");
exit(1);
}
}
/*-----------------------------------------------------------------*/
/*
ANALYSIS AND SYNTHESIS BANK
*/
/*----------------------------------------------------------------*/
void
{
analy_synth_channel1()
int xnew,y1,y4;
double
y;
long j,i,k,v,N2,z;
/*******************************************************************/
/*
Analysis bank performing nonuniform decimation
*/
/*----------------------------------------------------------------*/
xnew=xn;
for(j=1; j<=L; ++j){
k=L-j+1;
x1[k]=x1[k-1];
}
x1[0]=xnew;
M=M - L;
while(M>0){
return;
}
/* xnew holds the input data*/
/* update
delay line */
53
M=m;
y1=x1[1];
/******************************************************************/
/*
Synthesis analysis for signal reconstrution using polyphase
filter */
/* ----------------------------------------------------------------*/
L=l;
for(i=0; i<M-L; ++i)
{
x2[i]=y1;
y=0;
v=i;
while(v<=n1)
{
y=y +h[v]*x2[v]; /* filtering
v=v+M;
}
*/
xnew=0.0;
for(N2=1; N2<=L-1; ++N2)
/* update delay line */
{
z=L-N2+1;
x3[z]=x3[z-1];
}
x3[0]=y;
b[i]=x3[0];
y4=b[i]*M;
fprintf(out,"%d\n",y4); /* interleaving output data */
}
}
/*-----------------------------------------------------------------*/
/*
ANALYSIS AND SYNTHESIS BANK F1
*/
/*-----------------------------------------------------------------*/
void
analy_synth_channel2()
{
int xnew, y2,y5;
long j,i,v,k,N2,z;
double y;
/*******************************************************************/
/*
Analysis bank performing nonuniform decimation
*/
/*-----------------------------------------------------------------*/
xnew=xn;
for(j=1; j<=L; ++j)
{
k=L-j+1;
x1[k]=x1[k-1];
/* update delay line */
54
}
x1[1]=xnew;
M=M-L;
while(M>0)
{
return;
}
M=m;
y2=x1[1];
/*****************************************************************/
/*
Synthesis analysis F1 for signal reconstruction
*/
/*---------------------------------------------------------------*/
L=l;
for(i=0; i<M-L; ++i)
{
x3[i]=y2;
y=0;
v=i;
while(v<=n1)
{
y=y +h[v]*x3[v];
v=v+M;
}
xnew=0.0;
for(N2=1; N2<=L; ++N2)
{
z=L-N2+1;
x4[z]=x4[z-1];
}
x4[0]=y;
y5=x4[0]*M;
fprintf(out,"%d\n",y5);
++mm;
}
}
/* perform filtering */
/* update delay line
*/
/* interleaving output data*/
55
APPENDIX B
/*------------------------------------------------*/
/*
Nonuniform sampling and reconstrution
*/
/*
using 5th band filter coefficients
*/
/*------------------------------------------------*/
#include
#include
#include
<stdio.h>
<math.h>
<dos.h>
#define
npt
void
void
void
void
void
100
init_arrays();
read_coeffs();
decimator_interpolator_spec();
analy_synth_channel1();
analy_synth_channel2();
float y1[npt], y2[npt],y3[npt],b[npt],w[npt];
float
x1[npt], x2[npt],x3[npt],x4[npt],h[npt];
long m,l,n1,mm=0;
long M,L, ndata=0;
int xn;
FILE *in,*out, *fopen();
char din[30], fname1[30];
main()
{
clrscr();
init_arrays();
/* initialise coeffs and data arrays */
read_coeffs();
decimator_interpolator_spec(); /* ask user for decimation and*/
/* interp. Specification */
while(fscanf(in,"%d",&xn)!=EOF)
{
analy_synth_channel1();
analy_synth_channel2();
++ndata;
}
printf("number of data points in input file \t%ld \n",ndata);
printf("number of data points stored in output file\t%ld\n”,mm);
fclose(in);
fclose(out);
printf(" PRESS ANY KEY TO EXIT\n");
getch();
exit(0);
}
56
/*----------------------------------------------------------------*/
/*
DATA AND COEFFICIENT ARRAYS INITIALISATION FUNCTION
*/
/*----------------------------------------------------------------*/
void
{
init_arrays()
long i;
for(i=0; i < npt; ++i){
x1[i]=0;
h[i]=0;
x2[i]=0;
b[i]=0;
x3[i]=0;
w[i]=0;
x4[i]=0;
y1[npt]=0;
y2[npt]=0;
y3[npt]=0;
}
}
/*-----------------------------------------------------------------*/
/* FUNCTION CALLING THE FILTER COEFFICIENTS
*/
/*----------------------------------------------------------------*/
void read_coeffs()
{
n1=0;
printf("Enter the filter coefficients file name 5th.DAT\n");
scanf("%s",fname1);
if((in=fopen(fname1,"r"))==NULL)
{
printf("Filter coeffs file not found\n");
getch();
exit(1);
}
while(fscanf(in,"%f", &h[n1])!=EOF){
++n1;
}
printf("Filter length is %ld\n",n1);
--n1;
fclose(in);
}
/*-----------------------------------------------------------------*/
void
decimator_interpolator_spec()
{
printf("Enter name of file holding data DTEST2.DAT ");
printf("for nonuniform sampling and reconstruction \n");
scanf("%s",din);
57
printf("\n");
printf("The reconstructed data will be stored in **OUT.DAT2\n”);
printf("\n");
printf("Enter decimation factor\n");
scanf("%ld",&m);
printf("Enter the expanding factor\n");
scanf("%ld",&l);
M=m;
L=l;
/* decimation factor */
/* expanding factor */
if(L>=M){
printf(" Out of range for signal reconstruction\n");
printf(" Pleas try again\n");
getch();
exit(1);
}
if((in=fopen(din,"r"))==NULL)
{
printf("error reading input data file\n");
exit(1);
}
if((out=fopen("out.dat2","w"))==NULL)
{
printf("cannot open output data file\n");
exit(1);
}
}
/*-----------------------------------------------------------------*/
/*
ANALYSIS AND SYNTHESIS BANK
*/
/*----------------------------------------------------------------*/
void
{
analy_synth_channel1()
int
xnew, y1 y4;
double
y;
long j,i,k,v,N2,z;
/*******************************************************************/
/*
Analysis bank performing nonuniform decimation
*/
/*----------------------------------------------------------------*/
xnew=xn;
for(j=1; j<=L; ++j){
k=L-j+1;
x1[k]=x1[k-1];
}
x1[0]=xnew;
M=M - L;
while(M>0){
return;
}
/* xnew holds the input data*/
/* update
delay line */
58
M=m;
y1=x1[1];
/******************************************************************/
/*
Synthesis analysis for signal reconstrution using polyphase
filter */
/* ----------------------------------------------------------------*/
L=l;
for(i=0; i<M-L-1; ++i)
{
x2[i]=y1;
y=0;
v=i;
while(v<=n1)
{
y=y +h[v]*x2[v]; /* filtering
v=v+M;
}
*/
xnew=0.0;
for(N2=1; N2<=L-1; ++N2)
/* update delay line */
{
z=L-N2+1;
x3[z]=x3[z-1];
}
x3[0]=y;
b[i]=x3[0];
y4=b[i]*M;
fprintf(out,"%d\n",y4); /* interleaving output data */
}
}
/*-----------------------------------------------------------------*/
/*
ANALYSIS AND SYNTHESIS BANK F1
*/
/*-----------------------------------------------------------------*/
void
analy_synth_channel2()
{
int xnew, y2,y5;
long j,i,v,k,N2,z;
double y;
/*******************************************************************/
/*
Analysis bank performing nonuniform decimation
*/
/*-----------------------------------------------------------------*/
xnew=xn;
for(j=1; j<=L; ++j)
{
k=L-j+1;
x1[k]=x1[k-1];
/* update delay line */
59
}
x1[1]=xnew;
M=M-L;
while(M>0)
{
return;
}
M=m;
y2=x1[1];
/*****************************************************************/
/*
Synthesis analysis F1 for signal reconstruction
*/
/*---------------------------------------------------------------*/
L=l;
for(i=0; i<M-L-1; ++i)
{
x3[i]=y2;
y=0;
v=i;
while(v<=n1)
{
y=y +h[v]*x3[v];
v=v+M;
}
xnew=0.0;
for(N2=1; N2<=L; ++N2)
{
z=L-N2+1;
x4[z]=x4[z-1];
}
x4[0]=y;
y5=x4[0]*M;
fprintf(out,"%d\n",y5);
++mm;
}
}
/* perform filtering */
/* update delay line
*/
/* interleaving output data*/
60
APPENDIX C
/*----------------------------------------------------------------*/
/*
*/
/*
FIR coefficient calculation using Kaiser window
*/
/*-----------------------------------------------------------------*/
#include
#include
#include
<stdio.h>
<math.h>
<dos.h>
#define
pi
void
void
3.14159265
filter_spec();
lowpass_filter();
void sincx1();
/* internal functions */
void window_func();
double
bessel(double);
double
FC, FS, beta;
double
h[200],w[200],hb[200];
int
ftype,ntype,wtype,N,N1,nodd,nflag,iflag;
FILE
*out, *fopen();
/*________________________________________________________________*/
main()
{
int
j;
filter_spec();
/* obtain filter specification */
/* compute ideal impulse response */
lowpass_filter();
window_func();
/* compute the window function */
for(j=0; j< N1; ++j){
h[j]=h[j]*w[j];
fprintf(out,"%f\n",h[j]);
}
exit(0);
}
/*---------------------------------------------------------------*/
/*
*
Function to request filter specifications and window function:
*
*
FS
sampling frequency
*
FC
cutoff frequency for LPF
*
N
number of filter coefficients
*
*/
void
{
filter_spec()
61
printf("enter sampling frequency in Hz\n");
scanf("%lf",&FS);
/* obtain the bandedge frequencies */
printf("enter cutoff frequency in Hz\n");
scanf("%lf",&FC);
FC=FC/FS;
if(FC>0.5){
printf("out of range\n");
exit(1);
}
printf("enter beta for kaiser window\n");
scanf("%lf", &beta);
/* request filter length and determine whether it is odd or even
* for N even only N/2 coefficients need be calculated, and for N odd
* only (N+1)/2 because of the symmetry in h(n).
*/
printf("enter number of filter coefficients\n");
scanf("%d",&N);
N1=N/2;
nflag=1;
if((N-2*N1)==1){ /* N odd */
nflag=0;
N1=N1+1;
}
}
/*------------------------------------------------------------------* function to compute the ideal impulse response for a lowpass
*/
void
{
lowpass_filter()
int j;
sincx1();
}
/*-----------------------------------------------------------------* function to calculate sincx: 2FC * sin(nwc)/nwc
*/
void sincx1()
{
int
i,j;
float omega, p;
if((out=fopen("high3.dat","w"))==NULL){
printf("cannot open tst.dat\n");
exit(1);
}
omega=2*pi*FC;
h[0]=2*FC;
62
i=1;
if(nflag==1)
/* check for N even */
i=0;
for(j=i; j<N1; ++j){
p=nflag*0.5+j;
h[j]=2*FC*sin(omega*p)/(omega*p);
}
}
/*------------------------------------------------------------------* function to calculate the window function
*/
void window_func()
{
int
j;
double
bd,p,rm,bn,x1;
x1=beta;
/*Kaiser window */
bd=bessel(x1);
for(j=0; j<N1;++j){
p=nflag*0.5+j;
rm=2*p/(N-1); rm=rm*rm;
x1=beta*sqrt(1-rm);
bn=bessel(x1);
w[j]=bn/bd;
}
}
/*
*
*/
double
{
bessel(double x)
double
int
i;
y,t,t1,e,de,sde;
y=x/2;
t=1.E-08; e=1; de=1;
for(i=1; i <25; ++i){
t1=(double) i;
de=de*y/t1;
sde=de*de;
e=e+sde;
if((e*t-sde) > 0.0)
return(e);
}
}
63
APPENDIX D
% Hilbert Transform Matlab program with WP=0.035pi and WS=0.29pi used
% for signal reconstruction.
a=[0.1 0.91];
b=[1 1];
h=remez(92,a,b,'hilbert');
[H,WT]=freqz(h,[1],100);
subplot(211);
plot((WT/pi)/2,abs(H)),grid
title('HILBERT TRANSFORM '),...
xlabel('Normalized frequency'),ylabel('Magnitude')
APPENDIX E
/*--------------------------------------------------------*/
/*
Nonuniform sampling and reconstruction
*/
/*
using 3rd band and Hilbert transform coefficients */
/*--------------------------------------------------------*/
#include
#include
#include
<stdio.h>
<math.h>
<dos.h>
#define
npt
200
#define pi
3.141592654
#define DEL
27
void init_arrays();
void
read_coeffs();
void decimator_interpolator_spec();
void analy_synth_channel1();
void
analy_synth_channel2();
float y1[npt],
y2[npt],h[npt],hH[npt],hL[npt],xF[npt],xK[npt],del[npt];
float x1[npt], x2[npt], x3[npt],xH[npt],b[npt],Z[npt],xL[npt];
long n1,n2,m, l,NH,mm=0;
long M,L, ndata=0;
int
xn;
FILE *in,*out, *fopen();
char din[30], fname1[30], fname2[30];
main()
{
clrscr();
init_arrays(); /* initialise coeffs and data arrays */
read_coeffs();
/* reads coefficients */
decimator_interpolator_spec(); /* ask user for decimator and*/
/* interpolator specification*/
while(fscanf(in,"%d",&xn)!=EOF){
analy_synth_channel1(); /*even_decim();*/
analy_synth_channel2(); /*odd_decim();*/
++ndata;
64
}
printf("number of data points in input file \t%ld \n",ndata);
printf("number of data points stored in output file \t%ld \n",mm);
fclose(in);
fclose(out);
printf(" PRESS ANY KET TO EXIT \n");
getch();
exit(0);
}
/*--------------------------------------------------------------- */
void init_arrays()
{
long i;
for(i=0; i < npt; ++i){
x1[i]=0; xL[i]=0; xK[i]=0; xF[i]=0;
hL[i]=0; hH[i]=0; xH[i]=0;
b[i]=0;
del[i]=0;
y1[npt]=0;
y2[npt]=0;
Z[i]=0;
}
}
/*-----------------------------------------------------------------*/
void
read_coeffs()
{
n1=0; n2=0;
printf("enter Hilbert Transform coefficients file nam HILBERT.DAT\n")
scanf("%s",fname1);
printf("\n");
printf("enter 3rd Band Low Pass filter coefficients file name
3rd.DAT\n");
scanf("%s",fname2);
if((in=fopen(fname1,"r"))==NULL)
{
printf("Hilbert Transform coeff file not found\n");
getch();
exit(1);
}
while(fscanf(in,"%f",&hH[n1])!=EOF)
{
++n1;
NH=n1;
}
printf(" Hilbert filter length is %ld\n",NH);
--n1;
fclose(in);
if((in=fopen(fname2,"r"))==NULL)
{
65
printf("Low Pass coeff file not found\n");
getch();
exit(1);
}
while(fscanf(in,"%f",&hL[n2])!=EOF)
{
++n2;
}
--n2;
printf("Low pass filter length is %ld\n",n2);
fclose(in);
}
/*--------------------------------------------------------------*/
void
{
decimator_interpolator_spec()
printf(" Enter name of file holding data to be nonuniformly decimated
input.DAT\n");
scanf("%s",din);
printf("\n");
printf("*** The reconstructed data will be stored in DOUT.DAT
*****\n");
printf("\n");
printf("Enter decimation factor\n");
printf("\n");
scanf("%ld",&m);
if(m>3)
printf("you have selected a factor that will not reconstruct the
signal\n");
printf("\n");
printf("Enter the interpolation factor\n");
printf("it must be less than decimator factor\n");
printf("\n");
scanf("%ld",&l);
M=m;
L=l;
/* decimation factor */
/* interpolation factor */
if(L>=M)
{
printf(" outof range to perform decim. & inter. for signal
recovery\n");
getch();
exit(1);
}
if((in=fopen(din,"r"))==NULL)
{
printf("error reading input data file\n");
getch();
exit(1);
}
if((out=fopen("dout.dat","w"))==NULL)
{
printf("cannot open output data file\n");
exit(1);
66
}
}
/*-----------------------------------------------------------------*/
/* ANALYSIS & SYNTHESIS BANKS
*/
/*----------------------------------------------------------------*/
void
{
analy_synth_channel1()
float xnew, y1,y2;
double
y,s,c,D,GH,f,F0,Y;
long j,i,k,v,N,z,n3,n4,zk,K,n,Z,V;
n3=2; n4=1;
c=cos(2*pi/3);
s=-sin(2*pi/3);
/******************************************************************/
/*
ANALYSIS BANK
*/
/******************************************************************/
xnew=xn;
/* xnew holds the input data*/
for(j=1; j<=n3; ++j){
k=n3-j+1;
x1[k]=x1[k-1];
}
x1[0]=xnew;
M=M-L;
if (M>0)
return;
M=m;
y1=x1[1];
/* update
delay line */
/* non uniform decimation */
/****************************************************************/
/*
SYNTHESIS BANK
F0(z)
*/
/****************************************************************/
L=l;
for(i=0; i<M-L; ++i)
{
for(j=1; j<=n4; ++j)
{
k=n4 -j;
xF[k]=xF[k-1];
}
xF[1]=y1;
/* F0 branch delay */
N=NH;
/* Group delay compensation */
D=1-c;
for(zk=1; zk<=N; ++zk)
{
K=N-zk +1;
xK[K]=xK[K-1];
67
}
xK[0]=D;
/*-----------------------------------------------------------------*/
/*
Hilbert Transform GH filtering
*/
for(n=1; n<=NH; ++n)
{
Z=NH -n +1;
xH[Z]=xH[Z-1];
}
xH[0]=xF[1];
/* update FIR HILB delay line*/
y=0;
/* perform filtering */
v=i;
while(v<=NH)
{
y=y + hH[v]*xH[v];
GH=y*s;
v=v+M;
}
y2=xK[0];
f=y2 + GH;
/*----------------------------------------------------------------*/
/*
Low Pass GL filtering
*/
V=i;
Y=0;
while(V<=n2){
Y=Y + hL[V]*xH[V];
V=V+M;
/* perform Lowpass filtering */
}
y1=0.0;
F0= (f*Y)*L;
fprintf(out,"%f\n",F0);
}
}
/*-----------------------------------------------------------------*/
/* Function performing analysis and synthesis on F1 i.e. channel 2 */
/*-----------------------------------------------------------------*/
void analy_synth_channel2()
{
float xnew, y2,y1;
long j,i,v,k,N,z,n3,n4,zk,K,Z,V,n;
double y,s,c,D,GH,f,F1,Y;
n3=2;
c=cos(2*pi/3);
s=-sin(2*pi/3);
68
/*---------------------------------------------------------------*/
/*
ANALYSIS BANK
*/
/*---------------------------------------------------------------*/
xnew=xn;
/* input data */
for(j=1; j<=n3; ++j)
/* update delay line */
{
k=n3-j+1;
x1[k]=x1[k-1];
}
x1[1]=xnew;
M=M-L;
/* nonuniform decimation stage */
while(M>0)
{
return;
}
M=m;
y1=x1[1];
/*-----------------------------------------------------------------*/
/*
SYNTHSIS BANK F1(z)
*/
/*----------------------------------------------------------------*/
L=l;
for(i=0; i<M-L; ++i)
{
D=1-c;
for(n=1; n<=NH; ++n)
{
Z=NH-n+1;
xH[Z]=xH[Z-1];
}
xH[0]=y1;
/* update hilbert delay */
y=0;
v=i;
while(v<=NH){
y=y + hH[v] * xH[v];
GH=y*s;
v=v+M;
}
y2=D;
f=y2 - GH;
V=i;
Y=0;
while(V<=n2)
{
Y=Y+hL[V]*xH[V];
V=V+M;
}
/* Hilbert transform filtering */
/* Lowpass filtering */
y1=0.0;
F1=(f*Y)*L;
fprintf(out,"%f\n",F1);
++mm;
69
}
}
APPENDIX F
/*AICCOM.C-COMUNICATION ROUTINES FOR SERIAL PORT 0 OF AIC */
#define TWAIT while (!(PBASE[0x40] & 0x2)) /*wait till XMIT buffer
clear*/
extern int AICSEC[4];
/*array defined in main
prog */
volatile int *PBASE = (volatile int *) 0x808000; /*peripherals base
addr*/
void AICSET()
{
volatile int loop;
PBASE[0x28] = 0x00000001;
PBASE[0x20] = 0x000002C1;
asm("
LDI
00000002h,IOF");
for (loop = 0; loop < 50; loop++);
PBASE[0x42] = 0x00000111;
PBASE[0x43] = 0x00000111;
PBASE[0x40] = 0x0E970300;
PBASE[0x48] = 0x00000000;
asm("
OR
00000006h,IOF");
for (loop = 0; loop < 4; loop++)
{
TWAIT;
PBASE[0x48] = 0x3;
TWAIT;
PBASE[0x48] = AICSEC[loop];
}
}
void AICSET_I()
{
AICSET();
asm("
LDI
asm("
OR
asm("
OR
}
/*function to initialize AIC */
/*declare local variables
/*set timer period
/*set timer control register
/*set IOF low to reset AIC
/*keep IOF low for a while
/*set xmit port control
/*set receive port control
/*set serial port global reg
/*clear xmit register
/*set IOF high to enable AIC
/*loop to configure AIC
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
*/
/*wait till XMIT buffer clear*/
/*enable secondary comm
*/
/*wait till XMIT buffer clear*/
/*secondary command for SP0 */
/*configure AIC, enable TINTO*/
00000000h,IF");
00000010h,IE");
00002000h,ST");
int UPDATE_SAMPLE(int output)
{
int input;
TWAIT;
PBASE[0x48] = output << 2;
input = PBASE[0x4C] << 16 >> 18;
return(input);
}
/*function to configure AIC */
/*clear IF Register
*/
/*enable EXINT0 CPU interrupt*/
/*global interrupt enable
*/
/*function to update sample
*/
/*declare local variables
*/
/*wait till XMIT buffer clear */
/*left shift and output sample*/
/*input sample and sign extend*/
/*return new sample
*/
70
APPENDIX G
Coefficient quantization.
Quantized coefficients
Unquantized coefficients
-478123,
-1
745366,
1462976,
1749671,
1278198,
2,
-1736209,
-3236473,
-3704818,
-2606229,
-4,
3327634,
6045789,
6764015,
4661758,
5,
-5747955,
-10289324,
-11359673,
-7736761 ,
-7 ,
9353301 ,
16610872 ,
18216824 ,
12340171 ,
9 ,
-14817229,
-26281334,
-28831256,
-19570728,
-10,
23741720 ,
42484744 ,
47166044 ,
32521062 ,
11 ,
-41317156,
-76449344,
-88636528,
-64709912,
-12 ,
98932856 ,
214860032,
323823360,
401409792,
429496736,
401409792,
323823360,
214860032,
-2.22643e-04
-3.76328e-10
3.47088e-04
6.81251e-04
8.14754e-04
5.95207e-04
8.28900e-10
-8.08485e-04
-1.50710e-03
-1.72519e-03
-1.21362e-03
-1.43096e-09
1.54955e-03
2.81529e-03
3.14974e-03
2.17080e-03
2.15393e-09
-2.67660e-03
-4.79134e-03
-5.28976e-03
-3.60271e-03
-2.94780e-09
4.35547e-03
7.73504e-03
8.48287e-03
5.74634e-03
3.74605e-09
-6.89981e-03
-1.22382e-02
-1.34256e-02
-9.11333e-03
-4.47367e-09
1.10556e-02
1.97835e-02
2.19634e-02
1.51438e-02
5.05718e-09
-1.92398e-02
-3.55995e-02
-4.12746e-02
-3.01329e-02
-5.43482e-09
4.60692e-02
1.00052e-01
1.50792e-01
1.86921e-01
2.00000e-01
1.86921e-01
1.50792e-01
1.00052e-01
71
98932856 ,
-12 ,
-64709912,
-88636528,
-76449344,
-41317156,
11 ,
32521062 ,
47166044 ,
42484744 ,
23741720 ,
-10,
-19570728,
-28831256,
-26281334,
-14817229,
9 ,
12340171 ,
18216824 ,
16610872 ,
9353301 ,
-7 ,
-7736761,
-11359673,
-10289324,
-5747955,
5,
4661758,
6764015,
6045789,
3327634,
-4,
-2606229,
-3704818,
-3236473,
-1736209,
2,
1278198,
1749671,
1462976,
745367,
-1,
-478123,
4.60692e-02
-5.43482e-09
-3.01329e-02
-4.12746e-02
-3.55995e-02
-1.92398e-02
5.05718e-09
1.51438e-02
2.19634e-02
1.97835e-02
1.10556e-02
-4.47367e-09
-9.11333e-03
-1.34256e-02
-1.22382e-02
-6.89981e-03
3.74605e-09
5.74634e-03
8.48287e-03
7.73504e-03
4.35547e-03
-2.94780e-09
-3.60271e-03
-5.28976e-03
-4.79134e-03
-2.67660e-03
2.15393e-09
2.17080e-03
3.14974e-03
2.81529e-03
1.54955e-03
-1.43096e-09
-1.21362e-03
-1.72519e-03
-1.50710e-03
-8.08485e-04
8.28900e-10
5.95207e-04
8.14754e-04
6.81251e-04
3.47088e-04
-3.76328e-10
-2.22643e-04
72
APPENDIX H
% Plotting in Matlab of quantized coefficients of 5th band lowpass
%filter
Fs=8000; % sampling frequency
b=[-478123,-1, 745366, 1462976,1749671,1278198,2,-1736209,...
3236473,-3704818,-2606229,-4,3327634,6045789,6764015,4661758,...
5,-5747955,-10289324,-11359673,-7736761 ,-7 ,9353301 ,16610872 ,...
18216824 ,12340171 ,9 ,-14817229,-26281334,-28831256,-19570728,...10,23741720 ,42484744 ,47166044 ,32521062 ,11 ,-41317156,76449344,...
-88636528,-64709912,-12 ,98932856, 214860032,323823360, 401409792,...
429496736,...
401409792,323823360,214860032,98932856 ,-12 ,-64709912,-88636528,76449344,-41317156,...
11 ,32521062 ,47166044 ,42484744 ,23741720 ,-10,-19570728,-28831256,26281334,...
-14817229,9 ,12340171 ,18216824 ,16610872 ,9353301 ,-7 ,-7736761,11359673,-10289324,...
-5747955,5,4661758,6764015,6045789,3327634,-4,-2606229,-3704818,3236473,-1736209,...
2,1278198,1749671,1462976,745367,-1,-478123];
a=[1];
A=1000;
Hz=freqz(b,a,A);
m=abs(Hz);
dB=20*log10(m);
M=dB/2.5;
W=Fs/(2*A)*(0:A-1);
subplot(211);
plot(W,M),grid,title('Quantized Fifth band lowpass filter'),...
ylabel('Magnitude |H(z)|'),xlabel('Frequency Hz')
73
APPENDIX I
% Generated Input signal used in real time implementation
fs=8000; % sampling frequency
G=240;
% number of data points/samles
n=G/fs;
% setting time limit
t=0:1/fs:n; % sets time base
s=2.5*sin(2*pi*100*t)+ 5*sin(2*pi*200*t)+ 10*sin(2*pi*300*t)+...
15*sin(2*pi*400*t)+sin(2*pi*500*t)+ sin(2*pi*600*t)+...
sin(2*pi*700*t) + sin(2*pi*800*t)+ sin(2*pi*900*t)+ sin(2*pi*1000*t)
+ sin(2*pi*1100*t) + sin(2*pi*1200*t)+ sin(2*pi*1300*t)+...
+sin(2*pi*1400*t) + sin(2*pi*1500*t) +sin(2*pi*1600*t)+...
sin(2*pi*1700*t) +sin(2*pi*1800*t) + sin(2*pi*1900*t)
+sin(2*pi*2000*t)+ sin(2*pi*2100*t) +sin(2*pi*2200*t)+...
+sin(2*pi*2300*t)+ sin(2*pi*2400*t)+...
sin(2*pi*2500*t) +sin(2*pi*2600*t)+ sin(2*pi*2700*t) +
sin(2*pi*2800*t)+...
sin(2*pi*2900*t) + sin(2*pi*300*t)+ sin(2*pi*3100*t)+
sin(2*pi*3200*t)+...
sin(2*pi*3200*t) + sin(2*pi*3300*t) +sin(2*pi*3400*t)+
sin(2*pi*3500*t)+...
sin(2*pi*3600*t) +sin(2*pi*3700*t) + sin(2*pi*3800*t);
subplot(211);
plot(t,s),grid
title('Time domain of the input signal'),...
xlabel('Time (seconds)'),ylabel('Magnitude')
F=fft(s); % computes the Fourier transform of the signal
z=abs(F);
f=(fs)/G*(0:239); % set the frequency axis
subplot(212);
plot(f(1:120),z(1:120)),grid
title('Frequency domain'),...
xlabel('Frequency (Hz)'),ylabel('Magnitude')
74
APPENDIX J
/*---------------------------------------------------------------*/
/* REAL TIME IMPLEMENTATION ON
*/
/* Nonuniform sampling and reconstruction using 5th band filter
*/
/* coefficients
*/
/* ---------------------------------------------------------------*/
#include
"aiccom.c"
#include
"df250.h"
#include "input.h"
/* AIC communication routine */
/* 5th band filter coefficients */
/* Input signal */
#define VEC_ADDR (volatile int*) 0x00 /* address of vectors */
#define m 5
/* decimation factor */
#define l 3
/* interpolation factor */
#define
npt
100
int AICSEC[4]={0x1830,0x1,0x4E9E,0x67}; /* config data for AIC SP0*/
int data_out;
float
float
int
y1[npt],y3[npt];
/*y2[npt]*/
X1[npt], x2[npt],x3[npt]; /*x4[npt]; */
M,L, ndata=0;
/*-----------------------------------------------------------------*/
/* FUNCTION FOR ARRAY INITIALIZATION
*/
/*----------------------------------------------------------------*/
void
{
init_arrays()
int
i;
for(i=0; i < npt; ++i){
X1[i]=0;
x2[i]=0;
x3[i]=0;
y1[npt]=0;
}
}
/*----------------------------------------------------------------*/
/* ANALYSIS & SYNTHESIS FUNCTION FOR CHANNEL ONE
*/
/*----------------------------------------------------------------*/
void even_decim(int *IO_out, float *h, float *x1, int *xn, int n1)
{
float xnew, y2,y3;
int j,i,k,N3,z,v;
75
double y;
/*---------------------------------------------------------------*/
/* Analysis bank performing nonuniform decimation
*/
/*----------------------------------------------------------------*/
xnew=xn[ndata];
for(j=1; j<=L; ++j)
/* holds the input data */
/* update dalay line */
{
k=L-j+1;
x1[k]=x1[k-1];
}
x1[0]=xnew;
M = M-L;
if(M>0)
return;
M=m;
y2=x1[1];
/*---------------------------------------------------------------*/
/* Synthesis bank using polyphase filter for signal reconstruction*/
/*-----------------------------------------------------------------*/
L=l;
for(i=0; i<M-L-1; ++i)
{
x3[i]=y2;
y=0;
v=i;
while(v<=n1)
/* Filtering */
{
y=y+h[v]*x3[v];
v=v + M;
}
y3=y*M;
IO_out=y3;
/* output signal */
}
}
/*-----------------------------------------------------------------*/
/* ANALYSIS & SYNTHESIS BANK FOR CHANNEL TWO
*/
/*----------------------------------------------------------------*/
void odd_decim(int *IO_out,float *h,float *x1,int *xn,int n1)
{
float xnew, f,y1, y2;
long j,i,v,k,N2,z;
double y;
/*-----------------------------------------------------------------*/
76
/* Analysis bank performing nonuniform decimation
*/
/*-----------------------------------------------------------------*/
xnew=xn[ndata];
/* holds input data
*/
for(j=1; j<=L; ++j) /* update delay line */
{
k=L-j+1;
x1[k]=x1[k-1];
}
x1[1]=xnew;
M=M-L;
/* decimation stage */
while(M>0)
{
return;
}
M=m;
y2=x1[1];
/*-----------------------------------------------------------------*/
/* Synthesis bank for signal reconstruction
*/
/*-----------------------------------------------------------------*/
L=l;
/* interpolation stage */
for(i=0; i<M-L-1; ++i)
{
x3[i]=y2;
y=0;
v=i;
while(v<=n1)
/* filtering */
{
y=y +h[v]*x3[v];
v=v+M;
}
y1=y*M;
*IO_out=y1;
}
/* output signal */
}
/*-------------------------------------------------------------*/
void c_int05()
/* interrupt routine */
{
PBASE[0x48]= data_out << 2; /* output samples */
if(ndata <16) ++ndata;
else ndata=0;
}
/* reset the counter */
77
/*----------------------------------------------------------------*/
main()
{
volatile int INTVEC =VEC_ADDR; /* pointer to vectors */
int *IO_OUT;
IO_OUT=&data_out;
INTVEC[5]= (volatile int) c_int05; /*install interrupt 5 handler*/
AICSET_I(); /* function to configure AIC */
for(;;){ /* wait for interrupt */
init_arrays();
M=m; /* decimation factor */
L=l; /* interpolation factor */
while(ndata<V){
asm(" IDLE "); /* wait for interrupt */
even_decim((int*)IO_OUT,(float*)h,(float*)X1,(int*)xn,N);
odd_decim((int*)IO_OUT,(float*)h, (float*)X1,(int*)xn, N);
++ndata;
}
}
}
78
APPENDIX K
/*-----------------------------------------------------------------*/
/* REAL TIME IMPLEMENTATION ON
*/
/* Nonuniform sampling and reconstruction using 3rd band filter
*/
/* coefficients
*/
/* --------------------------------------------------------------*/
#include "aiccom.c" /* AIC communication routine*/
#include "df425.h"
/* 3rd band filter coefficients */
#include "input.h" /* input signal */
#define VEC_ADDR (volatile int*) 0x00 /*address of vectors */
#define m 3
/*decimation factor */
#define l 2
/*interpolation factor */
#define
npt
100
int AICSEC[4]= {0x1830,0x1,0x4E9E,0x67}; /* config data for AIC SP0*/
int data_out;
float
float
int
y1[npt],y3[npt];
X1[npt], x2[npt],x3[npt];
M,L, ndata=0;
/*-----------------------------------------------------------------*/
/* FUNCTION FOR ARRAY INITIALIZATION
*/
/*----------------------------------------------------------------*/
void
{
init_arrays()
int
i;
for(i=0; i < npt; ++i){
X1[i]=0;
x2[i]=0;
x3[i]=0;
y1[npt]=0;
}
}
/*-----------------------------------------------------------------*/
/* ANALYSIS & SYNTHESIS FUNCTION FOR CHANNEL ONE
*/
/*-----------------------------------------------------------------*/
void even_decim(int *IO_out, float *h, float *x1, int *xn, int n1)
{
float xnew, y2,y3;
int j,i,k,N3,z,v;
double y;
79
/*-----------------------------------------------------------------*/
/* Analysis bank for nonuniform decimation
*/
/*-----------------------------------------------------------------*/
xnew=xn[ndata]; /* holds input data */
for(j=1; j<=L; ++j) /* update delay line */
{
k=L-j+1;
x1[k]=x1[k-1];
}
x1[0]=xnew;
M = M-L;
if(M>0)
return;
M=m;
y2=x1[1];
/*---------------------------------------------------------------*/
/* Synthesis bank using polyphase filter for signal reconstruction*/
/*----------------------------------------------------------------*/
L=l;
for(i=0; i<M-L; ++i)
{
x3[i]=y2;
y=0;
v=i;
while(v<=n1) /* filtering */
{
y=y+h[v]*x3[v];
v=v + M;
}
y3=y*M;
IO_out=y3; /* output signal */
}
}
/*-----------------------------------------------------------------*/
/* ANALYSI & SYNTHESIS BANK FOR CHANNEL TWO
*/
/*----------------------------------------------------------------*/
void odd_decim(int *IO_out,float *h,float *x1,int *xn,int n1)
{
float xnew, f,y1, y2;
long j,i,v,k,N2,z;
double y;
80
/*----------------------------------------------------------------*/
/* Analysis bank performing nonuniform decimation
*/
/*-----------------------------------------------------------------*/
xnew=xn[ndata];
/* holds input data */
for(j=1; j<=L; ++j) /* update delay line */
{
k=L-j+1;
x1[k]=x1[k-1];
}
x1[1]=xnew;
M=M-L;
/*xn[ndata];*/
/* decimation stage */
while(M>0)
{
return;
}
M=m;
y2=x1[1];
/*--------------------------------------------------------------*/
/* Synthesis bank for signal reconstruction
*/
/*--------------------------------------------------------------*/
L=l;
/* interpolation stage */
for(i=0; i<M-L; ++i)
{
/*
x3[i]=y2[npt];*/
x3[i]=y2;
y=0;
v=i;
while(v<=n1)
/* filtering */
{
y=y +h[v]*x3[v];
v=v+M;
}
y1=y*M;
*IO_out=y1;
}
/* output signal */
}
/*------------------------------------------------------------*/
void c_int05()
/* interrupt routine
*/
{
PBASE[0x48]= data_out << 2; /* output samples */
if(ndata <16) ++ndata;
else ndata=0;
/*reset counter */
81
}
main()
{
volatile int *INTVEC =VEC_ADDR; /* pointer to vectors */
int *IO_OUT;
IO_OUT=&data_out;
INTVEC[5]= (volatile int) c_int05; /*install interrupt 5 handler*/
AICSET_I();
/* function to configure AIC */
for(;;){
/* wait for interrupt */
init_arrays();
M=m;
/* decimation factor */
L=l;
/* interpolation factor */
while(ndata<V){
asm(" IDLE "); /* wait for interrupt */
even_decim((int*)IO_OUT,(float*)h,(float*)X1,(int*)xn,N);
odd_decim((int*)IO_OUT,(float*)h, (float*)X1,(int*)xn, N);
++ndata;
}
}
82
APPENDIX L
/*LINK.CMD-COMMAND FILE FOR LINKING
*/
-c
/*USING C CONVENTION
*/
vecsir.obj
/*INTERR/RESET DEF
*/
third.obj
/*MAIN PROGRAM
*/
-o third.out
/*LINKED COFF OUTPUT FILE */
-l rts30.lib
/*RUN-TIME LIBRARY SUPPORT*/
MEMORY
{
VECS: org = 0
len = 0x40
/*INTERRUPT VECTORS*/
SRAM: org = 0x40
len = 0x3FC0 /*USER STATIC RAM */
RAM:
org = 0x809800 len = 0x800 /*INTERNAL RAM
*/
}
SECTIONS
{
.text:
{} > SRAM
/*CODE
*/
.cinit: {} > RAM
/*INITIALIZATION TABLES
*/
.stack: {} > RAM
/*SYSTEM STACK
*/
.bss:
{} > RAM
/*BSS SECTION
*/
vecs:
{} > VECS
/*VECTOR SECTION
*/
}
83
REFERENCES
[1] L.R. Rabiner and B. Gold, Theory and Application of Digital Signal Processing.
Englewood Cliffs, NJ: Prentice Hall. 1975.
[2] P.P. Vaidyanathan, “Quadrature mirror filter banks, M-band extension and perfect
reconstruction techniques,” IEEE ASSP Mag., vol. 4, pp. 4-20, July 1987.
[3] P.P. Vaidyanathan, “Efficient reconstruction of band-limited from nonuniformly
decimated by use of Polyphase filter banks,” IEEE Trans. on Acoustics, Speech
and Signal Processing. Vol. 38 No 11 pp. 1927-1936, November 1990.
[4] D. F. Elliot, Handbook on Digital Signal Processing, Newyork Academic,1987.
[5] M.J.T. Smith and T.P. Barnwell, , “ A unifying framework for analysis/synthes
systems based on maximally decimated filter banks,” in Proc. IEEE Int. Conf.
ASSP, Tampa, Florida, March 1985, pp 521-524.
[6] P.P. Vaidyanathan, “ Theory and design of M-channel maximally decimated
quadrature mirror filters with arbitrary M, having perfect reconstruction property”,
IEEE Trans. on Acoustics, Speech and Signal Proc. Vol. ASSP 35, pp. 476-492,
April 1987.
[7] A.J. Jerri “ The shannon sampling theorem, its various extensions and applications
Proc. IEEE Nov. 1977 pp 1565-96
[8] L.R Rabiner and R.E.Crochiere, Multirate Digital Signal Processing.
Prentice-Hall. 1983.
[9] F.Marvasti, A Unified Approach To Zero-Crossing and Nonuniform Sampling.
Illinios Institute of Technology Chicago, USA.
[10] TLC32040C-TLC32041J Analog Interface Circuits, Texas Instrument, Inc.,
Dallas, 1995.
[11] DSP Applications with the TMS320C30 Evalution Module, Texas Instruments,
Inc., Dallas, Texas, 1991.
[12] P.P.Vaidyanathan and Liu,” Classical Sampling Theorem”, IEEE Trans. ASSP
vol 36 No 9 Sep. 1988.
[13] TMS320C3x User Guide, Texas Instruments, Inc., Dallas, Texas, 1991.
[14] TMS320C3x Evaluation Module Technical Referrence, Texas Instruments, Inc.,
Dallas, 1990.
[15] Emmanuel C. Ifeachor and B.R. Jervis, DSP Practical Approach.
84
Addison-Wesley, 1993.
Download