implementation of fm demodulator algorithms on a high … · implementation of fm demodulator...
TRANSCRIPT
HSRHOCHSCHULE FÜR TECHNIK RAPPERSWI L
ELEKTROTECHNIKDiploma Thesis
Page 1 of 4
Application for Faculty Appointment
Recentphotograph of
applicant
Please submit completed application form, with relevant supporting documents to:Vice President (Human Resources), NANYANG TECHNOLOGICAL UNIVERSITY, Administration Building, Level 4, 50 Nanyang Avenue,Singapore 639798 or Fax: (65) 791-9340.
GENERAL INFORMATION
Please indicate position applying for: School:
Please indicate where you came to know about the position being applied for:
� Advertisement in Newspapers / Journals / Others. The name of the publication is _______________________
� Personal Contacts
� NTU Website. If you have seen our advertisement in other website(s), please name website(s) _______________________
� Others. Please specify ________________________
Please indicate details of any previous application(s):
Date: School:
PERSONAL PARTICULARS
Full name as in Identity Card / Passport:(In BLOCK LETTERS and underline Family Name / Surname)
Postal Address:
Name in Chinese characters, if applicable:
Date of Birth: Country of Birth:
Home address (if different from above):
Ethnic Group: Religion: Office Tel: Home Tel:
Sex: Marital Status: Mobile: Pager:
E-mail: Confidential Fax:Names and Date of Birth of Children, if applicable:
Passport No: Date of Issue:
Nationality: Identity Card No:
Color* : Pink / Blue / Red
Place of Issue: Date of Expiry:
Non-Singapore Citizen currently residing in Singapore (Please attach a copy of your Singapore Immigration Pass)
� Singapore Permanent Resident � Non-Singapore Permanent Resident
Date of SPR Issue: Type of Singapore Immigration Pass you are currently holding:
UIN:� Employment Pass� Student Pass
� Work Permit� Dependant’s Pass
� Social Visit Pass
(Please attach a copy of your Entry & Re-entry permit) Date of Issue: Date of Expiry:
Implementation of FM DemodulatorAlgorithms on a High Performance Digital
Signal Processor
TMS320C6711DSP
Franz Schnyder Christoph Haller
11.1.2002
Supervisors: Dr. Chang Chip Hong, Andreas Ehrensperger
2
Abstract
Analog modulations are more and more replaced by digital ones. To keep the compatibility thenew device should be able to perform the analog modulation. A interesting solution is to solvethis with digital signal processing. In an earlier semester project, four FM demodulation algo-rithms were developed and tested on their suitability. Two of them (mixed and PLL demodulator)are are implemented on the DSP (TMS320C6711DSK).
Because both algorithms demand the same pre and after signal preparation, the demodulationis split into sub projects to reach a high compatibility between the algorithms. First they are re-alized in floating-point. That allows to concentrate on the algorithms themeselves without anyeffects of a fixed-point implementation. After that, the algorithms are translated step by step fromfloating-point to fixed-point. Afterwards the algorithms are optimized in time and signal quality.As in the earlier work, the algorithms are tested out with measuring the SINAD and the signalnoise ratio of the demodulated signal. Furthermore the needed computing time of the implemen-tations is measured. The two algorithms are compared each other. The mixed demodulator showsa better performance than the PLL.
The Chapters Theory 3 and Simulation 4 were not developed in this project, but in the earliersemester project. Nevertheless they are included to get the whole context of developed digital FMdemodulation in a single document.
i
Abstract
ii
Contents
Abstract i
List of Figures vii
List of Tables xi
List of Listings xiv
Acknowledgement xv
Subject xviiIntroduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiTask . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiReporting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiiDates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviiiOrganization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xviii
1. Introduction 11.1. Motivation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2. Objective . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3. Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.3.1. FM Receiver Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.3.2. The Signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Project Management 32.1. Milestones . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2. Responsibilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3. Theory 53.1. Frequency Modulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53.2. Algorithms for Signal Pretreatment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2.1. Subsampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63.2.2. Quadrature-Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3. Algorithms for Digital FM Demodulation . . . . . . . . . . . . . . . . . . . . . . . . . 93.3.1. Baseband Delay Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.3.2. Phase-Adapter Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113.3.3. Phase-Locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.3.4. Mixed Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
iii
Contents
4. Simulation 174.1. General Knowledge from Simulations . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
4.1.1. Ideal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.1.2. DSP Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174.1.3. DSP Model with Gaussian Noise . . . . . . . . . . . . . . . . . . . . . . . . . . 19
4.2. Algorithms for Signal Pretreatment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.2.1. FM Modulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.2.2. Subsampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.2.3. Quadrature-Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
4.3. Baseband Delay Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3.1. Ideal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.3.2. DSP Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.3.3. DSP Model with Gaussian Noise . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.4. Phase-Adapter Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.4.1. Ideal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
4.5. Phase-Locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 274.5.1. Ideal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284.5.2. DSP Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.5.3. DSP Model with Gaussian Noise . . . . . . . . . . . . . . . . . . . . . . . . . . 30
4.6. Mixed Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.6.1. Ideal Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.6.2. DSP Model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.6.3. DSP Model with Gaussian Noise . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.7. Comparison of the Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.7.1. Signal Quality . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 344.7.2. Robustness . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.7.3. Computing Power and Storage Utilization . . . . . . . . . . . . . . . . . . . . 364.7.4. The Appropriate Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5. Implementation 395.1. System Architecture . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
5.1.1. Signal Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 395.1.2. The Sampling Rates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.1.3. Analog-to-Digital Conversation THS1408 . . . . . . . . . . . . . . . . . . . . . 435.1.4. Digital-to-Analog Conversation . . . . . . . . . . . . . . . . . . . . . . . . . . 475.1.5. Programm Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475.1.6. Interrupt Routines and Scheduling . . . . . . . . . . . . . . . . . . . . . . . . . 48
5.2. Floating-Point Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.2.1. Quadrature Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.2.2. First Down Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545.2.3. Mixed Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 545.2.4. PLL Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 555.2.5. Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565.2.6. Second Down Sampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
5.3. Fixed-Point Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 575.3.1. Fractional Q Formats . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585.3.2. Quadrature Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605.3.3. Mixed Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625.3.4. PLL Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 625.3.5. Out Filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
5.4. Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
iv
Contents
5.4.1. Adaptive Seeking of Carrier Angular Frequency . . . . . . . . . . . . . . . . . 705.4.2. Time Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6. Tests And Results 776.1. Spectrum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 776.2. Signal Quality (SINAD) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.2.1. Mixed Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796.2.2. PLL Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816.2.3. Comparison of Mixed and PLL Demodulator . . . . . . . . . . . . . . . . . . . 82
6.3. Robustness (S/N) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.3.1. Mixed Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846.3.2. PLL Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 846.3.3. Comparison of Mixed and PLL Demodulator . . . . . . . . . . . . . . . . . . . 85
6.4. Computing Time . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.4.1. Demodulation Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 866.4.2. Interrupt Routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.4.3. CPU Processing Load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7. Conclusions and Recommendations 93
A. Equipment 95A.1. Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
A.1.1. DSP Board . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95A.1.2. Analog-to-Digital Converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
A.2. Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96A.2.1. DSP IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96A.2.2. MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
A.3. Signal And Measure Instruments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96A.3.1. Signal Generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96A.3.2. Oscilloscope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97A.3.3. Audio Measurement System . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
B. Abbreviations and Symbols 99B.1. Formula Symbols . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99B.2. Abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100
C. Simulation Measure Algorithms 101C.1. Harmonic distortion k and SINAD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101C.2. Signal to noise ratio S/N . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 102
D. Bibliography 103D.1. English Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103D.2. German Books . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103D.3. Texas Instruments Documentation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
E. Simulink models 105E.1. Baseband-Delaydemodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105E.2. Phase-Adapter-Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 108E.3. Phasenregelschleife . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109E.4. Mix Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
v
Contents
F. Listings 115F.1. C Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
F.1.1. ADC and DAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115F.1.2. Floating-Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119F.1.3. Fixed-Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126F.1.4. Fixed-Point Optimized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136F.1.5. Floating-Point Adaptive . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
F.2. Linear Assembly Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146F.2.1. Fixed-Point Optimized . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
F.3. MATLAB Listings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
vi
List of Figures
1.1. Block diagram FM receiver architecture . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2. Spectrum message signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21.3. Spectrum FM signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2.1. Project schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3.1. Subdivisions of FM demodulation block . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2. Spectrum subsampling with even λ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.3. Spectrum subsampling with odd λ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.4. Quadrature-Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.5. Real quadrature-mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93.6. Complex baseband delay demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . 103.7. Real baseband delay demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103.8. Real amplitude normalization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.9. Phase-adapter demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123.10. Phase-Locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 133.11. Actual realization Phase-Locked Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . 143.12. Mixed demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
4.1. Quantizer and saturation blocks in Simulink . . . . . . . . . . . . . . . . . . . . . . . 184.2. Simulink block FM modulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.3. Simulink model FM modulators . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.4. Simulink model subsampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.5. Plot 1 subsampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.6. Plot 2 subsampling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204.7. Simulink block quadrature-mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.8. Simulink model quadrature-mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.9. Plot quadrature-mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 224.10. Simulink model baseband delay demodulator . . . . . . . . . . . . . . . . . . . . . . 224.11. Plot of delay demodulator ideal with kFM = 180 . . . . . . . . . . . . . . . . . . . . . 234.12. Plot of delay demodulator ideal with kFM = 18000 . . . . . . . . . . . . . . . . . . . . 234.13. Spectrum of the chirp signal from a ideal delay demodulator . . . . . . . . . . . . . . 234.14. Spectrum of chirp signal for delay demodulator DSP model . . . . . . . . . . . . . . 244.15. Plot FM signal with noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 264.16. Plot noise and output signal with noise . . . . . . . . . . . . . . . . . . . . . . . . . . 264.17. Simulink model phase-adapter demodulator ideal . . . . . . . . . . . . . . . . . . . . 264.18. Plot phasea-adapter demodulator with kFM = 180 . . . . . . . . . . . . . . . . . . . . 274.19. Plot phase-adapter demodulator with kFM = 18000 . . . . . . . . . . . . . . . . . . . 274.20. Plot PLL ideal with kFM = 1800 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.21. Plot PLL ideal with kFM = 18000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.22. Spectrum of the chirp signal for the ideal PLL . . . . . . . . . . . . . . . . . . . . . . . 30
vii
List of Figures
4.23. PLL DSP kFM = 1800, with bandpass filter . . . . . . . . . . . . . . . . . . . . . . . . . 304.24. PLL DSP kFM = 18000, with bandpass filter . . . . . . . . . . . . . . . . . . . . . . . . 304.25. PLL DSP kFM = 1800, without bandpass filter . . . . . . . . . . . . . . . . . . . . . . . 314.26. PLL DSP kFM = 18000, without bandpass filter . . . . . . . . . . . . . . . . . . . . . . 314.27. PLL DSP kFM = 18000, with the bandpass filter in the feedback loop . . . . . . . . . 314.28. Simulink model mixed demodulator ideal . . . . . . . . . . . . . . . . . . . . . . . . . 324.29. Plot of ideal mixed demodulator with kFM = 180 . . . . . . . . . . . . . . . . . . . . . 334.30. Plot of ideal mixed demodulator with kFM = 18000 . . . . . . . . . . . . . . . . . . . 334.31. Spectrum of the chirp signal for an ideal mixed demodulator . . . . . . . . . . . . . . 334.32. Spectrum of the chirp signal for DSP mixed demodulator . . . . . . . . . . . . . . . . 344.33. Plot of FM signal with noise . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.34. Plot of the noise and the output signal . . . . . . . . . . . . . . . . . . . . . . . . . . . 354.35. Comparison of the harmonic distortion for ideal models of different algorithms with
constant kFM of 18000 and variable frequency . . . . . . . . . . . . . . . . . . . . . . 354.36. Comparison of harmonic distortion for ideal models of different algorithms with
constant frequency of 2000Hz and variable kFM . . . . . . . . . . . . . . . . . . . . . 364.37. Comparison of SINAD for DSP models of different algorithms with constant kFM of
18000 and variable frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 364.38. Comparison of S/N ratio for different demodulation algorithmen, with a kFM of
18000 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
5.1. Overview of floating-point implementation . . . . . . . . . . . . . . . . . . . . . . . . 405.2. Overview of fixed-point implementation . . . . . . . . . . . . . . . . . . . . . . . . . 415.3. Input and output samples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 425.4. Spectrum of FM signal after subsampling . . . . . . . . . . . . . . . . . . . . . . . . . 435.5. THS1408 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 435.6. Schema address bus wiring THS1408 . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.7. Ping Pong Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 465.8. EDMA setup for Ping Pong Buffering . . . . . . . . . . . . . . . . . . . . . . . . . . . 465.9. Ping Pong Buffering DAC . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 475.10. Programm flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485.11. Layout main file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485.12. Scheduling with software interrupt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485.13. Overview interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.14. DAC interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.15. EDMA interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.16. Demodulate software interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . 505.17. Quadrature mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 515.18. Frequency response of low-pass filter for quadrature mixing, floating point . . . . . 525.19. Digital block diagram of quadrature mixer . . . . . . . . . . . . . . . . . . . . . . . . 535.20. Signal spectrum after quadrature mixing . . . . . . . . . . . . . . . . . . . . . . . . . 545.21. Signal spectrum after first down sampling . . . . . . . . . . . . . . . . . . . . . . . . . 545.22. Block diagram of mixed demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 555.23. Block diagram of PLL demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565.24. Band-pass filter frequency response, floating point . . . . . . . . . . . . . . . . . . . . 575.25. Signal spectrum before second down sampling . . . . . . . . . . . . . . . . . . . . . . 575.26. Signal spectrum after second down sampling . . . . . . . . . . . . . . . . . . . . . . . 585.27. Q.15 Bit Fields . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 585.28. Block diagram of cascaded low-pass filter . . . . . . . . . . . . . . . . . . . . . . . . . 605.29. Change in block diagram of . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 605.30. Output signals and delay states of cascaded low-pass filter . . . . . . . . . . . . . . . 61
viii
List of Figures
5.31. Output signals and delay states of cascaded low-pass filter . . . . . . . . . . . . . . . 615.32. Plot arc tangent lookup table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 635.33. Sine values with belonging indexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 645.34. Index manipulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655.35. Linear interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 665.36. Sign of correction changes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 675.37. Sign of correction does not change . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 685.38. Block diagram transposed filter structure . . . . . . . . . . . . . . . . . . . . . . . . . 695.39. Adapted System . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 705.40. Adaptive seeking of carrier angular frequency . . . . . . . . . . . . . . . . . . . . . . 725.41. development flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.1. FFT print of demodulated signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 776.2. FFT print of DSP generated sine wave . . . . . . . . . . . . . . . . . . . . . . . . . . . 786.3. FFT print of demodulated signal for the range of 0 to 20kHz . . . . . . . . . . . . . . 786.4. Principle of THD+N Measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 796.5. SINAD of fixed-point mixed demodulator with various table sizes for direct lookup 806.6. SINAD of fixed-point mixed demodulator with various table sizes for interpolated
lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 806.7. SINAD comparison of direct and interpolated lookup for fixed-point mixed demod-
ulator and the floating-point implementation . . . . . . . . . . . . . . . . . . . . . . . 806.8. SINAD of fixed-point PLL demodulator with various table sizes for direct lookup . 816.9. SINAD of fixed-point PLL demodulator with various table sizes for interpolated
lookup . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 816.10. SINAD comparison of direct and interpolated lookup for fixed-point PLL demodu-
lator and the floating-point implementation . . . . . . . . . . . . . . . . . . . . . . . . 826.11. Error of linear interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 826.12. SINAD comparison of different demodulator implementations . . . . . . . . . . . . . 836.13. Oscilloscope print FM signal normal . . . . . . . . . . . . . . . . . . . . . . . . . . . . 836.14. Oscilloscope print FM signal with noise added . . . . . . . . . . . . . . . . . . . . . . 836.15. Spectrum of an demodulated signal with an S/N ratio of 20dB by the FM signal . . . 846.16. S/N of the mixed demodulated signal with a S/N of 20dB at the input FM signal . . 846.17. S/N of the mixed demodulated signal with a S/N of 15dB at the FM input signal . . 856.18. S/N of the PLL demodulated signal with a S/N of 20dB at the input FM signal . . . 856.19. S/N of the PLL demodulated signal with a S/N of 15dB at the FM input signal . . . 856.20. S/N of the PLL demodulated signal with a S/N of 15dB at the FM input signal . . . 866.21. Time measurement results Quadrature mixer ( quad_mix ) . . . . . . . . . . . . . . . 876.22. Time measurement results mixed demodulator direct lookup ( mixed_demodulate ) 886.23. Time measurement results mixed demodulator interpolated lookup (
mixed_demodulate ) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 886.24. Time measurement results PLL demodulator direct lookup ( pll_demodulate ) . . . . 886.25. Time measurement results out filter ( out_filter ) . . . . . . . . . . . . . . . . . . . . . 896.26. Time comparison of the demodulation functions . . . . . . . . . . . . . . . . . . . . . 896.27. Executing time of interrupt routines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 906.28. CPU processing load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
E.1. Blockschaltbild Simulink Aufbau Idealer Baseband-Delaydemodulator . . . . . . . . 105E.2. Blockschaltbild Simulink Aufbau DSP Baseband-Delaydemodulator . . . . . . . . . 106E.3. Blockschaltbild Simulink Aufbau DSP Baseband-Delaydemodulator mit gausschem
Rauschen . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 107E.4. Blockschaltbild Simulink Aufbau Idealer Phase-Adapter-Demodulator . . . . . . . . 108
ix
List of Figures
E.5. Blockschaltbild Simulink Aufbau Idealer PLL . . . . . . . . . . . . . . . . . . . . . . . 109E.6. Blockschaltbild Simulink Aufbau DSP PLL . . . . . . . . . . . . . . . . . . . . . . . . 110E.7. Blockschaltbild Simulink Aufbau DSP PLL mit gausschem Rauschen . . . . . . . . . 111E.8. Blockschaltbild Simulink Aufbau Idealer Mix Demodulator . . . . . . . . . . . . . . 112E.9. Blockschaltbild Simulink Aufbau DSP Mix Demodulator . . . . . . . . . . . . . . . . 113E.10. Blockschaltbild Simulink Aufbau DSP Mix Demodulator mit gausschem Rauschen . 114
x
List of Tables
4.1. Parameter quantizer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.2. Parameter saturation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184.3. Parameter FM modulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194.4. Parameter quadrature-mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 214.5. Harmonic distortion of the ideal delay demodulator . . . . . . . . . . . . . . . . . . . 234.6. SINAD delay demodulator DSP model . . . . . . . . . . . . . . . . . . . . . . . . . . . 244.7. S/N delay demodulator DSP model . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254.8. Harmonic distortion phase-adapter demodulator . . . . . . . . . . . . . . . . . . . . . 264.9. Harmonic distortion PLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 294.10. SINAD PLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304.11. S/N PLL . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 314.12. Harmonic distortion factor mixed demodulator ideal . . . . . . . . . . . . . . . . . . 324.13. SINAD DSP mixed demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 334.14. S/N DSP Mix Demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
5.1. Jumper settings THS1408 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.2. Addresses of registers THS1408 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 445.3. Truth table address decode THS1408 . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.4. EMIF timing registers for THS1408 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 455.5. Filter specifications low-pass filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 695.6. Filter specifications high-pass filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
xi
List of Tables
xii
List of Listings
5.1. DAC interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 495.2. EDMA interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 505.3. Demodulate softawre interrupt routine . . . . . . . . . . . . . . . . . . . . . . . . . . 505.4. Argument calculation fixed-point mixed demodulator . . . . . . . . . . . . . . . . . . 625.5. PLL demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 655.6. Interpolated Lookup Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67F.1. adc_THS1408.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115F.2. adc_THS1408.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116F.3. dac_codec.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118F.4. dac_codec.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118F.5. Floating-Point :: global_settings.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119F.6. Floating-Point :: fm_dem_main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119F.7. Floating-Point :: quad_mix.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121F.8. Floating-Point :: quad_mix.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 122F.9. Floating-Point :: downsample_one.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123F.10. Floating-Point :: downsample_one.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123F.11. Floating-Point :: mixed_demodulate.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 123F.12. Floating-Point :: mixed_demodulate.c . . . . . . . . . . . . . . . . . . . . . . . . . . . 123F.13. Floating-Point :: pll_demodulate.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124F.14. Floating-Point :: pll_demodulate.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124F.15. Floating-Point :: out_filter.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125F.16. Floating-Point :: out_filter.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125F.17. Floating-Point :: downsample_two.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126F.18. Floating-Point :: downsample_two.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126F.19. Fixed-Point :: global_settings.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126F.20. Fixed-Point :: fm_dem_main.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126F.21. Fixed-Point :: quad_mix.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129F.22. Fixed-Point :: quad_mix.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 129F.23. Fixed-Point :: mixed_demodulate.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130F.24. Fixed-Point :: mixed_demodulate.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130F.25. Fixed-Point Interpolated :: mixed_demodulate.h . . . . . . . . . . . . . . . . . . . . . 131F.26. Fixed-Point Interpolated :: mixed_demodulate.c . . . . . . . . . . . . . . . . . . . . . 131F.27. Fixed-Point :: pll_demodulate.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132F.28. Fixed-Point :: pll_demodulate.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132F.29. Fixed-Point Interpolated :: pll_demodulate.h . . . . . . . . . . . . . . . . . . . . . . . 133F.30. Fixed-Point Interpolated :: pll_demodulate.c . . . . . . . . . . . . . . . . . . . . . . . 133F.31. Fixed-Point :: out_filter.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135F.32. Fixed-Point :: out_filter.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135F.33. Fixed-Point Optimized :: global_settings.h . . . . . . . . . . . . . . . . . . . . . . . . . 136F.34. Fixed-Point Optimized :: fm_dem_main.c . . . . . . . . . . . . . . . . . . . . . . . . . 137F.35. Fixed-Point Optimized :: quad_mix.h . . . . . . . . . . . . . . . . . . . . . . . . . . . 139
xiii
List of Listings
F.36. Fixed-Point Optimized :: quad_mix.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 139F.37. Fixed-Point Optimized :: mixed_demodulate.h . . . . . . . . . . . . . . . . . . . . . . 140F.38. Fixed-Point Optimized :: mixed_demodulate.c . . . . . . . . . . . . . . . . . . . . . . 140F.39. Fixed-Point Optimized Interpolated :: mixed_demodulate.h . . . . . . . . . . . . . . 141F.40. Fixed-Point Optimized Interpolated :: mixed_demodulate.c . . . . . . . . . . . . . . 141F.41. Fixed-Point Optimized :: pll_demodulate.h . . . . . . . . . . . . . . . . . . . . . . . . 141F.42. Fixed-Point Optimized :: pll_demodulate.c . . . . . . . . . . . . . . . . . . . . . . . . 142F.43. Fixed-Point Optimized :: out_filter.h . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143F.44. Fixed-Point Optimized :: out_filter.c . . . . . . . . . . . . . . . . . . . . . . . . . . . . 143F.45. Floating-Point Optimized Adaptive :: mixed_demodulate.h . . . . . . . . . . . . . . 145F.46. Floating-Point Optimized Adaptive :: mixed_demodulate.c . . . . . . . . . . . . . . . 145F.47. Fixed-Point Optimized :: quad_mix_lin_ass.sa . . . . . . . . . . . . . . . . . . . . . . 146F.48. tanTabGen.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149F.49. tanTabGenInterp.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150F.50. SineTabGen.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 150F.51. SineTabGenInt.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151F.52. mixer_design.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152F.53. lowpass_design_noisefilter.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153F.54. highpass_design_noisefilter.m . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
xiv
Acknowledgement
Living in Singapore and working on our diploma project for the last twelve weeks have been anenriching experience for us. Without the support of many people, this would not have been possi-ble. At this point we would like to express our appreciation to all persons who were involved.
Thanks to Andreas Ehrensperger, our supervisor in Switzerland, for having the efforts of support-ing us from overseas. Dr. Chang Chip Hong, our local supervisor, for his encouraging supporthere in Singapore. Dr. T. Srikanthan, director of Center for High Performance Embedded Systems.Dr. Ma Jian-Guo for reviewing the report. Much credit to those who made our stay even possi-ble: Peter Schneider, Vice-President of the University of Applied Sciences (HSR), Rapperswil; Ms.Anita Riegler, International Relations Office, University of Applied Sciences (HSR), Rapperswil;Ms. Agnes Yap and Ms. Catherine Tai , International Relations Office, Nanyang TechnologicalUniversity (NTU), Singapore. We would like to thank the students and colleagues in the labora-tory who supported us in any form.
xv
Acknowledgement
xvi
Subject
Implementation of FM demodulator algorithms on ahigh performance digital signal processor
Introduction
Mobile radio provider organizations are planning to replace their traditional analog FM-basedradio system, by a new digital system like TETRA, TETRAPOL or GSM-R. To guarantee a seamlessoperation it could be very useful if the new system could operate in a special mode, which iscompatible to the old FM system. From the commercial as well as from the technical point of viewit would be very interesting if such an special mode could be implemented as a part of software ofthe mobile signal processors without need for any additional hardware.
Task
At least two of the FM-demodulation algorithms, which have been designed and validated duringthe last HSR semester project, should be realized as real time.The input signal is a FM-modulated intermediate frequency signal (IF) with the following specifi-cations:
• carrier frequency: 10.7MHz
• maximum frequency deviation: 3kHz
• maximum signal bandwidth: 12.5kHz implementations on a digital signal processor.
This IF-signal should be sampled directly using bandpass-subsampling techniques.Concerning the implementation of the algorithms, special attention should be paid to the followingaspects:
• The implementations should be based on a fixed point architecture. (If a floating point signalprocessor is used, only the fixed point subset of the instruction set should be used)
• The implementation should be optimized with the highest priority to a low computing load,which lowers the power consumption of the target system.
With the implemented prototypes extensive tests under real world conditions should be made forvalidation.
xvii
Subject
Reporting
The report has to be written in English and 6 copies are needed. Three complete reports are for theHSR including a CD-ROM containing the complete set of the elaborated data. Three complete re-ports also including copies of the CD-ROM for the NTU. The report shall also include a translationof the earlier semester project to have the whole context in an English document.
DatesBegin of Thesis 22 October 2001End of Thesis 11 January 2002
Organization
Supervisor NTU Asst. Prof. Dr. Chang Chip HongSupervisor HSR Andreas Ehrensperger
xviii
1. Introduction
1.1. Motivation
Frequency modulation (FM) is an analog modulation, which is for example used in VHF radiobroadcasting. Another field of application for FM is private mobile radio (PMR), which is used byorganizations like police, fire departments, railroad or power supply companies, for mobile com-munication. Those analog systems will be gradually replaced by a digital counterparts in the newgeneration. For a smooth transition of the two systems, it is essential for the new generation sys-tem to be able to communicate with the radio equipment of the old generation. Because all the newradio equipment are based on DSP-Technology, it is obvious and of commercial interest to performthe demodulation with the signal processor instead of adding additional analog hardware.
1.2. Objective
Various algorithms to perform the demodulation were developed and simulated in the previoussemester project. This previous work is included in Chapters Theory 3 and Simulation 4. Twoappropriate algorithms are now implemented on a DSP platform. These implementations are thentested for signal quality and robustness.
1.3. Specifications
1.3.1. FM Receiver Architecture
The modulated signal sFM is frequency limited at an intermediate frequency of 10.7 MHz. Theantenna, tuner, and the bandpass filter are given and do not fall in the scope of this work. (seeFigure 1.1).
Tuner sFMFM Demodulation
sD
10.7 MHz
Figure 1.1.: Block diagram FM receiver architecture
1
Introduction
1.3.2. The Signals
The message signal sN is a speech signal from 300 Hz to 3400 Hz. The amplitude is normalized toone (see Figure 1.2).
A
f [HZ]1 k 2 k 3 k 4 k
message signal
300 3400
b = 3100 Hz
A
f [HZ]
FM signal
10.7 M
b = 12.5 kHz
Figure 1.2.: Spectrum message signal
The FM-Signal sFM has a bandwidth of 12.5 kHz and a carrier frequency of 10.7 MHz. The ampli-tude is also normalized to one (see Figure 1.3).
A
f [HZ]1 k 2 k 3 k 4 k
message signal
300 3400
b = 3100 Hz
A
f [HZ]
FM signal
10.7 M
b = 12.5 kHz
Figure 1.3.: Spectrum FM signal
2
2. Project Management
The project was divided into five main tasks, which were further divided into subtasks. For eachsubtask the required time was estimated shown in time schedule Figure 2.1. At the importantstages of the project a milestone was set.
2.1. Milestones
M1 First Floating-Point Demodulation A first version of both demodulation algorithms is run-ning, where time and quality are not of great interest and the source code is a draft version.
M2 Floating-Point Demodulation The two demodulation algorithms are running with a goodsignal quality and the source is well commented.
M3 Fixed-Point Demodulation Both algorithms are running stable on a fixed-point implementa-tion in C, without great effort in speed optimization.
M4 Optimized Fixed-Point Demodulation Both algorithms are speed optimized and runningstable. Various tests under real world conditions are done to characterize them.
M4 Report and Presentation The report is finished and the presentation is prepared.
2.2. Responsibilities
The project was carried out in a teamwork and therefore the tasks were distributed among the twopersons. This is also shown in Figure 2.1.
3
Project Management
Milestones M 1 PH 2 3 PH PH 4 PH 5
Estimated timeActual Time
X X
X X
X
X X
X X
X
X
X
X
X X
X
X
X
05-03 Preparing Presentation
Fran
z Sc
hnyd
erC
hris
toph
Hal
ler
X X
X
05-01 Translation Old Report
05-02 Report
03-04
03-05 Tests
05 Documentation And Presentation
Optimization
04 Fixed-Point Implementations
04-01 Mixer Algorithm
03-02 Mixed Demodulator Algorithm
Floating-Point Implementations
Mixer Algorithm
01
02
02-02 Codec 535 With EDMA
Administrative Work
Analog-Digital-Converter andDigital-Analog-Converter
02-01 ADC 1408 With EDMA
ID43 44
Oct. 01 Nov. 01
45 46 47
Jan. 02
48
Task Name01 025249 50 51
Dec. 01
04-05 Tests
02-03 Tests
04-02 Mixed Demodulator Algorithm
04-04 Optimization
03
03-01
04-03 PLL Demodulator Algorithm X
03-03 PLL Demodulator Algorithm X
Figure 2.1.: Project schedule
4
3. Theory
3.1. Frequency Modulation
Frequency modulation (FM) is a type of angle-modulated signal. A conventional angle modulatedsignal is defined by the following equation.
sFM(t) = A · cos(ωT · t +φFM(t)) (3.1)
for FM, the relation of sN to φFM is given by
φFM(t) = kFM ·∫
sN(t) · dt (3.2)
where ωT is the carrier angular frequency expressed ind rad/s and kFM is the modulation index.There is no connection between the spectrum of the message sN(t) and the spectrum of the modu-lated signal. If we use a harmonic message like
sN(t) = K · cos(ωN · t)
The modulated signal can be expressed as
sFM(t) = A · cos(ωT · t +φFM(t))
withφFM(t) = kFM ·
∫K · cos(ωN · t) · dt
The integral does not convert so
φFM(t) = kFM · K · limT→∞
t∫−T
cos(ωN · τ) · dτ =kFM · K
ωN·[
sin(ωN · t) + limT→∞
sin(ωN · T)]
φFM(t) =kFM · K
ωN· sin(ωN · t)
Letµ =
kFM · KωN
and ωN = 2 · π · fg, the frequency derivation is given by
∆F = µ · fg =kFM · K
2 · π (3.3)
The modulated FM signal is now
sFM(t) = A · cos [ωT · t + µ · sin(ωN · t)]
5
Theory
Using the Bessel function Figure
Jn(x) =∞
∑i=0
(−1)i
i! · (n + i)!· ( x
2)
n+2·i
and the relation
cos [α + x · sin(β)] =∞
∑n=−∞
Jn(x) · cos(α + n ·β)
the FM signal can be written as
sFM(t) = A ·∞
∑n=−∞
Jn(µ) · cos(ωT · t + n ·ωN)
the frequency response can be determined with the Fourier transformation
SFM(ω) =∞∫
−∞
sFM(t) · e− j·ω·t · dt
with∞∫
−∞
cos(ωx · t) · e− j·ω·t · dt = π · [δ(ω + ωx) + δ(ω−ωx)]
SFM can be expressed as
SFM(ω) =∞
∑n=−∞
Jn(µ) · π · [δ(ω + ωT + n ·ωN) + δ(ω−ωT − n ·ωN)]
In general the FM bandwidth is not limited, but it declines fast outside a bandwidth around thecarrier frequency. This bandwidth can be found using the Carson’s rule
bFM = 2 · (∆F + fg) (3.4)
where fg is the highest frequency in the message. Hence the bandwidth rises with a rising ∆F anda rising message frequency.
3.2. Algorithms for Signal Pretreatment
All the digital FM demodulation algorithms presented in the next section need the FM signal inthe baseband. Therefore the FM demodulation unit from Figure 1.1 is further divided into threeunits: subsampling, quadrature mixing and baseband FM demodulator (see Figure 3.1).
3.2.1. Subsampling
The FM signal after the bandpass filter has a carrier frequency of 10.7 MHz and a bandwidth of12.5 kHz. This results in a maximum frequency of over 10.7 MHz. Hence, a sampling rate of over21 MHz is required. This data rate is too fast for today DSP’s. However as the signal is frequencylimited (Bandwidth b), a subsampling is possible and the sampling rate can be calculated as follows[6]:In the special case that
f1 = λ · b , λ ∈ [N]f2 = (λ + 1) · b
6
3.2. Algorithms for Signal Pretreatment
FM demodulation
Subsampling Quadraturemixing
Baseband FMdemodulation
sFM
sFM
sFMsimag
srealsD
sD
Figure 3.1.: Subdivisions of FM demodulation block
the sample rate isfA = 2 · b (3.5)
for a non aliasing periodic sequel of the spectrum. Figure 3.2 shows the spectrum subsampling foran even λ. Figure 3.3 shows the subsampling for an odd λ.
ff1 f2
b
4b
f2b=fA
ffA
ff1 f2
b
3b
f2b=fA
ffA
Figure 3.2.: Spectrum subsampling with even λ
If the subsampling is interpreted in terms of the carrier frequency, fT
fT −b2
= λ · b
fT = b2λ + 1
2
For a general carrier frequency fT and bandwidth b, the condition of an even λ is often not fulfilled.Thus, the bandwidth has to increase.
b′ = b · q q > 1
7
Theory
ff1 f2
b
4b
f2b=fA
ffA
ff1 f2
b
3b
f2b=fA
ffA
Figure 3.3.: Spectrum subsampling with odd λ
the new bandwidth is
fT = b′2λ + 1
2
b′ =2 fT
2λ + 1
where λ is a largest integer number, but smaller than fT− b2
b . Therefore the sampling rate is
fA = 2 · b′ =4 fT
2λ + 1(3.6)
3.2.2. Quadrature-Mixer
The mixing to the baseband is carried out by the multiplication of the FM signal and a complexoscillator e jωT n and a low pass filter [6] (see Figure 3.4). The input signal is the modulated signal sFM
sFM(n) g(n) sbasis(n)
nj Te ω
Z*
Figure 3.4.: Quadrature-Mixer
sFM (n) = A · cos (ωTn +φFM (n)) (3.7)
The output signal of the mixer is:
g (n) = sFM (n) · e jωT n = A · cos (ωTn +φFM (n)) · e jωT n = A · e j(ωT n+φFM(n)) + e− j(ωT n+φFM(n))
2· e jωT n
=A2
[e j(ωT n+φFM(n)+ωT n) + e j(−ωT n−φFM(n)+ωT n)
]=
A2
[e j(2ωT n+φFM(n)) + e j(−φFM(n))
]
8
3.3. Algorithms for Digital FM Demodulation
sbasis (n) = (g (n) ∗ TP)∗ =(
A2
e− jφFM(n))∗
=A2
e jφFM(n) =A2
cos (φFM (n)) + jA2
sin (φFM (n))
(3.8)The result is a complex signal sbasis. The mixer can also be realized with real signals by multiplyingthe FM signal with a sine and cosine oscillation signal (see Figure 3.5). The input signal is again
sFM(n)cos(ωT n)
sin(ωT n)
gr1(n)
gi1(n)
sreal(n)
simag(n)
ωT
2ωT0
ω
ω
sfm
sreal/imag
-1
Figure 3.5.: Real quadrature-mixer
the FM signal sFM.sFM (n) = A · cos (ωTn +φFM (n))
Therefore, the output signals are
gr1(n) = sFM (n) · cos (ωTn) = A · cos (ωTn +φFM (n)) · cos (ωTn)
=A2
[cos (ωTn +φFM (n)−ωTn) + cos (ωTn +φFM (n) + ωTn)]
=A2
cos (φFM (n)) +A2
cos (2ωTn +φFM (n))
sreal(n) = gr1(n) ∗ gTP(n) =A2
cos (φFM (n)) (3.9)
gi1(n) = sFM (n) · sin (ωTn) = A · cos (ωTn +φFM (n)) · sin (ωTn)
=A2
[sin (−ωTn−φFM (n) + ωTn) + sin (ωTn +φFM (n) + ωTn)]
=A2
sin (−φFM (n)) +A2
sin (2ωTn +φFM (n))
simag (n) = (−1) · gi1 (n) ∗ gTP(n) =A2
sin (φFM (n)) (3.10)
It results in two signal, the real part sreal and the imaginary part simag, also known as the I (Inphase)and Q (Quadraturephase) signals.
3.3. Algorithms for Digital FM Demodulation
3.3.1. Baseband Delay Demodulator
As the name implies, the baseband delay demodulator needs the FM-Signal in the baseband. Forthat reason a quadrature mixing (see Section 3.2.2) has to be done first. Figure 3.6 shows the blockdiagram of the complex baseband delay demodulator. The input signal is the complex FM signal
9
Theory
Z-1
sbasis(n) g1(n)
Z*
arg
sbasisv(n)
g2(n) sD(n)FM
1T k⋅
Figure 3.6.: Complex baseband delay demodulator
in the baseband sbasis given in Eq. 3.8. With Eq. 3.2 the system can be described as follow, where Tis the sample time.
g1 (n) = sbasis · sbasisv = e jφFM(n) · e− jφFM(n−1) = e j(φFM(n)−φFM(n−1))
g2 (n) = arg (g1 (n)) = φFM (n)−φFM (n− 1)
sD (n) =g2 (n)T · kFM
=φFM (n)−φFM (n− 1)
T · kFM=
φ′FM (n)kFM
=kFM · sN (n)
kFM= sN (n) (3.11)
The output signal sD is equal to the original message sN . Hence, the system demodulates a com-plex FM signal in the baseband, sbasis.
One complex multiplication needs four real multiplications and is therefore time-consuming. Withthe formula of Euler the calculation can be written as
g1 (n) = e jφFM(n) · e− jφFM(n−1) = [cos (φFM (n)) + j sin (φFM (n))] · [cos (φFM (n− 1))− j sin (φFM (n− 1))]= cos (φFM (n)) cos (φFM (n− 1)) + sin (φFM (n)) sin (φFM (n− 1))
+ j [sin (φFM (n)) cos (φFM (n− 1))− cos (φFM (n)) sin (φFM (n− 1))]
= cos (φFM (n)−φFM (n− 1)) + j sin (φFM (n)−φFM (n− 1)) = e j(φFM(n)−φFM(n−1))
It shows that the required information appears in the real part as well as in the imaginary part.Thus the system can be reduced to the imaginary part. Using the two real signals in the basebandsreal from Eq. 3.9 and simag from Eq. 3.10 as input signals.Figure 3.7 shows the block diagram of the real baseband delay demodulator. The output signal is
Z-1
Z-1
sreal(n)
simag(n)
sreal(n-1)
simag(n-1)
h1(n)
h2(n)
+
-
arcsinsD(n)h3(n)
FM
1T k⋅
h4(n)
Figure 3.7.: Real baseband delay demodulator
h1 (n) = simag (n) · sreal (n− 1) = sin (φFM (n)) · cos (φFM (n− 1))h2 (n) = sreal (n) · simag (n− 1) = cos (φFM (n)) · sin (φFM (n− 1))
h3 (n) = h1 (n)− h2 (n) = sin (φFM (n)) cos (φFM (n− 1))− cos (φFM (n)) sin (φFM (n− 1))= sin (φFM (n)−φFM (n− 1))
10
3.3. Algorithms for Digital FM Demodulation
sD (n) = arcsin h3 (n) · 1T · kFM
=φFM (n)−φFM (n− 1)
T · kFM=
φ′FM (n)kFM
=kFM · sN (n)
kFM= sN (n)
(3.12)It is equal to the original message signal sN . The system demodulates the two real FM signals inthe baseband.
The signal after the arcsine
h4 (n) = φFM (n)−φFM (n− 1) = φ′FM · T = kFM · sN (n) · T = kFM · sN (n) · 1
fA
must be limited between − π2 and π
2 to be clearly defined
max(
kFM · sN (n) · 1fA
)=∣∣∣∣ kFM · sN
fA
∣∣∣∣ <π
2
From Eq. 3.3 the maximal frequency deviation can be calculated for flawless demodulation.
kFM · sN = ∆F · 2 · π∆F · 2 · π
fA<
π
2
∆F <π
2· fA
2 · π <fA
4(3.13)
It shows that the maximal ∆F depends on the sampling rate. Therefore it is not limited, becausewith rise of ∆F also the bandwidth of the FM-Signal rises. Thus the sample rate has to be increased.
The delay demodulator needs the modulated signal to have a constant amplitude, therefore anamplitude normalization has to be done prior to the delay demodulator.
Amplitude normalization
The received FM signal due to distortion in the channel is not known. However the delay demod-ulator needs a constant amplitude which is achieved by normalizing the magnitude of the signal.This is done by dividing the complex signal (Eq. 3.8) by its absolute value.
sout =sbasis
|sbasis|=
a (n) · e jφFM(n)∣∣a (n) · e jφFM(n)∣∣ =
a (n) · e jφFM(n)
a (n)= e jφFM(n)
The same applies to the two real signals of Eq. 3.9 and Eq. 3.10 (see Figure 3.8).The output signals are
out (n) =sreal + jsimag∣∣sreal + jsimag
∣∣ =sreal + jsimag√
s2real + s2
imag
=sreal√
s2real + s2
imag
+ jsimag√
s2real + s2
imag
The result is a constant amplitude signal normalized to one.
3.3.2. Phase-Adapter Demodulator
The phase-adapter demodulator also needs a FM signal in the baseband as input signal (see Sec-tion 3.2.2). It works with real signal, so the input is sreal of Eq. 3.9 and simag of Eq. 3.10. Figure 3.9shows the block diagram. The equation for the output signal is:
11
Theory
simag(n)
sreal(n) outreal(n)
outimag(n)
R
+
+
1•
2↑
2↑
Figure 3.8.: Real amplitude normalization
sreal(n)
simag(n)
arctansD(n)
Z-1
g(n) +
- FM
1T k⋅
Figure 3.9.: Phase-adapter demodulator
g (n) = arctan(
simag (n)sreal (n)
)= arctan
(sin (φFM (n))cos (φFM (n))
)= arctan (tan (φFM (n))) = φFM (n)
sD (n) =g (n)− g (n− 1)
T · kFM=
g′(n)kFM
= s(n) (3.14)
The output signal sD is equal to the original message sN . The system demodulates the FM signalin the baseband.
The signal after the arc tangent function g (n) = φFM (n) must be limited between − π2 and π
2 to beclearly defined. Assuming sinusoidal message signal, the following conditions can be derived:
|φFM (n)| < π
2
|φFM (n)| =∣∣∣∣ kFM · K
ωNsin(ωN · t)
∣∣∣∣ =kFM · K
ωN<
π
2
From Eq. 3.3the maximal frequency derivation can be determined.
kFM · sN = ∆F · 2 · π∆F · 2 · π2 · π · fN
=∆FfN
<π
2
∆F <π · fN
2(3.15)
The maximum derivation ∆F depends on the frequency of the message. In the worst case, for verylow message frequencies, the maximal derivation will be very low and not practicable for mostapplications. Therefore this demodulator is only useful for narrowband FM.
Because of the limitation of φFM the problem of a division by zero is eliminated. This is becausethe signal sreal = cos (φFM) can only be zero for φFM = ± π
2 · i, where i is an odd integer.
12
3.3. Algorithms for Digital FM Demodulation
3.3.3. Phase-Locked Loop
The Phase-Locked Loop (PLL) is a feedback loop. Besides digital demodulation, it is also used forcarrier and timing regeneration. Figure 3.10 shows the block diagram of a Phase-Locked Loop. FM
Phase Detector Loop Filter
VoltageControlledOscillator
sD(n)sFM(n)
Figure 3.10.: Phase-Locked Loop
modulation stores the information in the variation of frequency. The idea of a PLL is the following:With the help of the feedback loop, the controlled frequency should closely follow the referencefrequency. The controlled frequency in this case is the demodulated message sD(n), which shouldcorrespond to the original message sN(n). The reference is given by the modulated signal sFM(n),which indirectly represents the message sN(n). The Phase detector detects the phase differencebetween the modulated signal and the voltage controlled oscillator (VCO). This phase differenceis filtered by the loop filter that the message signal results.The actual realization of the PLL is shown in Figure 3.11. The function of the feedback loop will bediscussed now. The goal is to describe mathematically the assosiation between the reference signalsFM(n) and the controlled signal sFM(n). sFM(n) is:
sFM(n) = A · cos(ωT · n + kFM ·n−1
∑i=0
sN(i))
The PLL as shown in Figure 3.11 is a baseband PLL, so the FM-Siganl sFM(n) will be mixed to thebaseband prior to the demodulation (see Section 3.2.2). The upper signal path is:
A2· cos(kFM ·
n−1
∑i=0
sN(i))
and the lower is:A2· sin(kFM ·
n−1
∑i=0
sN(i))
Now the demodulated signal sD(n) can be written as:
sD(n) =
[A2· sin(kFM ·
n−1
∑i=0
sN(i)) · cos(kFM ·n−1
∑i=0
sD(i))− A2· cos(kFM ·
n−1
∑i=0
sN(i)) · sin(kFM ·n−1
∑i=0
sD(i))
]∗ g(n)
(3.16)
13
Theory
QuadratureMixer + G
sin
I
cos
-1
VoltageControlledOscillator
Loop Filter
Phase Detector
sD(n)sFM(n)
kFM
Figure 3.11.: Actual realization Phase-Locked Loop
It’s difficult to discuss the equation above because of the convolution. Therefore a transformationto the Z-Domain would simplify the analysis, this is not possible because of the nonlinear loop.To get rid of the convolution, the transfer function of the filter G is reduced to a constant P. Theconvolution is now replaced by a multiplication. Further more the brackets can be simplified bythe sine rule:
sD(n) =A · P
2· sin(kFM ·
n−1
∑i=0
sN(i)− kFM ·n−1
∑i=0
sD(i)) =A · P
2· sin
(kFM ·
n−1
∑i=0
sN(i)− sD(i)
)(3.17)
The equation can be written as:
n−1
∑i=0
sN(i)−sD(i) =arcsin( sD(n)·2
A·P )kFM
(3.18)
The aim of the feedback loop is to make:
sN(n) = sD(n)
This can be achieved if the right hand side of Eq. 3.18 is equal to zero. To do so, the constant P orkFM needs to be big enough. The PLL can be described by the equation:
n−1
∑i=0
kFM·sN(i)− kFM · sD(i) = 0
To fulfil the equation the PLL needs to control to:
sD(n) = sN(n)
14
3.3. Algorithms for Digital FM Demodulation
Like described above the filter G was reduced to a constant P to demodulate the FM signal. ThePLL is a nonlinear system. Nonlinear Systems have the characteristic to produce non harmonicfrequencies. These frequencies are undesirable because they cause a distortion. One way to reducethis is by adding a filter to the loop based on the specification of the message signal. However thesimulation showed that it makes the result even worse.
3.3.4. Mixed Demodulator
The mixed demodulator is a combination of the delay demodulator and the phase adapter Demod-ulator. That way, some of the disadvantages can be removed. Figure 3.12 shows the block diagram
Z-1
Z-1
sreal(n)
simag(n)
+
-
arctansD(n)g1(n)
sreal(n-1)
scos(n)
ssin(n)
+
+simag(n-1)
g2(n)FM
1T k⋅
Figure 3.12.: Mixed demodulator
of the mixed demodulator. The input signals are the two real signals sreal and simag after the mixingEq. 3.9 and Eq. 3.10. From Eq. 3.2 the output signal can be written as:
ssin (n) = simag (n) · sreal (n− 1)− sreal (n) · simag (n− 1)= sin (φFM (n)) · cos (φFM (n− 1))− cos (φFM (n)) · sin (φFM (n− 1))
= sin (φFM (n)−φFM (n− 1))
scos (n) = sreal (n) · sreal (n− 1) + simag (n) · simag (n− 1)= cos (φFM (n)) · cos (φFM (n− 1)) + sin (φFM (n)) · sin (φFM (n− 1))
= cos (φFM (n)−φFM (n− 1))
g1 (n) =ssin(n)scos(n)
=sin (φFM (n)−φFM (n− 1))cos (φFM (n)−φFM (n− 1))
= tan (φFM (n)−φFM (n− 1))
g2 (n) = arctan (g1 (n)) = φFM (n)−φFM (n− 1)
sD (n) =g2 (n)T · kFM
=φFM (n)−φFM (n− 1)
T · kFM=
φ′FM (n)kFM
= sN (n) (3.19)
15
Theory
The mixed demodulator demodulates the FM signals in the baseband.
Similarly the signal after the arc tangent g2 (n) needs to be limited between − π2 and π
2 . Thereforethe same conclusions for the ∆F as in the the delay demodulator can be made (refer to Eq. 3.13).∆F depends only on the sampling rate.
Because of the limitation of the signal g2 (n) the problem of a division by zero does not exist.The signal
scos (n) = cos (φFM (n)−φFM (n− 1)) = cos (g2 (n))
can be zero only when φFM = ± π2 · i, where i is an odd integer. To avoid a division by zero, the
output of the delay z−1 for the first sample needs to be initialized to a non-zero number.
16
4. Simulation
All the algorithms introduced in Section 3.3 will be simulated and evaluated by using SIMULINK r
(Dynamic Systems for MATLAB r) models.In this chapter, constants and parameters will be chosen. One parameter is kFM which is deter-mined by the signal specification. It can be calculated with Eq. 3.4 and the given bandwidth bFM:
bFM = 2 ·(∆F + fg
)= 2 ·
(s·kFM
2π+ fg
)s · kFM = 2π
(bFM
2 − fg
)kFM =
2π
s
(bFM
2− fg
)=
2π
1
(12500
2− 3400
)= 2π · 2850 ≈ 18000 (4.1)
To test the correctness of the algorithms, an ideal model was created for each algorithm. A DSPmodel was also created for each one of them, to cover the real time performance of the implemen-tation on hardware. To evaluate the robustness of the algorithms, Gaussian noise is added to thechannel in the model.The next section covers some of the knowledge, which apply to all algorithms and are mentionedhere not to repeat them each time.
4.1. General Knowledge from Simulations
4.1.1. Ideal Model
To make a statement about the quality of the signal, the harmonic distortion k was measured. InAppendix C.1 the procedure of measuring the harmonic distortion is explained. With the help ofthe Chirpsignal block of Simulink, a statement about the frequency response is possible. It showsthat for a rising kFM the signal quality sinks. This effect isn’t caused by the algorithm, it appearsas a result of the aliasing of the spectrum. The FM signal is in principle not bandlimited. Thebandwidth based on Carson includes only 90 % of the energy of the signal. So the aliasing appearswith a higher kFM after the subsampling.
4.1.2. DSP Model
There are fixed-point or floating-point DSP-Boards. The representable range of a 32bit fixed-pointnumber is about [
−216
2... +
216 − 12
]The range of a floating-point representation is
±[10−38...1038]
Floating-point numbers are more complex and so they need more processing time than fixed-pointnumbers. The simulations are made for fixed-points. This has the advantage of speed but also
17
Simulation
possesses some disadvantages. The number range is smaller and a quantization error is present.Also overflows can occur. For these reasons Quantizer and Saturation blocks were added to themodels. Figure 4.1 shows these blocks and Table 4.1 and Table 4.2 show the parameters of these
Quantizer Saturation
Figure 4.1.: Quantizer and saturation blocks in Simulink
blocks.
Table 4.1.: Parameter quantizerQuantization interval q
Table 4.2.: Parameter saturationUpper limit GOLower limit GU
There are two common ways to define the quantization interval q and the limits GO, GU . Onepossible set is :
q = 1
GO =216 − 1
2
GU = −216 − 12
the other is:
q =2
216 − 1GO = 1
GU = −1
For the simulation the second way, which is often called the Q format, was chosen.
The quantization can also be interpreted by adding Gaussian noise to the signal. For that reasonit makes sense to filter the demodulated signal sD(n) with a bandpass at the end. This bandpassneeds a pass band from 100Hz to 4000Hz, this bandwidth covers the specification of the messagesignal with a little reserve. The filter was designed as butterworth filter as followed:
Type ButterworthOrder 6Lower fg 100HzUpper fg 4000Hz
18
4.2. Algorithms for Signal Pretreatment
To make a statement about the quality of the demodulated signal, the SINAD was measured bythe DSP model. Appendix C.1 explains the exact procedure of the measurement.
4.1.3. DSP Model with Gaussian Noise
To simulate a interference channel a Gaussian noise was added to the modulated signal. Even thisis a very simple model, some good statements about the robustness of the algorithm can be made.The Signal to Noise Ratio (S/N) was measured at the demodulated signal. The power of the noisewas set, so the S/N ratio of the modulated signal is 10dB. The exact procedure of the measurementis explained in Appendix C.2. The S/N gets better with a rising kFM, this is due to the biggerspectrum spreading. Therefore a compromise between a big kFM for a good S/N and a small kFMfor a better signal quality has to be determined. A good kFM value is provided by Eq. 3.4 which isneeded for calculating the Carson bandwidth.
4.2. Algorithms for Signal Pretreatment
4.2.1. FM Modulator
To do the simulation, a FM Modulator block was created in Simulink. Figure 4.2 shows the block
s
Real (Cos)
Imag (Sin)
QuadraturMischer
Quad Mischer
sN sFMFMModulator
FM Modulator
sReal
sImag
sDBasisband
Verzögerungs-Demodulator
Basisband Verzögerungsdemodulator
In1
In2
Out1
Out2
ReelerAmplituden
Normalisierer
Amplituden Normalisierer
Figure 4.2.: Simulinkblock FMmodulator
=⇒
1sFM
wt
12:34
t
cos
cos
w
Trägerfrequenz
k
Modulationskonst.
Tz-1
Integrator
1sN
Figure 4.3.: Simulink model FM modulators
of the FM Modulator and Figure 4.3 shows the complete model. Table 4.3 shows the parameters ofthe block.
Table 4.3.: Parameter FM modulatorFM Constant FM modulation constant kFMSample Time sec Sample time of the simulationCarrier Frequency rad/sec Carrier frequency of FM signals
4.2.2. Subsampling
Figure 4.4 shows the structure of the subsampling model. The simulation works with two differentfrequencies fH und fA. fA is the sampling rate which can be calculated according to Eq. 3.6
fT − b2
b=
10700000− 125002
12500= 855.5 ⇒ λ = 854
19
Simulation
Zero-OrderHold1
Zero-OrderHold
nsignal2
To Workspace7
fmsignal2
To Workspace6
fmsignalH
To Workspace5
nsignal
To Workspace4
fmsignalA
To Workspace3
tvecH
To Workspace2
tvecA
To Workspace1
Sine Wave2 300
Sine Wave 300
sN sFMFM
Modulator
FM Modulator 2
sN sFMFM
Modulator
FM Modulator 1
12:34
Digital Clock
sN
sN
Figure 4.4.: Simulink model subsampling
fA =4 fT
2λ + 1=
4 · 107000002 · 854 + 1
= 25043.89Hz
The second frequency fH is used to simulate the continues, analog system which will be subsam-peled, and fulfils the sampling theorem for the modulated signal. It also has to be a multiple of fAto run the simulation. All this results in
fH = 855 · fA = 21412521.94Hz
The FM Modulator 1 modulates the message to a carrier frequency of 10.7Mhz. This signal isonce connected straight to output fmsignalH and once subsampled with fA and connected to out-put fmsignalA . The same message is modulated with FM Modulator 2 to a carrier frequencyof fA
4 and connected to output fmsignal2 .
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 107
0
0.1
0.2
0.3
0.4
f
fmsignalH
1.0695 1.07 1.0705 1.071 1.0715
x 107
0
0.1
0.2
0.3
0.4
f
fmsignalH ZOOM
0 0.5 1 1.5 2 2.5
x 104
0
0.1
0.2
0.3
0.4
f
fmsignalA
a)
b)
c)
Figure 4.5.: Plot 1 subsampling
0 0.5 1 1.5 2 2.5 3
x 104
0
0.05
0.1
0.15
0.2
f
fmsignalA
0 0.5 1 1.5 2 2.5 3
x 104
0
0.05
0.1
0.15
0.2
f
fmsignal2
0 0.5 1 1.5 2 2.5 3
x 104
-4
-2
0
2
4x 10-3
f
e
a)
b)
c)
Figure 4.6.: Plot 2 subsampling
Figure 4.5 shows the plot of the simulation with kFM = 10. A small spectrum for the FM-Signalresults. The spectrum of the subsampled signal fmsignalA is compared to the original spectrumfmsignalH . Figure 4.5 (a) shows the original spectrum over the entire frequency band from DCto fH , (b) shows the spectrum of the same signal just for the frequencies from 854 · fA to 855 · fA,
20
4.2. Algorithms for Signal Pretreatment
this is the part that is shifted by subsampling. (c) shows the spectrum of the subsampled signal.It shows that the FM signal has a carrier of fA
4 . Furthermore it shows that b) is shifted to c) asdescribed in Section 3.2.1.Figure 4.6 shows the plot of the simulation with kFM = 18000, which results in a wide spectrum.The spectrum of the subsampled signal fmsignalA is compared to the spectrum of the signalwhich was modulated direct to a carrier of fA
4 . Figure 4.6 (a) shows the spectrum of the subsampledsignal, (b) the spectrum of the direct modulated signal and (c) the error signal e given by:
e = fft (fmsignal2)−fft (fmsignalA)
The simulation result shows that the two spectrums are nearly identical. Hence, in subsequentsimulations, the subsampling will be left out and the message will be modulated directly by acarrier of a quarter of the sampling rate.
4.2.3. Quadrature-Mixer
s
Real (Cos)
Imag (Sin)
QuadraturMischer
Quad Mischer
sN sFMFMModulator
FM Modulator
In1
In2
Out1
Out2
ReelerAmplituden
Normalisierer
Amplituden Normalisierer
Figure 4.7.: Simulinkblockquadrature-mixer
=⇒2
Imag (Sin)
1Real (Cos)
b(z)a(z)
Tiefpass R
b(z)a(z)
Tiefpass I
Sin
Negierer
M R
M I
-1
Konstante
Cos1s
Figure 4.8.: Simulink model quadrature-mixer
Figure 4.7 shows the block of the Quadrature-Mixer and Figure 4.8 shows the complete subsystemmodel. Table 4.4 shows the parameters of the blocks. The two low-pass filters have butterworth
Table 4.4.: Parameter quadrature-mixerFilter Order Order of low-pass filter I low-pass filter RSample Time sec Sample time of the simulationEdge Frequency Hz Edge Frequency of low-pass filter I low-pass filter RCarrier Frequency rad/sec The carrier frequency of the FM signals
response low-passes and are calculated by MATLAB [b,a]=butter(ordnung,2*f*T). f is the cutoff fre-quency and T the sample time. Figure 4.9 shows the spectrum of the input signal sFM and the twooutput signal sreal and simag with the following parameters.
Filter Order 10Sample Time 40µsEdge Frequency 6250HzCarrier Frequency 2 · π · 6250rad/sec
21
Simulation
0 0.5 1 1.5 2 2.5
x 104
0
0.05
0.1
0.15
0.2
f
|A|
fmsignal
0 0.5 1 1.5 2 2.5
x 104
0
0.05
0.1
0.15
0.2sreal
0 0.5 1 1.5 2 2.5
x 104
0
0.05
0.1
0.15
0.2simag
Figure 4.9.: Plot quadrature-mixer
4.3. Baseband Delay Demodulator
4.3.1. Ideal Model
Figure 4.10 shows the Simulink model of the ideal baseband delay demodulator. Figure E.4 inthe Appendix shows the layout for the simulation. Table 4.5 shows the harmonic distortion factor
1sD
asin
arkussinus
Product1
Product
1/(s*K)
Normierung auf 1
z-1
Delay1
z-1
Delay
In1
In2
Out1
Out2
ReelerAmplituden
Normalisierer
Amplituden Normalisierer
2sImag
1sReal
sRealNV
sImagNV
sRealN
SImagN
Figure 4.10.: Simulink model baseband delay demodulator
k measured with various kFM and various frequencies of a harmonic sinusoidal message signal.With Eq. 3.13 the maximal ∆F and the maximal kFM can be calculated.
kFM =2 · π · fA
4s=
π · fA
2= 39′270
This kFM can never be reached due to the bandwidth. The increase in the harmonic distortion withrising kFM and rising frequency is caused by the increasing bandwidth, which results in aliasing.Figures 4.11 and 4.12 show (a) the spectrum of the input signal insignal , (b) the spectrum of theoutput signal outsignal and (c) a time slot of the input and the output signal. The input signalis a sinusoidal with a frequency of 2000 Hz. In Figure 4.11, kFM was set to 180 and in Figure 4.12it was set to 18000. It shows that a low-pass filter with a 3dB cutoff frequency fg ≈ 4000Hz at theoutput would improve the signal quality for higher kFM.To make statement about the frequency response of the signal a chirp signal from 300 to 3400 Hzwas applied. Figure 4.13 shows (a) the spectrum of the input signal and (b) to (e) the spectra ofthe output signal with various kFM. Therefore, that with a higher kFM and a high frequency theresponse degrades. This is again because of the aliasing.
22
4.3. Baseband Delay Demodulator
Table 4.5.: Harmonic distortion of the ideal delay demodulatorkFM fN k18 300 0.000180 300 0.0001800 300 0.00018000 300 0.01218 2000 0.000180 2000 0.0001800 2000 0.00318000 2000 0.21518 3400 0.000180 3400 0.0001800 3400 0.00618000 3400 0.355
0 0.5 1 1.5 2 2.5 3
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT insignal
0 0.5 1 1.5 2 2.5 3
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT outsignal
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
A
insignaloutsignal
c)
b)
a)
Figure 4.11.: Plot of delay demodulatorideal with kFM = 180
0 0.5 1 1.5 2 2.5 3
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT insignal
0 0.5 1 1.5 2 2.5 3
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT outsignal
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
A
insignaloutsignal
a)
b)
c)
Figure 4.12.: Plot of delay demodulatorideal with kFM = 18000
300 34000
a) Insignal
300 34000
b) kFM=18
300 34000
c) kFM=180
300 34000
d) kFM=1800
300 34000
e) kFM=18000
Figure 4.13.: Spectrum of the chirp signal from a ideal delay demodulator
23
Simulation
4.3.2. DSP Model
Figure E.2 in the Appendix shows the layout of the DSP simulation model. As described above,quantizer and saturation blocks were added. Also the cosine block was replaced by a lookup tablewith interpolation.The SINAD was measured for various frequencies with a constant kFM = 18000. Table 4.6 showsthe results with and without a bandpass filter at the output.
Table 4.6.: SINAD delay demodulator DSP modelfN k (without filter) k (with filter)300 0.018 0.0152000 0.218 0.0113400 0.288 0.085
Again a chirp signal from 300 to 3400 Hz was applied to the input. Figure 4.14 shows (a) thespectrum of the input signal and (b) the spectrum of the output signal with a kFM of 18000.
300 34000
a) Insignal
300 34000
b) Outsignal
Figure 4.14.: Spectrum of chirp signal for delay demodulator DSP model
In the DSP model of the Delaydemodulator, a lower limit for ∆F or rather kFM has to be set. Thisis because of the subtraction in the derivation. If the slope of the signal is small, the result of thesubstraction (div) is very small compared to the quantization interval q.
div = φFM (n)−φFM (n− 1)
Hence, the signal quality degrades, since div can not be quantized sufficiently. With a bigger kFM,the slope rises and so does div. The factor 1
T·kFMcan be interpreted as a metric for the degradation
of the signal quality. A factor of unit would be the ideal. This means, with a given sample rate thekFM should be equal to it. This is not possible because of the limitation in the bandwidth, but canbe achieved approximately.Another approach to enlarge div is to delay for k samples z−k instead of just delay for one samplez−1. This approach didn’t lead to a usable solution, because the output signal was deformed by asin(x)
x function. This can be shown as followed. The transfer function of the integrator is
z−1 · T1− z−1
24
4.4. Phase-Adapter Demodulator
multiplied with the transfer function of the one sample delayed derivative is
z−1 · T1− z−1 ·
1− z−1
T= z−1
The result is only a delay of one sample.Now the integrator is multiplied with the k sample delayed derivative
z−1 · T1− z−1 ·
1− z−k
T=
z−1 ·(1− z−k
)1− z−1
The z−1 is only a delay. The rest is1− z−k
1− z−1
This transfer function transformed to the time domain is a rectangle with the length k. Therefore adeformation of the spectrum with a sin(x)
x results.
4.3.3. DSP Model with Gaussian Noise
Figure E.2 in the Appendix shows the layout of the simulation with gaussian noise.Table 4.7 shows the signal to noise ratio (S/N) of the output signal. The power of the added noisewas set, so the S/N ratio of the modulated signal is 10dB.
Table 4.7.: S/N delay demodulator DSP modelfN S/N [dB] S/N [dB] S/N [dB] S/N [dB]
kFM = 9000 kFM = 12000 kFM = 15000 kFM = 18000300 7.84 10.41 12.56 14.311000 7.69 10.36 12.31 13.942000 7.74 10.38 12.22 13.483400 6.99 8.99 10.13 10.68
It shows, that with a rising frequency the S/N degrades This is because of the slight damping bythe higher frequencies (see Figure 4.13), which lowers the power of the signal. Due to the smallerspreading of the FM spectrum, the sinking ratio with a smaller kFM can be seen clearly.Figure 4.15 shows the input signal of the demodulator with a sinusoidal signal of 300 Hz. Fig-ure 4.16 shows a) the output signal in the same scale as the noise signal and b) the noise signalwhich was added. It shows that the noise was deformed and is rising with higher frequencies.This effect is due to the derivation, because higher frequencies are weighted more.
4.4. Phase-Adapter Demodulator
4.4.1. Ideal Model
Figure 4.17 shows the Simulink model of the ideal phase-adapter demodulator. Figure E.4 in theAppendix shows the layout for the simulation.Table 4.8 shows the harmonic distortion factor k measured for various kFM and frequencies of asinusoidal message signal. Using Eq. 3.15 the maximal ∆F and the maximal kFM can be calculated.
kFM =π2 · fN
s= π2 · fN
25
Simulation
0 0.5 1 1.5 2 2.5
x 104
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
f
|A|
FFT fmUnoise
Figure 4.15.: Plot FM signalwith noise
0 0.5 1 1.5 2 2.5
x 104
0
0.002
0.004
0.006
0.008
0.01
f
|A|
outsignal
0 0.5 1 1.5 2 2.5
x 104
0
0.002
0.004
0.006
0.008
0.01
f
|A|
noise
a)
b)
Figure 4.16.: Plot noise and output signal with noise
1sD
1/(s*k)
Normierung auf 1Divison
z-1
Delay
atan
Arkustangens
2sImag
1sReal
Figure 4.17.: Simulink model phase-adapter demodulator ideal
Table 4.8.: Harmonic distortion phase-adapter demodulatorkFM max(kFM) fN k18 1480 300 0.000180 1480 300 0.0001800 1480 300 0.99818000 1480 300 1.00018 9870 2000 0.000180 9870 2000 0.0001800 9870 2000 0.00318000 9870 2000 0.98418 16780 3400 0.000180 16780 3400 0.0001800 16780 3400 0.00618000 16780 3400 0.977
This equation is just valid for an ideal mathematical integrator, and so the sinusoidal signal wouldresult in a cosine signal. The integrator of the FM Modulator has an initial condition of zero andso the integrated signal has an offset. Hence, kFM has to be divided by two so that it is still limited
26
4.5. Phase-Locked Loop
between − π2 to π
2 after the arc tangent.
kFM =π2 · fN
2
As soon as this value is exceeded, the harmonic distortions raise above one and the demodulatorcan not be used anymore. Figures 4.18 and Figure 4.19 illustrate this. In both situations a sinusoidalsignal of 2000 Hz was modulated and demodulated. One with kFM = 180 and another withkFM = 18000.In both figures (a) shows the spectrum of the input signal and (b) shows the outputsignal, and (c) shows a time slot with input and output signals. This confirms the statement that
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT insignal
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT outsignal
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
A
insignaloutsignal
a)
b)
c)
Figure 4.18.: Plot phasea-adapter demod-ulator with kFM = 180
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT insignal
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT outsignal
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
A
insignaloutsignal
a)
b)
c)
Figure 4.19.: Plot phase-adapter demodu-lator with kFM = 18000
the Phase-Adapter-Demodulator is only useful for narrowband FM. Therefore it does not meet thespecifications and will not be discussed further.
4.5. Phase-Locked Loop
The loop gain P is the only unknown to be determined. In Section 3.3.3 it was described for smallkFM the loop gain P has to be set as big as possible. In this chapter kFM was set to 18000 due to theCarson bandwidth. Criteria Eq. 3.18, which discusses the error e(n) between sN(n) and sD(n), isreviewed here.
e(n) = sN(n)− sD(n)
n−1
∑i=0
sN(i)−sD(i) =arcsin( sD(n)·2
A·P )kFM
The best way to undo the summation on the left hand side is to change the expression to the Z-domain. In general:
a(n) =n−1∑
i=0b(n) ↔ A(z) = z
z−1 · B(z)
B(z) = z−1z · A(z) ↔ b(n) = a(n)− a(n− 1)
Substituted then into Eq. 3.18:
e(n) = sN(n)− sD(n) =arcsin( sD(n)·2
A·P )kFM
−arcsin( sD(n−1)·2
A·P )kFM
27
Simulation
The result of the arc tangent is between −π/2 and π/2. So the maximal error e(n) is:
|e(n)max| =π
kFM= 1.7453 · 10−4
Due to the normalization to one, the error is 0.017453 % of the signal amplitude. There is still thequestion of an appropriate loop gain P. It can be calculated with the help of Eq. 3.17:
sD(n) =A · P
2· sin(kFM ·
n−1
∑i=0
sN(i)− kFM ·n−1
∑i=0
sD(i)) =A · P
2· sin(
n−1
∑i=0
kFM·sN(i)− kFM · sD(i))
|sD(n)max| =A · P
2= 1
Because of the normalization, A and K (see Section 3.1) and the maximal value of sD(n) are equalto one. Thus P is
P = 2
But there is a problem here. The amplitude of the sinusoidal signal in Eq. 3.17 is exactly one onlyif the following condition is true:
∆F =kFM
2 · π = ωN (4.2)
This condition is analyzed in the time domain. The outputs of the mixer are:
A2· cos(kFM ·
∫sN(ωN · t) · dt) =
A2· cos(
kFM
ωN· SN(ωN · t)) (4.3)
andA2· sin(kFM ·
∫sN(ωN · t) · dt) =
A2· sin(
kFM
ωN· SN(ωN · t)) (4.4)
SN(ωN · t) is the antiderivative of sN(ωN · t) and ωN is the momentary frequency. So Eq. 4.2 canbe written as:
kFM = 2 · π ·ωN
Substitute the result in the Eq. 4.3 and Eq. 4.4
A2· cos(2 · π · SN(ωN · t))
andA2· sin(2 · π · SN(ωN · t))
It shows that in this case the argument of the cosine or the sine is between zero and 2 · π . If therange of the argument is smaller, the amplitude of the sine function in Eq. 3.17 is smaller than one.So the chosen loop gain of P = 2 is not sufficient to amplify the amplitude of the demodulatedsignal to one. In this case the demodulated signal is just proportional but not equal to the originalmessage.
4.5.1. Ideal Model
Figure E.5 in the Appendix shows the layout of the ideal simulation model in Simulink. Table 4.9shows the harmonic distortion factor k of the demodulated signal for various frequencies and kFMof a sinusoidal message.Figure 4.20 and Figure 4.21 confirm the measurements of the harmonic distortion. a) shows thespectrum of the message sN(n). It is a sinusoidal signal with a frequency of fN = 2000Hz. (b)
28
4.5. Phase-Locked Loop
Table 4.9.: Harmonic distortion PLLkFM fN k18 300 0.167180 300 0.0021800 300 0.02218000 300 0.04618 2000 0.162180 2000 0.0021800 2000 0.00018000 2000 0.14418 3400 0.152180 3400 0.0021800 3400 0.00318000 3400 0.254
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.02
0.04
0.06
0.08
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.20.: Plot PLL ideal with kFM =1800
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.21.: Plot PLL ideal with kFM =18000
shows the spectrum of the demodulated signal sD(n) ,and (c) shows a time slot of sN(n) and sD(n).In Figure 4.21 (b) the harmonic distortion is worsen at frequencies over 5000 Hz. Figure 4.22 shows(a) the spectrum of the message signal and (b), (c), and (d) the spectra of the demodulated signalsfor various kFM. The message signal is a chirp signal from fN = 300Hz to fN = 3400Hz.
4.5.2. DSP Model
Figure E.6 in the Appendix shows the layout of the DSP simulation. As mentioned earlier quan-tizer and saturation blocks were added. Table 4.10 shows the results of the SINAD measurements.It was measured with and without a bandpass filter at the output. The filter improves the qualityof the demodulated signal.Figures 4.23 to 4.27 illustrate the measurements of the SINAD. The same problem with additionalhigh frequencies generated by a higher kFM appears. This problem is reduced by the filter. Fig-ure 4.27 shows the demodulated signal sD(n) with a bandpass in the feedback loop. Figure 4.27(b) shows that a lot of additional frequencies appear. Hence a filter in the loop doesn’t bring anybenefits. On contrary it worsens the quality.
29
Simulation
300 34000
a) Insignal
f
|A|
300 34000
b) kFM=180
f
|A|
300 34000
c) kFM=1800
f
|A|
300 34000
d) kFM=18000
f
|A|
Figure 4.22.: Spectrum of the chirp signal for the ideal PLL
Table 4.10.: SINAD PLLkFM fN k with filter k without filter18 300 0.018 0.168180 300 0.018 0.0211800 300 0.025 0.03618000 300 0.088 0.19818 2000 0.041 0.195180 2000 0.043 0.1141800 2000 0.042 0.11518000 2000 0.080 0.24718 3400 0.076 0.218180 3400 0.078 0.1861800 3400 0.078 0.18618000 3400 0.080 0.396
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.02
0.04
0.06
0.08
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.23.: PLL DSP kFM = 1800, withbandpass filter
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.24.: PLL DSP kFM = 18000,with bandpass filter
4.5.3. DSP Model with Gaussian Noise
Table 4.11 shows the S/N ratios of the PLL with various kFM. It was stated above that a bettersignal quality is achieved with a smaller kFM, the degradation wasn’t serious though. This model
30
4.6. Mixed Demodulator
0 0.5 1 1.5 2 2.5
x 104
0
0.5
1
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.02
0.04
0.06
0.08
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.25.: PLL DSP kFM = 1800,without bandpass filter
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.26.: PLL DSP kFM = 18000,without bandpass filter
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT t1
0 0.5 1 1.5 2 2.5
x 104
0
0.05
0.1
0.15
0.2
f
|A|
FFT t2
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
|A|
t1t2
a)
b)
c)
Figure 4.27.: PLL DSP kFM = 18000, with the bandpass filter in the feedback loop
Table 4.11.: S/N PLLfN S/N [dB] S/N [dB] S/N [dB] S/N [dB]
kFM = 9000 kFM = 12000 kFM = 15000 kFM = 18000300 11.90 10.39 8.754 7.451000 10.71 11.73 12.29 12.022000 8.22 10.24 11.66 12.623400 5.23 7.70 9.44 10.59
shows that with a bigger kFM, an improvement in the S/N ratio can be achieved. The specifiedkFM = 18000 will achieve the best results.
4.6. Mixed Demodulator
4.6.1. Ideal Model
Figure 4.28 shows the Simulink model of the Mix Demodulator. Figure E.4 in the Appendix showsthe layout of the Simulink simulation.Table 4.12 shows the harmonic distortion factor k, measured for various kFM and various frequen-
31
Simulation
1sD
Product3
Product2
Product1
Product
1/(T*K)
Normierungauf 1
Divisionz-1
Delay1
z-1
Delay
atan
Arkustangens
2sImag
1sReal
sRealNVsRealNV
sImagNV
sImagNV
sImagNV
Figure 4.28.: Simulink model mixed demodulator ideal
cies of a sinusoidal message signal.
Table 4.12.: Harmonic distortion factor mixed demodulator idealkFM fN k18 300 0.000180 300 0.0001800 300 0.00018000 300 0.01218 2000 0.000180 2000 0.0001800 2000 0.00318000 2000 0.21718 3400 0.000180 3400 0.0001800 3400 0.00618000 3400 0.353
Like the delay demodulator the maximal ∆F can be calculated by Eq. 3.13. From which the maxi-mal kFM can be determined.
kFM =2 · π · fA
4s=
π · fA
2= 39′270
Due to the bandwidth limitation,this kFM is not reachable. The degradation of the harmonic dis-tortion with rising kFM and higher frequencies is again the result of the starting aliasing.Figure 4.29 and Figure 4.30 show (a) the spectrum of the input signal insignal , (b) the spectrumof the output signal outsignal and (c) a time slot of the input and output signals. The inputsignal is a sinusoidal signal with a frequency of 2000 Hz. In Figure 4.29, a kFM of 180 was applied.In Figure 4.30 the kFM is 18000. It shows again that a low-pass filter with fg ≈ 4000Hz at the outputcould improve the signal quality under a high kFM.Again a chirp signal from 300 to 3400 Hz was applied to the input. Figure 4.31 shows (a) thespectrum of the input signal and (b) to (e) the spectra of the output signals with various kFM. It canbe seen that the signal transmission worsens with higher frequencies, again because of the aliasing.
32
4.6. Mixed Demodulator
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT insignal
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT outsignal
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
A
insignaloutsignal
a)
b)
c)
Figure 4.29.: Plot of ideal mixed demodu-lator with kFM = 180
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT insignal
0 0.5 1 1.5 2 2.5
x 104
0
0.2
0.4
0.6
0.8
f
|A|
FFT outsignal
0.01 0.0105 0.011 0.0115 0.012 0.0125 0.013 0.0135 0.014 0.0145 0.015
-1
0
1
t
A
insignaloutsignal
a)
b)
c)
Figure 4.30.: Plot of ideal mixed demodu-lator with kFM = 18000
300 34000
a) Insignal
300 34000
b) kFM=18
300 34000
c) kFM=180
300 34000
d) kFM=1800
300 34000
e) kFM=18000
Figure 4.31.: Spectrum of the chirp signal for an ideal mixed demodulator
4.6.2. DSP Model
Figure E.9 in the Appendix shows the layout of the Simulink simulation. As mentioned before,quantizer and saturation blocks were added. In addition the arc tangent block was replaced by alookup table with interpolation.The SINAD was measured again for various frequencies and a constant kFM = 18000. Table 4.13shows the results with and without a bandpass filter at the output.
Table 4.13.: SINAD DSP mixed demodulatorfN k (without filter) k (with filter)300 0.013 0.0122000 0.216 0.0083400 0.286 0.087
Again a chirp signal from 300 to 3400 Hz was applied to input. Figure 4.32 shows (a) the spectrumof the input signal and (b) the spectrum of the output signal with a kFM of 18000.For the mixed demodulator, the lower limit for kFM is given as by the delay demodulator describedin Section 4.3.2.
33
Simulation
300 34000
a) Insignal
300 34000
b) Outsignal
Figure 4.32.: Spectrum of the chirp signal for DSP mixed demodulator
4.6.3. DSP Model with Gaussian Noise
Figure E.9 in the Appendix shows the layout for the Simulink simulation of the DSP model withgaussian noise.Table 4.14 shows the S/N ratio at the output of the demodulator. The power of the added noisewas set, so the S/N ratio of the modulated signal is 10dB.
Table 4.14.: S/N DSP Mix DemodulatorfN S/N [dB] S/N [dB] S/N [dB] S/N [dB]
kFM = 9000 kFM = 12000 kFM = 15000 kFM = 18000300 7.83 10.41 12.44 13.711000 7.70 10.33 12.24 13.432000 7.77 10.39 12.10 12.643400 6.97 8.81 9.41 8.40
Figure 4.33 shows the noisy FM signal, which is applied to the demodulator. The message is asinusoidal signal with a frequency of fN = 300Hz. Figure 4.34 shows (a) the noise signal whichwas added, (b) the output signal with the same scale as the noise. The deformation of the noisedue to the derivation was observed evidently.
4.7. Comparison of the Algorithms
In this section the algorithms will be compared to each other concerning signal quality, robustness,computing power and storage utilization. The phase-adapter demodulator will not be included inthe comparison, because it does not meet the specifications.
4.7.1. Signal Quality
The comparison regarding the signal quality is done on the basis of the harmonic distortion andSINAD. The delay demodulator and the mixed demodulator show nearly identical values for theideal and the DSP models, due to their similarity. The harmonic distortion rises with rising fre-quencies or rising kFM, which is, due to rising bandwidth and aliasing. The PLL also shows a
34
4.7. Comparison of the Algorithms
0 0.5 1 1.5 2 2.5
x 104
0
0.02
0.04
0.06
0.08
0.1
0.12
0.14
0.16
f
|A|
FFT fmUnoise
Figure 4.33.: Plot of FM sig-nal with noise
0 0.5 1 1.5 2 2.5
x 104
0
0.002
0.004
0.006
0.008
0.01
f
|A|
outsignal
0 0.5 1 1.5 2 2.5
x 104
0
0.002
0.004
0.006
0.008
0.01
f
|A|
noise
a)
b)
Figure 4.34.: Plot of the noise and the output signal
similar behavior, with a small difference that the harmonic distortion is rising for a very small kFM.In general, the values of k for all the algorithms are fairly close.
Harmonic Distortion
0
0.05
0.1
0.15
0.2
0.25
0.3
0.35
0.4
0 1000 2000 3000 4000f [Hz]
k
Delay Dem. PLLMixed Dem.
Figure 4.35.: Comparison of the harmonic distortion for ideal models of different algorithms with constantkFM of 18000 and variable frequency
Another performance characteristic can be compared by applying a chirp signal. Again the delaydemodulator and the mixed demodulator show nearly the same behavior. The PLL has a slightlyworse frequency response.
4.7.2. Robustness
The robustness measure gives the information on how the demodulator acts with noise on thechannel. The signal to noise ratio (S/N) of the demodulated signal provides an insight into therobustness. Therefore, a Gaussian noise was added to the FM-Signal before applying to the de-modulator and the ratio was measured at the output. In this measurement the delay demodulator
35
Simulation
Harmonic Distortion
0
0.05
0.1
0.15
0.2
0.25
0 5000 10000 15000 20000k FM
k
Delay Dem. PLLMixed Dem.
Figure 4.36.: Comparison of harmonic distortion for ideal models of different algorithms with constant fre-quency of 2000Hz and variable kFM
SINAD
00.010.020.030.040.050.060.070.080.09
0.1
0 1000 2000 3000 4000f [Hz]
SIN
AD Delay Dem.
PLLMixed Dem.
Figure 4.37.: Comparison of SINAD for DSP models of different algorithms with constant kFM of 18000 andvariable frequency
and the mixed demodulator show a similar behavior, with a slightly better result obtained by thedelay demodulator. The S/N drops in both demodulators with an sinking kFM owing to sinkingfrequency spreading. With higher frequencies, the ratio sinks a little, because of the sinking fre-quency response at high frequencies. The PLL shows a different behavior for low frequencies. Theratio sinks not just for high frequencies but also for the low ones.
4.7.3. Computing Power and Storage Utilization
In this section no absolute values will be determined. Just a cross comparison is done.All the algorithms need a mixer so this block will be left out for the comparison. First the delay de-modulator and the mixed demodulator will be compared. They both use about the same amountof additions and multiplications. Both of them need a division and one arc table function. Also thedelay register is of the same size. However, the delay demodulator needs an additional table forthe root function in the amplitude normalization. Hence it needs a little bit more storage and com-puting power. The PLL needs the least computing power as no division is required. Besides, thenumber of additions and multiplications is smaller. The trigonometric functions sine and cosinecan be realized with just one table. Hence the storage requirement is about the same as that of the
36
4.7. Comparison of the Algorithms
Signal-To-Noise Ratio
0
2
4
6
8
10
12
14
16
0 1000 2000 3000 4000f [Hz]
S/N
Delay Dem. PLLMixed Dem.
Figure 4.38.: Comparison of S/N ratio for different demodulation algorithmen, with a kFM of 18000
mixed demodulator. So the following ranking can be obtained.Computing power:
PLL < MixedDemodulator ≈ DelayDemodulator
Storage utilization:PLL ≈ MixedDemodulator < DelayDemodulator
4.7.4. The Appropriate Algorithm
Out of this knowledge the mixed demodulator seems to be the most suitable algorithm. Its realiza-tion needs less storage than that of the delay demodulator to achieve nearly the same signal qualityand robustness. The PLL requires less resources, but its robustness is worse for low frequencies.Hence, the mixed demodulator is the first choice for the implementation. The PLL is the secondbecause of low computing power.
37
Simulation
38
5. Implementation
The mixed demodulator and the PLL demodulator are implemented on a Texas InstrumentTMS320C6711 digital signal processor. A DSP starter kit is used which includes aTMS320C6711DSK board and the Code Composer Studio (CCS) IDE. The CCS is is a completeIDE featuring code building, debugging and real time analysis. It is especially designed for TexasInstrument DSP’s. Also included are DSP/BIOS a Chip Support Library (CSL) and a Board Sup-port Library (BSL). It supports implementation in C++ , C and Assembler.
The algorithms are implemented in C. The first approach is implemented in floating-point to avoidproblems with overflows and quantization. The code sequences are kept simple without any op-timization or time effective programming. The transformation of the algorithm to C code at thisstage aims at only verifying its functionality on the targeted DSP.In the next step the floating-point implementation is transformed into a fixed-point with still nogreat effort in speed optimization. The problems of overflows and quantization are discussed.Thereafter, the C implementation is optimized in speed. Finally some of time intensive parts arewritten in linear assembler to decrease the computing load.
5.1. System Architecture
5.1.1. Signal Path
Figure 5.1 outlines the floating-point implementation of the demodulator. It shows the samplingrates and the buffer lengths for the different stages of the demodulation. The entry end exit pointsof the functions are marked and the used buffers are shown. For specific buffers a sketch of thesignal’s spectrum is shown.Figure 5.2 shows the same for the fixed-point implementation.
39
Implementation
IIR LP IIR LP
IIR OSZ
ID
emod
ulat
ion
Algo
rithm
IIR BPAD
CD
AC
leng
ht 1
28
in_b
uffe
rle
nght
128
re_b
uffe
r
leng
ht 1
28
im_b
uffe
r
leng
ht 3
2
im_b
uffe
r_do
wn_
one
leng
ht 3
2
re_b
uffe
r_do
wn_
one
leng
ht 3
2
out_
buffe
r_do
wn_
one
leng
ht 1
6
out_
buffe
r_do
wn_
two
4 4
2
Sam
plig
Rat
e63
.993
kH
z15
.998
kH
z79
99 H
z
Buf
fer L
engt
hBU
FFER
SIZE
_IN
PUT=
128
BUFF
ERSI
ZE_D
EMO
DU
LATO
R=3
2BU
FFER
SIZE
_OU
TPU
T=16
Func
tion
8 k
16 k
16 k
64 k
2fT
64 k
f T
quad
_mix
mix
ed_d
emod
ulat
epl
l_de
mod
ulat
eou
t_fil
ter
0
00
00
leng
ht 1
28
re_b
uffe
r
leng
ht 1
28
im_b
uffe
rle
nght
32
out_
buffe
r_do
wn_
one
dow
nsam
ple
_one
dow
nsam
ple
_tw
o
Func
tion
Entry
Func
tion
Exit
nD
owns
ampl
ing
Figure 5.1.: Overview of floating-point implementation
40
5.1. System Architecture
IIR LP IIR LP
IIR OSZ
ID
emod
ulat
ion
Algo
rithm
IIR LPAD
CD
AC
leng
ht 1
28
re_b
uffe
r
leng
ht 1
28
im_b
uffe
r
leng
ht 3
2
im_b
uffe
r
leng
ht 3
2
re_b
uffe
r
leng
ht 3
2
out_
buffe
r
leng
ht 1
6
out_
buffe
r_do
wn
4 4
2
Sam
plig
Rat
e63
.993
kH
z15
.998
kH
z79
99 H
z
Buf
fer L
engt
hBU
FFER
SIZE
_IN
PUT=
128
BUFF
ERSI
ZE_D
EMO
DU
LATO
R=3
2BU
FFER
SIZE
_OU
TPU
T=16
Func
tion
8 k
16 k
16 k
64 k
2fT
64 k
f T
quad
_mix
mix
ed_d
emod
ulat
epl
l_de
mod
ulat
eou
t_fil
ter
0
00
00
IIR HP
Func
tion
Entry
Func
tion
Exit
nD
owns
ampl
ing
leng
ht 1
28
in_b
uffe
r_A
Figure 5.2.: Overview of fixed-point implementation
41
Implementation
5.1.2. The Sampling Rates
In Section 4.4 a sampling rate of 25043.89Hz was calculated according to Eq. 3.6. This would be theideal sampling frequency for the subsampling, but the hardware sets the following limitations:
Analog Digital (Converter THS1408) The clock of the ADC is generated by the Timer inside theDSP. Therefore only sampling rates of fA = 150MHz
8·i are possible, where i is an integer.
Digital Analog (Converter On Board Codec) The on board codec has an unchangeable sam-pling rate of 8000Hz. Thus the sampling rate of the ADC has to be a multiple of 8000Hzfor the downsampling.
In addition, the conditions of the subsampling need to be fulfilled by the sample rate of the ADC.With the hardware setup of the DSP DSK and the ADC EVM it is not possible to meet all these con-ditions because it is not possible to run the ADC with a multiple frequency of the DAC frequency.The sample rate which was chosen is
fA =150MHz
8 · 293= 63.993kHz
it meets all conditions except the one for the downsampling. During the processing the signal willbe totally downsampled by 8 and therefore the sampling frequency of the output signal is:
fA =1500000008 · 293 · 8
=63993.17
8= 7999.15Hz
Therefore the output samples arrive too early (Figure 5.3), and the output signal appears to be
t
t
input7999.15 Hz
output8000 Hz
Figure 5.3.: Input and output samples
slightly faster. This is not a problem because the difference is smaller than 1 Hz. The problemis that about every second there is a missing sample. Therefore a value between the last outputand the next to come is interpolated for the missing sample. Due to the phase shift of about onesampling period introduced by the additional sample, a low short rustle in the output signal canbe heard every time the additional sample is issued.This problem is introduced by the hardware and could be solved by using one master clock fromwhich both the ADC clock and the DAC clock are derived so that both ADC and DAC operationsare synchronized. An attempt was made to realize this hardware solution with the DSK by wiringthe codec clock (4.096 MHz) to the input pin of the DSP timer. Unfortunately the clock was notable to drive both the codec and the timer input. The effort of adding a driver was not made.Because the noise introduced by this error is very small and as audible for just pure sinusoidal sig-nals and not for speech, no further efforts were done to reduce it. In a commercial implementationthe solution with a master clock would eliminate this problem completely.
42
5.1. System Architecture
-13.140 fM = 13.1400
f [kHz]
|A|12.5 kHz
-13.140 26.2800
f [kHz]
|A|
13.140-26.280
-13.140 26.2800
f [kHz]
|A|
13.140-26.280
FM signal after subsampling
I and Q signal before filter
I and Q signal after filter
Figure 5.4.: Spectrum of FM signal after subsampling
The spectrum of the FM signal after the downsampling is shown in Figure 5.4. The new carrierfrequency fM can be calculated with equation
fM = fT − fA · floor(
fT
fA
)= 10.7 · 106 − 63993 · floor
(10.7 · 106
63993
)= 13.140Hz (5.1)
where fT is the carrier frequency of the analog FM signal.
5.1.3. Analog-to-Digital Conversation THS1408
The on board codec of the DSP DSK has a fix sample rate of 8000 Hz. Therefore an additional ADC(THS1408 EVM) is connected to the daughtercard connectors of the DSP. The data from the ADCis transferred by the Enhanced Direct Memory Access unit (EDMA) to reduce the workload of theDSP.The implementation to setup the ADC and the EDMA is done in the two files adc_THS1408.h(Listing F.1) and adc_THS1408.c (Listing F.2). It uses the EMIF, EDMA, TIMER, and IRQ modulesof the Chip Support Library (CSL) to provide an interface to control and configure the on chipperipherals of the DSP.
THS1408
THS1401, THS1403, THS140814-BIT, 1/3/8 MSPS DSP COMPATIBLE ANALOG-TO-DIGITAL CONVERTERS
WITH INTERNAL REFERENCE AND PGA
SLAS248B – DECEMBER 1999 – REVISED JANUARY 2001
1POST OFFICE BOX 655303 • DALLAS, TEXAS 75265
features
� 14-Bit Resolution
� 1, 3, and 8 MSPS Speed Grades Available
� Differential Nonlinearity (DNL) ±0.6 LSB Typ
� Integral Nonlinearity (INL) ±1.5 LSB Typ
� Internal Reference
� Differential Inputs
� Programmable Gain Amplifier
� µP Compatible Parallel Interface
� Timing Compatible With TMS320C6000 DSP
� 3.3-V Single Supply
� Power-Down Mode
� Monolithic CMOS Design
applications
� xDSL Front Ends
� Communication
� Industrial Control
� Instrumentation
� Automotive
14 15
WROEDGNDDGNDCLKDVDDDVDDD0D1D2DVDDDGND
36
35
34
33
32
31
30
29
28
27
26
25
16
1
2
3
4
5
6
7
8
9
10
11
12
IN–AVDDVBGCML
REF+REF–
AGNDAGNDDGND
OVD13D12
17 18 19 20
A0
A1
NC
NC
47 46 45 44 4348 42
IN+
AV
AG
ND
AG
ND
AG
ND
D5
D4
D3
DG
ND D9
D8
D7
D6
40 39 3841
21 22 23 24
37
13
CS
D11
D10
PFB AND PHP PACKAGE(TOP VIEW)
DD
AV
DD
DV D
D
DV D
D
DV D
D
NC – No internal connection
Copyright 2001, Texas Instruments IncorporatedPRODUCTION DATA information is current as of publication date.Products conform to specifications per the terms of Texas Instrumentsstandard warranty. Production processing does not necessarily includetesting of all parameters.
Please be aware that an important notice concerning availability, standard warranty, and use in critical applications ofTexas Instruments semiconductor products and disclaimers thereto appears at the end of this data sheet.
On products compliant to MIL-PRF-38535, all parameters are testedunless otherwise noted. On all other products, productionprocessing does not necessarily include testing of all parameters.
Figure 5.5.: THS1408
The THS1408 is a 14-bit, 8MSPS single supply analog-to-digital converter with an internal refer-ence, differential inputs, programmable input gain and on-chip sample and hold amplifier. Formore detailed information refer to [11] and [12]. The jumper settings of the EVM are summarizedin Table 5.1. The Power to the EVM is supplied from the DSP DSK (jumper H14). The input is
43
Implementation
Table 5.1.: Jumper settings THS1408Jumper Setting Description Jumper Setting Description
H1 - unused H9 2-3 inputH2 - unused H10 - unusedH3 - clock H11 - unusedH4 - unused H12 - hardware loopbackH5 - clock H13 - hardware loopbackH6 1-2 clock H14 1-2 powerH7 2-3 input H15 2-3 boardH8 1-2 input
applied as a single ended input (jumpers H7 to H9). The other jumper settings are explained in thefollowing sections.
Address Mapping
The ADC EVM is connected to the DSP DSK via the daughtercard connectors. The device containsseveral registers. A register is selected by the values of the A1 and A0 in Table 5.2. Figure 5.6
Table 5.2.: Addresses of registers THS1408A1 A0 Register Abbreviation HEX Address0 0 Conversation result RES 0xA000’00400 1 PGA (Gain) PGA 0xA000’00441 0 Offset OFF 0xA000’00481 1 Control CTL 0xA000’004C
shows how the address bus is wired to the EVM and the ADC, with the jumper H15 set to 2-3. The
TMS320C6711
CE2*
EA6EA5EA4EA3EA2
XC9536XL
OUT_CE2*
OUT_EA6OUT_EA5OUT_EA4OUT_EA3OUT_EA2
THS1408
A1A0
CS*ADCCSB
Figure 5.6.: Schema address bus wiring THS1408
EVM uses a Xilinx XC9536 CPLD to perform the address decode and control. Table 5.3 is the truthtable of the address decode logic.The CE2 signal is a EMIF memory space enable signal. On the C6711 it defines the memory blockfrom address 0xA000’0000 with the length of 256MB [14]. With this information the addresses ofthe THS1408 registers can be determined (Table 5.2).The off chip memory is accessed through the EMIF, therefore the values for the CE2CTL register ofthe EMIF have to be set according to the specifications of the THS1408 ADC (Tabel 5.4 [12] [16]).
44
5.1. System Architecture
Table 5.3.: Truth table address decode THS1408OUT_EA6 OUT_EA5 OUT_EA4 OUT_EA3 OUT_EA2 OUT_CE* DACCSB1 0 0 0 0 0 01 0 0 0 1 0 01 0 0 1 0 0 01 0 0 1 1 0 01 0 1 0 0 0 11 0 1 0 1 0 11 1 0 0 0 0 0All other combinations 1
Table 5.4.: EMIF timing registers for THS1408Field Abbreviation ValueRead Setup RDSETUP 1Read strobe RDSTRB 3Read hold RDHLD 1Write setup WRSETUP 4Write strobe WRHLD 6Write hold WRSTRB 3Memory type MTYPE 32-bit-wide asynchronous interface
Conversion Rate
The clock for the ADC is generated with the timer 0 of the DSP. Jumpers H3, H5, and H6 of theEVM have to be set according to Table 5.1, to connect the timer output to the clock input of theADC. The timer 0 is clocked by the internal source of CPU_Rate/4 = fCPU
4 .
f (clock_source) =fCPU
4
The output is set as clock output, the frequency is
fclk =f (clock_source)
2 · timer_period_register
hence the frequency is:
fclk =fCPU
4 · 2 · i(5.2)
Where i is the value set in the timer period register and fCPU is the DSP Speed. The timer periodregister is set to i = 293 which results in a frequency of fclk = fA = 63993Hz. The selection of thesampling rate is further explained in Section 5.1.2.
Ping Pong Buffering
To reduce the overhead of interrupt routines vector processing is applied. The CPU will not beinterrupted by every new value from the ADC to fetch it. Instead, the EDMA will take care ofthis. The EDMA will transfer the values from the ADC to the memory of the DSP and interruptthe CPU after one hole vector (in this case 128 values) has been transferred. Then the hole vectorcan be processed by the CPU, while the EDMA will continue to fetch the ADC values. To avoid
45
Implementation
the EDMA overwriting the values on which the CPU is working, the vector is transferred to twodifferent buffers. One buffer will be filled by the EDMA while the CPU is working with the otherbuffer (Figure 5.7). This is widely known as Ping Pong Buffering.
ADC EDMA CPU
t1
t1
Buffer
t2
t2
Ping(in_buffer_A)
Pong(in_buffer_B)
Figure 5.7.: Ping Pong Buffering
To do this, one EDMA Channel and two EDMA Reload Tables are needed. Two configurationsare needed, one for the ping and one for the pong buffer. In both of them the source address isthe Conversion Result Register (0xA000’0040) of the ADC and the source increment is disabled.The destination address in one of them is the start address of the ping buffer and the start addressof the pong buffer is the destination of the other. The destination increment is enabled and thecounter is set to the length of the vector (in this case 128). The link in the configuration for pingpoints to the configuration of the pong buffer and visa versa to result in a circular system. This isillustrated in Figure 5.8.
Ping
OptionsSource Address
Destination Address
Link Adr-- 128
- 1
OptionsSource Address
Destination Address
Link Adr-- 128
- 1
OptionsSource Address
Destination Address
Link Adr-- 128
- 1
ADC
EDMA Channel
EDMA Reload Tables
Ping
conf
igur
atio
nPi
ngco
nfig
urat
ion
Pong
conf
igur
atio
n
Pong
Figure 5.8.: EDMA setup for Ping Pong Buffering
Then the EDMA is configured to interrupt the CPU after a hole vector is transferred and the EDMAinterrupt is enabled on the DSP. To determine which buffer the EDMA has just finished fillingeach configuration sets a different field in the Channel Interrupt Pending Register (CIPR). This is
46
5.1. System Architecture
specified by the Transfer Complete Code (TCC) field in the option part of the configuration. Formore information on EDMA setup and registers, refer to [16].Because the data from the ADC to the buffers are transferred by the EDMA, the L2 cache of theDSP does not recognize it and the cache valid flags are not changed. Therefore the DSP wouldread the old values from the cache. There are two ways to avoid this. The first way is to clear thevalid flags of the cache for the buffer area every time the EDMA has finished a transfer. This can bedone by the CACHE_clean function. The second way is to configure a part of the on-chip memoryas mapped memory instead of cache. In this case the number of cache ways is reduced, but thedata from the ADC are directly stored in on chip memory which gains performance. Thereforethe second resolution is applied. The change of the internal memory usage can be done in theDSP/BIOS configuration file.
5.1.4. Digital-to-Analog Conversation
To perform the digital-to-analog conversation the on board codec is used. It is a 16-bit dual channelvoice or data codec and has a fix sample rate of 8000 Hz ([13]). It is produced by a 4.096 MHz clockon the DSK and the internal divider (512 times) of the codec. The codec is accessed through themultichannel buffered serial port (McBSP).The two files dac_codec.h (Listing F.3) and dac_codec.c (Listing F.4) include the implementation forthe setup and the handling of the codec. It uses the AD535 module from the Board Support Library(BSL) which is a set of application programming interfaces used to configure and control on-boarddevices.As the sampling rate of the DAC is low compared to the ADC frequency and the the downsamplingrate of the ADC can not be matched exactly (see Section 5.1.2), the data is directly written to theDAC by the DSP without using the EDMA. Nevertheless, the output also uses two Buffers becausevector processing is applied. Therefore Figure 5.7 can be extended to Figure 5.9.
ADC EDMA CPU
t1
t1t2
t2
DACCPU
t2
t1
Ping(in_buffer_A)
Pong(in_buffer_B)
Ping(out_buffer_A)
Pong(out_buffer_B)
t2
t1
Figure 5.9.: Ping Pong Buffering DAC
The scheduling of the two CPU blocks is explained in Section 5.1.6.
5.1.5. Programm Flow
Like in every C programm the entry point is the main function. In this case the main function isused to initialize the used hardware, the software libraries, and to set up the interrupts. After theinitialization, the application goes to an idle loop to be driven by interrupts (see Figure 5.10). Themain function and the interrupt routines are implemented in the fm_dem_main.c file. Figure 5.11shows a simplified layout.
47
Implementation
main idle interruptroutine
interrupt pending
interrupt routinefinished
Figure 5.10.: Programm flow
main
Init CSL library
Init BSL library
Init ADC and EDMA
Init DAC
Enable interrupts
Start ADC and DAC
DAC interrupt routine
EDMA interrupt routine
Demodulate software interrupt routine
<überschrift>
10.12.101 10:36 Seite 1EasyCASE(SPX)-V5.1 MAIN.SPX Top
Figure 5.11.: Layout main file
5.1.6. Interrupt Routines and Scheduling
The system is driven by two different hardware interrupts. One from the EDMA of the ADC andthe other from the codec DAC. Therefore the CPU is invoked from two different sources and neces-sitates proper scheduling. The two hardware interrupts have the same priority level and can notinterrupt each other. To avoid missing an interrupt the time intensive calculation of the demodu-lation algorithm is done in a software interrupt (SWI) which is posted from the EDMA interruptroutine and can be interrupted by any hardware interrupt as shown in Figure 5.12. Software inter-
t
DAC HWIRoutine
EDMA HWIRoutine
Missed !
DAC HWIRoutine
EDMA HWIRoutine
Demodulate SWIRoutine
post SWI
interruptsSWI
continuesSWI
interruptsSWI
continuesSWI
t
Figure 5.12.: Scheduling with software interrupt
rupts can be configured in the DSP/BIOS configuration and they are posted with the SWI_postfunction. The hardware interrupts are kept as short as possible.Figure 5.13 shows an outline of the interrupts, interrupt routines and what is responsible for settingthe pointers.
DAC Interrupt Routine
The DAC interrupt routine just writes the current value to the codec and increments the outputcounter, which determines current index of the buffer. In case of the missing sample it also per-forms the interpolation as in Listing 5.1 and Figure 5.14.
48
5.1. System Architecture
ADC EDMA
in_buffer_ptr
DAC
in_buffer_A
in_buffer_B
out_buffer_A
out_buffer_B
out_buffer_ptr
63.993 kHz
499.9 Hz 499.9 Hz
Hardware Interrupt HWI
Software Interrupt SWI
Set pointers
Pointer
CPU:EDMA HWI
Routine
CPU:DAC HWIRoutine
CPUdemodulate SWI
Routine
8000 Hz
Figure 5.13.: Overview interrupts
DAC interrupt routine
Interpolate last samplefrom A bufferand fisrtsample from B buffer andsend to DAC
Interpolate last samplefrom B buffer and fisrtsample fromA buffer andsend to DAC
Buffer A in EDMAif
then else
Send sample form Abuffer to DACaccording to outcounter
Send sample form Bbuffer to DACaccording to outcounter
Buffer A in EDMAif
then else
increment outcounter
outcounter too bigif
then else
<überschrift>
3.1.102 10:21 Seite 1EasyCASE(SPX)-V5.1 DACINT.SPX Top
Figure 5.14.: DAC interrupt routine
Listing 5.1: DAC interrupt routine1 void dacInt( void )2 {3 /* interpolate a missing sample */4 if (outcounter>15)5 {6 /* select the buffer */7 if (a_inEDMA)8 {9 AD535_HWI_write(outAD535h,(( out_buffer_A[15]+
out_buffer_B[0])/2));10 } else11 {12 AD535_HWI_write(outAD535h,((out_buffer_B[15]+
out_buffer_A[0])/2));
13 }14 } else /* output a value */15 {16 /* select the buffer */17 if (a_inEDMA)18 {19 AD535_HWI_write(outAD535h,out_buffer_A[outcounter]);20 } else21 {22 AD535_HWI_write(outAD535h,out_buffer_B[outcounter]);23 }24 /* update outcounter */25 outcounter++;26 }27 }
EDMA Interrupt Routine
The EDMA interrupt routine resets the output counter, clears the transfer completion interruptflag, sets the pointers and flags for the new buffers, and then posts the software interrupt (List-ing 5.2 and Figure 5.2).
Demodulate Software Interrupt Routine
In this routine the actual demodulation is carried out. The functions of the demodulation algo-rithms are called as in Listing 5.3 and Figure 5.16.
49
Implementation
Listing 5.2: EDMA interrupt routine1 void edmaInt( void )2 {3 /* reset outcounter */4 outcounter=0;56 /* select EDMA channel */7 if (EDMA_intTest(THS1408_BUFFER_A_TCC))8 {9 /* Clear transfer completion interrupt flag */
10 EDMA_intClear(THS1408_BUFFER_A_TCC);1112 /* set buffer pointers */13 a_inEDMA=0;14 in_buffer_ptr=in_buffer_A;15 out_buffer_ptr=out_buffer_A;1617 /* post software interrupt -> start demodulation
*/18 SWI_post(&demodulate_swi);19 }20 if (EDMA_intTest(THS1408_BUFFER_B_TCC))21 {22 /* Clear transfer completion interrupt flag */23 EDMA_intClear(THS1408_BUFFER_B_TCC);2425 /* set buffer pointers */26 a_inEDMA=1;27 in_buffer_ptr=in_buffer_B;28 out_buffer_ptr=out_buffer_B;2930 /* post software interrupt -> start demodulation
*/31 SWI_post(&demodulate_swi);32 }33 }
EDMA interrupt routine
reset outcounter
clear transfer complet flag A
set buffer pointers and flags to buffer A
post software interrupt
block transfer A completif
then else
clear transfer complet flag B
set buffer pointers and flags to buffer B
post software interrupt
block transfer B completif
then else
<überschrift>
6.12.101 17:06 Seite 1EasyCASE(SPX)-V5.1 E:\DATEN\THESIS\DOCUME~1\IMPLEM~1\STUFF\EDMAINT.SPX Top
Figure 5.15.: EDMA interrupt routine
Listing 5.3: Demodulate softawre inter-rupt routine
1 void demodulateSwiFunc( void )2 {3 int i;4 /* turn 14bit input into 16bit Q15 value */5 for (i=0 ;i<BUFFERSIZE_INPUT;i++)6 {7 in_buffer_ptr[i]=in_buffer_ptr[i]<<2;8 }9
10 quad_mix(in_buffer_ptr,re_buffer,im_buffer);1112 mixed_demodulate(re_buffer,im_buffer,out_buffer);1314 out_filter(out_buffer,out_buffer_ptr);15 }
demodulate software interrupt
turn 14bit inputinto 16bit Q15 value
quadrature mixer
mixed demodulatororpll demodulator
out filter
<überschrift>
10.12.101 10:38 Seite 1EasyCASE(SPX)-V5.1 SWIINT.SPX Top
Figure 5.16.: Demodulate software inter-rupt routine
5.2. Floating-Point Algorithm
In this section the mixed demodulator and PLL demodulator are specially discussed in regards totheir implementations in C.
5.2.1. Quadrature Mixer
Figure 5.17 shows again the block diagram of the Quadrature with the buffer names as they areused in the code sequences. There are two important tasks. A sine and a cosine oscillators have tobe generated first. Then a low-pass filter will be specified.
To generate a sine or a cosine signal it is possible to use an IIR filter. The impulse responses ofthe IIR filters have to take the following forms:
hS(n) = sin(ωM · n · T)
50
5.2. Floating-Point Algorithm
cos(ωΜ n T)
sin(ωΜ n T)
-1
in_buffer(FM Signal)
re_buffer(I Signal)
im_buffer(Q Signal)
Figure 5.17.: Quadrature mixer
and:hC(n) = cos(ωM · n · T)
T represents the sample time, which is used to run the filters. ωM is the angular frequency ofthe demanded oscillation. The exact angular frequency depends on the spectrum situation beforequadrature mixing (see Chapter 5.1).
The filter characteristics of an IIR filter are completely specified by their impulse responses. The Ztransformation of the impulse response delivers all coefficients of the filter. In this case it is aboutdesigning a filter on the limit of stability (non decaying impulse response). A difficulty of suchfilters, specially in a fixed point implementation, is to keep the limit of stability all the time. Therequired Z transfer function can be found in a simple Z transformation table:
hS(n) = sin(ωM · n · T)Z↔HS(z) =
sin(ωM · T) · z−1
1− 2 · cos(ωM · T) · z−1 + z−2 (5.3)
and:
hC(n) = cos(ωM · n · T)Z↔HC(z) =
1− cos(ωM · T) · z−1
1− 2 · cos(ωM · T) · z−1 + z−2 (5.4)
The denominators of the two Z transfer functions are equal, this brings along the common use ofthe delay stores. Hence the two oscillations can be created with a filter with one feedback pathand two forward paths (see Figure 5.19). The filter structure can be directly derived from the Ztransfer function [5]. If the filter is actuated with a delta function, the output would be a sine anda cosine signal, respectively (because their impulse response specification). These signals are thenmultiplied with the FM signal sFM(n).
The next step is to filter them with a low pass filter. For fast applications, an IIR filter is pre-ferred to a FIR filter due to the smaller filter order for the same specifications. High filter ordersare the main cause of undesirable time delay.
To get the IIR filter specifications, it is necessary to look at the spectrum situation. Figure 5.4shows the spectrum of the FM signal after subsampling. The pass frequency is defined by the halfbandwidth of the original FM signal ( f p = 6300Hz). That is the highest frequency which has tobe handled. The stop frequency is chosen as high as possible, but low enough to prevent aliasing( f s = 19000Hz). The pass band loss and the stop band attenuation were declared, to optain thefilter order n as small as possible, but larger enough attenuation in the stop band.
51
Implementation
A useful tool to calculate IIR filter coefficients is MATLAB. The following code sequence showsa matlab M-File which returns the coefficients of a butterworth IIR filter with the given specifica-tions:
1 %IIR low-pass filter for quadrature mixing23 %specifications:4 %sample frequency in Hz5 fa=150000000/(8*293);6 %pass frequency in Hz7 fp=6300;8 %stop frequency in Hz9 fs=19000;
10 %loss in pass band in dB11 dp=2;12 %loss in stop band in dB13 ds=60;1415 %computing:16 [n, fn]=buttord(fp*2/fa, fs*2/fa, dp, ds);17 %return:
18 %order19 n20 %cutoff frequency21 fn2223 %computing:24 [B,A]=butter(n,fn);25 %return:26 %denominator of transfer function27 B28 %nominator of transfer function29 A3031 %computing:32 [H,W]=freqz(B,A,n);33 %return:34 freqzplot(H,W);
The filter order is computed to n = 5 and the 3dB cutoff frequency to fn = 6653Hz. So the transferfunction of the low pass filter is:
HLP(z) = 10−3 · 1.513433 + 7.567165 · z−1+15.134330 · z−2+15.134330 · z−3+7.567165 · z−4+1.513433 · z−5
1− 2.895729 · z−1+3.634448 · z−2−2.392826 · z−3+0.817619 · z−4−0.115082 · z−5
Figure 5.18 shows the frequency response of the low pass filter.
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-400
-300
-200
-100
0
Frequency (Hz)
0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2
x 104
-70
-60
-50
-40
-30
-20
-10
0
Frequency (Hz)
Mag
nitu
de (d
B)Ph
ase
(deg
rees
)
Figure 5.18.: Frequency response of low-pass filter for quadrature mixing, floating point
Now the parts of the quadrature mixer are discussed in the view of its digital realization. Figure5.19 shows the whole digital block diagram of the quadrature mixer with the buffer and variablenames which are used in the code sequences. The following C function represents the translationfrom digital block structure to C code.
52
5.2. Floating-Point Algorithm
z-1z-1
bs2
asc2
+
+
bc2
z-1z-1 z-1 z-1 z-1
alp4 alp5 alp6alp2 alp3
blp4 blp5 blp6blp1 blp2 blp3
+
+
x
z-1z-1 z-1 z-1 z-1
alp4 alp5 alp6alp2 alp3
blp4 blp5 blp6blp1 blp2 blp3
+
+
x
+-
-+
+-
in_buffer
re_buffer
im_buffer
zsc3zsc1 zsc2
zlpc1 zlpc6
zlps5
zlpc5zlpc4zlpc3zlpc2
zlps4zlps3zlps2zlps1 zlps6
Figure 5.19.: Digital block diagram of quadrature mixer
1 void quad_mix( float in_buffer[] , float re_buffer[] , floatim_buffer[])
2 {3 int i;45 /*__cosine/sine generation__*/67 for (i=0;i<BUFFERSIZE_INPUT;i++)8 {9 /*feedback*/
10 zsc1=-(zsc2*asc2+zsc3);1112 /*foreward*/13 re_buffer[i]=zsc1+zsc2*bc2; /*cosine*/14 im_buffer[i]=zsc2*bs2; /*sine*/1516 /*shift delays*/17 zsc3=zsc2;18 zsc2=zsc1;19 }2021 /*__mixing__*/2223 for (i=0;i<BUFFERSIZE_INPUT;i++)24 {25 /*mixing*/26 re_buffer[i]=re_buffer[i]*in_buffer[i]; /*I-path*/27 im_buffer[i]=im_buffer[i]*in_buffer[i]; /*Q-path*/28 }2930 /*__low pass__*/
3132 for (i=0;i<BUFFERSIZE_INPUT;i++)33 {34 /*feedback*/35 zlpc1=re_buffer[i]-(alp2*zlpc2+alp3*zlpc3+alp4*zlpc4+
alp5*zlpc5+alp6*zlpc6); /*I-path*/36 zlps1=im_buffer[i]-(alp2*zlps2+alp3*zlps3+alp4*zlps4+
alp5*zlps5+alp6*zlps6); /*Q-path*/3738 /*foreward*/39 re_buffer[i]=blp1*zlpc1+blp2*zlpc2+blp3*zlpc3+blp4*zlpc4
+blp5*zlpc5+blp6*zlpc6; /*I-path*/40 im_buffer[i]=-(blp1*zlps1+blp2*zlps2+blp3*zlps3+blp4*
zlps4+blp5*zlps5+blp6*zlps6); /*Q-path*/4142 /*shift delays*/43 /*I-path*/44 zlpc6=zlpc5;45 zlpc5=zlpc4;46 zlpc4=zlpc3;47 zlpc3=zlpc2;48 zlpc2=zlpc1;49 /*Q-path*/50 zlps6=zlps5;51 zlps5=zlps4;52 zlps4=zlps3;53 zlps3=zlps2;54 zlps2=zlps1;55 }56 }
The function is called with three parameters. The first parameter is a pointer to an array containingvalues of the subsampled FM signal. The other arguments are the pointers to the arrays used forthe output of the quadrature mixer: re_buffer and im_buffer contain values of the I and Q signals,respectively.
First the cosine and sine signals are produced and saved in the re_buffer (cosine) and the im_buffer
53
Implementation
(sine). The IIR filter, which is used to generate these signals, must be actuated with a delta function.Instead of using a delta function as input signal, the delay variables can be declared to achieve thesame result.
The next step is to multiply the cosine and sine signal with the subsampled FM signal and savethem back to the re_buffer and im_buffer, respectively.
At last the signals in the re_buffer and im_buffer are low-pass filtered and saved back to re_bufferand im_buffer.
5.2.2. First Down Sampling
In Figure 5.20 the spectrum after quadrature mixing (of one path) is shown. It shows that the
|A|
f
f=64000Hz
|A|
f=16000Hz
f
f=64000Hz
Figure 5.20.: Signal spectrum after quadrature mixing
sampling frequency f = 64000Hz can be reduced with a factor of four to f = 16000Hz. Fig-ure 5.21 represents the frequency response after down sampling (of one path). The reduction can
|A|
f
f=64000Hz
|A|
f=16000Hz
f
f=64000Hz
Figure 5.21.: Signal spectrum after first down sampling
be realized by picking every fourth value of the re_buffer and im_buffer and store them in there_buffer_down_one and im_buffer_down_one (reduced buffersize), respectively.
The code sequence below explains the down sampling in C:1 void downsample_one( float re_buffer[] , float im_buffer[] , float re_buffer_down_one[] , float im_buffer_down_one[])2 {3 int i;45 for (i=0;i<BUFFERSIZE_DEMODULATOR;i++)6 {7 re_buffer_down_one[i]=re_buffer[i*DOWNSAMPLE_ONE];8 im_buffer_down_one[i]=im_buffer[i*DOWNSAMPLE_ONE];9 }
10 }
5.2.3. Mixed Demodulator
Figure 5.22 shows again the architecture of the mixed demodulator. The signals are annotated bytheir names in the code sequence. The associated C code is given as follows:
54
5.2. Floating-Point Algorithm
Z-1
Z-1
+
-
arctan
coold
+
+siold
FM
1T k⋅
sinew
demo
conew
out_buffer_down_one
re_buffer_down_one
im_buffer_down_one
Figure 5.22.: Block diagram of mixed demodulator
1 void mixed_demodulate( float re_buffer_down_one[] , float im_buffer_down_one[] , float out_buffer_down_one[])2 {3 int i;45 for (i=0;i<BUFFERSIZE_DEMODULATOR;i++)6 {7 /*__shifting values__*/8 coold=conew;9 siold=sinew;
10 conew=re_buffer_down_one[i];11 sinew=im_buffer_down_one[i];1213 /*__calculating demodulated value__*/14 demo=(coold*sinew-siold*conew)/(coold*conew+siold*sinew); /*atan argument*/15 demo=atanf(demo); /*atan value*/16 demo=demo*decon; /*demodulated value*/17 out_buffer_down_one[i]=demo;18 }19 }
The parameters are the pointers to the arrays which contain the down sampled I signal and Qsignal (re_buffer_down_one, im_buffer_down_one) and a pointer to an array containing the de-modulated signal (out_buffer_down_one).
First the delay has to be realized. The value conew and sinew must be declared with a nonzerovalue to prevent a division by zero by the first call. Then the demodulated value can be calculatedas explained in the block diagram.
5.2.4. PLL Demodulator
Figure 5.23 shows the block diagram with the buffer and variable names as they are used in C.The constant P_PLL is chosen PPLL = 2 as declared in Section 3.3.3. Another constant K_PLLwas declared to be KPLL = kFM · T ≈ 1.2. With these values, there are some distortions aroundf = 1000Hz. The best result is achieved with KPLL = 2.8.
1 void pll_demodulate( float re_buffer_down_one[] , floatim_buffer_down_one[] , float out_buffer_down_one[])
2 {3 int i;4 float demo; /*value of demodulation*/56 for (i=0;i<BUFFERSIZE_DEMODULATOR;i++)7 {8 /*__calculation of demodulation__*/9 i_path=re_buffer_down_one[i]*sinf(arg);
10 q_path=im_buffer_down_one[i]*cosf(arg);11
12 demo=q_path-i_path;13 demo=demo*P_PLL;1415 out_buffer_down_one[i]=demo*GAIN_PLL;1617 /*__summation of argument__*/18 arg=arg+K_PLL*demo;1920 /*__limitation of argument__*/21 if (arg>2*PI)22 {23 arg=arg-2*PI;
55
Implementation
-
+
sine
Σ
cosine
K_PLL
P_PLL demo
out_buffer_down_one
i_path
re_buffer_down_one
im_buffer_down_one
q_path
arg
Figure 5.23.: Block diagram of PLL demodulator
24 }2526 else if (arg<-2*PI)27 {
28 arg=arg+2*PI;29 }30 } /* for */31 } /* pll_demodulate */
The argument (arg) of sine and cosine must be limited because a small DC offset is enough to risethe argument beyond the valid range due to the summation.
5.2.5. Filter
After demodulation the demodulated signal should be filtered with a band-pass filter to suppressthe noise or DC offset.
The coefficients of the band-pass filter are also calculated with a MATLAB M-file:
1 %IIR band-pass filter23 %specifications:4 %sample frequency in Hz5 fa=150000000/(8*293*4);6 %first pass-band frequency in Hz7 fp1=200;8 %second pass-band frequency in Hz
9 fp2=3600;10 %IIR band-pass filter order11 n=5;1213 %computing14 [b,a]=butter(n,[fp1*2/fa fp2*2/fa]); [H,W]=freqz(b,a);15 freqzplot(H,W);
The band-pass filter frequencies are specified as the speech message signal (see Section 1.3). Thestop-band frequency is chosen, that the band-pass filter order is n = 5. Figure 5.24 shows thefrequency response of the band-pass filter. The kind of implementation in C is the same as thelow-pass filter of the quadrature mixer:
1 void out_filter( float out_buffer_down_one[])2 {3 int i;45 for (i=0;i<BUFFERSIZE_DEMODULATOR;i++)6 {7 /*feedback*/8 zbp1=out_buffer_down_one[i]-(abp2*zbp2+abp3*zbp3+abp4*
zbp4+abp5*zbp5+abp6*zbp6+abp7*zbp7+abp8*zbp8+abp9*zbp9+abp10*zbp10+abp11*zbp11);
9
10 /*foreward*/11 out_buffer_down_one[i]=bbp1*zbp1+bbp2*zbp2+bbp3*zbp3+
bbp4*zbp4+bbp5*zbp5+bbp6*zbp6+bbp7*zbp7+bbp8*zbp8+bbp9*zbp9+bbp10*zbp10+bbp11*zbp11;
1213 /*shift delays*/14 zbp11=zbp10;15 zbp10=zbp9;16 zbp9=zbp8;17 zbp8=zbp7;18 zbp7=zbp6;
56
5.3. Fixed-Point Algorithm
0 500 1000 1500 2000 2500 3000 3500 4000-700
-600
-500
-400
-300
-200
-100
0
100
Frequency (Hz)
Phas
e (d
egre
es)
0 500 1000 1500 2000 2500 3000 3500 4000-100
-80
-60
-40
-20
0
Frequency (Hz)
Mag
nitu
de (d
B)
Figure 5.24.: Band-pass filter frequency response, floating point
19 zbp6=zbp5;20 zbp5=zbp4;21 zbp4=zbp3;22 zbp3=zbp2;
23 zbp2=zbp1;24 }25 }
5.2.6. Second Down Sampling
After filtering, a second down sampling is necessary because the digital analog converter runswith a fix frequency of f = 8000Hz. Figure 5.25 represents the signal spectrum after demodulation(speech signal). After the second down sampling the spectrum of the signal is showed in Figure5.26.
|A|
f
f=16000Hz f
|A|
f=16000Hzf=8000Hz
Figure 5.25.: Signal spectrum before second down sampling
5.3. Fixed-Point Algorithm
In this section the fixed-point implementations are explained. Before the algorithms are discusseda short introduction to fractional fixed-point numbers is given.
57
Implementation
|A|
f
f=16000Hz f
|A|
f=16000Hzf=8000Hz
Figure 5.26.: Signal spectrum after second down sampling
5.3.1. Fractional Q Formats
In computing arithmetic, fractional quantities can be approximated by using a pair of integers(n, e) the mantissa and the exponent. The pair represents the fraction:
n · 2−e
The exponent e can be considered as the number of digits you have to move into n before placingthe binary point. If e is a variable quantity, held in a register and unknown at compile time, (n, e)is said to be a floating-point number. If e is known in advance, at compile time, (n, e) is said to afixed-point number. Fixed-point numbers can be stored in standard integer variables by storingthe mantissa.
In a Qm.n format, there are m bits used to represent the two’s complement integer portion ofthe number, and n bits used to represent the two’s complement fractional portion. m + n + 1 bitsare needed to store a general Qm.n number. The extra bit is needed to store the sign of the numberin the most-significant bit position. The representable integer range is specified by (−2m, 2m) andthe finest fractional resolution is 2−n. The most commonly used format is Q.15. Q.15 means that
Fractional Q Formats
A-3Performance/
A.2.2 Q.15 Format
Q.15 format places the sign bit at the leftmost binary digit, and the next 15 left-most bits contain the two’s complement fractional component. The approxi-mate allowable range of numbers in Q.15 representation is (–1,1) and the fin-est fractional resolution is 2�15
� 3.05 � 10�5.
Table A–2. Q.15 Bit Fields
Bit 15 14 13 12 11 10 9 … 0
Value S Q14 Q13 Q12 Q11 Q10 Q9 … Q0
A.2.3 Q.31 Format
Q.31 format spans two 16-bit memory words. The 16-bit word stored in thelower memory location contains the 16 least significant bits, and the highermemory location contains the most significant 15 bits and the sign bit. Theapproximate allowable range of numbers in Q.31 representation is (–1,1) andthe finest fractional resolution is 2�31
� 4.66 � 10�10.
Table A–3. Q.31 Low Memory Location Bit Fields
Bit 15 14 13 12 … 3 2 1 0
Value Q15 Q14 Q13 Q12 … Q3 Q2 Q1 Q0
Table A–4. Q.31 High Memory Location Bit Fields
Bit 15 14 13 12 … 3 2 1 0
Value S Q30 Q29 Q28 … Q19 Q18 Q17 Q16
Figure 5.27.: Q.15 Bit Fields
a 16-bit word is used to express a signed number between positive and negative one. The most-significant binary digit is interpreted as the sign bit in any Q format number. Thus, in Q.15 format,the decimal point is placed immediately to the right of the sign bit. The fractional portion to theright of the sign bit is stored in regular two’s complement format (see Figure 5.27). The approxi-mate allowable range of numbers in Q.15 representation is (1, 1) and the finest fractional resolutionis 2−15 = 3.05 · 10−5 The integer value of an Q.15 value can be computed using equation:
i = round(
f · 215) (5.5)
Where i is the integer value and f is the fractional value. For example:
i = round (0.5 · 32768) = 16384
The following subsections show how to perform the basic arithmetic operations on two fixed pointnumbers, a = n2−p and b = m2−q , expressing the answer in the form c = k2−r, where p, q and rare fixed constant exponents.
58
5.3. Fixed-Point Algorithm
Change of Exponent
The simplest operation to be performed on a fixed-point number is to change the exponent. Tochange the exponent from p to r the mantissa k can be calculated from n by a simple shift.Since:
n2−p = n2r−p · 2−r
the implementation is
k = n << (r-p) if (r>=p)k = n >> (p-r) if (p>r)
Addition and Subtraction
To perform the operation c = a + b, first convert a and b to have the same exponent r as c and thenadd the mantissas. This method is proved by the equation:
n2−r + m2−r = (n + m)2−r
Therefore two Q.15 numbers can be simply added:
k = n + m
Subtraction is similar.
Multiplication
The product c = a · b can be performed using a single integer multiplication. From the equation:
a · b = n2−p ·m2−q = (n ·m)−(p+q)
it follows that the product n ·m is the mantissa of the answer with exponent p + q. To convert theanswer to have exponent r, perform shifts as described above.For example, two Q.15 numbers:
k = (n * m)>>15
Division
Division c = a/b can also be performed using a single integer division. The equation is:
ab
=n2−p
m2−q =( n
m
)2q−p =
( nm
)2(r+q−p)2−r
In order not to lose precision, the multiplication must be performed before the division by m.Q.15 example:
k = (n<<15)/m
59
Implementation
5.3.2. Quadrature Mixer
Like in the floating-point implementation, the sine and the cosine signal of the mixer are generatedwith an second order IIR filter. The coefficients remain the same, except that they have to betransformed to a Q.15 value according to Eq. 5.5. To avoid overflows in the delay states and theoutput value, the delay states are initialized to {0 0 0.8} or rather {0 0 26214} in Q.15 instead of {0 01} (delta function).
z-1 z-1
b1_0 b1_1
a1_2a1_1
b1_2
++
+ + ++
+-
z-1 z-1
b2_0 b2_1
a2_2a2_1
b2_2
++
+ + ++
+-
z-1
a0_0 a0_1
b0_1
+ +
+-
Cascade 0 Cascade 1 Cascade 2
z-1 z-1
b2_0 b2_1
a2_2a2_1
b2_2
++
+ + ++
+-
Cascade 2
4
Sampling Rate = 63.993 kHzBuffer Length = 128
Sampling Rate = 15.998 kHzBuffer Length = 32
ax_1
+
ax_1a
+
ax_1b
++
Figure 5.28.: Block diagram of cascaded low-pass filter
The low-pass filter designed in the floating-point implementation was fifth order. IIR filters is verysensitive to quantization errors. The filter transfer function of a filter higher than second order willchange so much due to quantization that the filter is no longer working properly. The solutionis to realize the filter with cascades of first and second order filters. Hence the quadrature mixerlow-pass filter is slitted into one first order and two second order filters (Figure 5.28).MATLAB provides functions to split the filter into cascaded second-order sections. First [z,p,k]= butter(n,Wn) obtains zero-pole-gain form, then [sos,g] =zp2sos(z,p,k,’order’,’scale’) converts the zero-pole-gain parameters to second-ordersections. Using infinity-norm scaling (scale) in conjunction with up-ordering (order) minimizesthe probability of overflow in the realization.The ax_1 coefficient of each cascade is greater than one and can therefore not be expressed as a Q.15number. The solution is to split the coefficient into two coefficients
ax_1a + ax_1b = ax_1
which are now less than one and can be expressed in the Q.15 format. The implementation willchange as shown in Figure 5.29.
z-1 z-1
b1_0 b1_1
a1_2a1_1
b1_2
++
+ + ++
+-
z-1 z-1
b2_0 b2_1
a2_2a2_1
b2_2
++
+ + ++
+-
z-1
a0_0 a0_1
b0_1
+ +
+-
Cascade 0 Cascade 1 Cascade 2
z-1 z-1
b2_0 b2_1
a2_2a2_1
b2_2
++
+ + ++
+
-
Cascade 2
4
Sampling Rate = 63.993 kHzBuffer Length = 128
Sampling Rate = 15.998 kHzBuffer Length = 32
ax_1
+
ax_1a
+
ax_1b
+
+
Figure 5.29.: Change in block diagram of
To reduce the computing load, the first downsampling is included in the last cascade of the filter.Hence the forward path of the last cascade is only executed every fourth time as in Figure 5.30.The output values are stored in the first quarter of the re_buffer and the im_buffer and thus the
60
5.3. Fixed-Point Algorithm
z-1 z-1
b1_0 b1_1
a0_2a0_1
b1_2
++
+ + ++
+-
z-1 z-1
b2_0 b2_1
a2_2a2_1
b2_2
++
+ + ++
+-
z-1
a0_0 a0_1
b0_1
+ +
+-
Cascade 0 Cascade 1 Cascade 2
z-1 z-1
b2_0 b2_1
a2_2a2_1
b2_2
++
+ + ++
+-
Cascade 2
4
Sampling Rate = 63.993 kHzBuffer Length = 128
Sampling Rate = 15.998 kHzBuffer Length = 32
Figure 5.30.: Output signals and delay states of cascaded low-pass filter
buffer length is reduced from 128 to 32.
The design of the low-pass filter and the oscillator for the fixed-point implementation are donewith the MATLAB file mixer_design.m. It calculates the coefficients for the filter and the oscillator,scales them to the Q.15 value and plots them in a format to the screen that can be copied into thesource code. Afterwards it tests the filter for overflows by monitoring the delay states and outputsof every cascade. To represent a worst case scenario, a square waveform is chosen as the inputsignal. Figure 5.31 shows the plots of all the monitored signals. It shows that due to scaling, an
0 100 200
-1
-0.5
0
0.5
1
Delay Cascade0
0 100 200
-1
-0.5
0
0.5
1
Output Cascade0
0 100 200
-1
-0.5
0
0.5
1
Delay Cascade1
0 100 200
-1
-0.5
0
0.5
1
Output Cascade1
0 100 200
-1
-0.5
0
0.5
1
Delay Cascade2
0 100 200
-1
-0.5
0
0.5
1
Output SignalInput Signal
Figure 5.31.: Output signals and delay states of cascaded low-pass filter
overflow could still occur during the settling time. To preclude this the down scaling of 0.8 intro-duced through the oscillator is not undone before the filter and therefore the input signal to the
61
Implementation
filter is always ≤ 0.8.
The implementation of the quadrature mixer is done in the files quad_mix.c and quad_mix.h.
5.3.3. Mixed Demodulator
The implementation of the fixed-point mixed demodulator is very close to the floating-point im-plementation. The main differences are highlighted below.The arctangent table is created with the files atan.c and antan.h. They define a constant table withthe values of the arctangent function. The MATLAB file tanTabGen.m is used to calculate the valuesof the table and write the h and c files. To reduce the computing load and avoid scaling andoverflow problems, the factor 1
T·kFM(see Eq.5.22) is included in the table.Therefore the lookup table
fulfils the equation:
out =1
T · kFM· arctan (in) (5.6)
The minimum range of the table can be calculated by using the maximum derivation of 3000 Hz:
inmax = tan (kFM · T) = tan(
2 · π · ∆FfA
)= tan
(2 · π · 3000
15998
)= 2.415
To allow easy determination of the index, the range of the table should be a power of two. There-fore the input range of the arctangent is set to 22 = 4. Only the positive part of the arctangentfunction is stored in the table, because the function is symmetrical and the negative part can bederived from the positive part.One approach is to use the value from the lookup table directly as output. Therefore the table hasto store enough values to be sufficient accurate. Another approach is to interpolate the output.This involves additional computing time, but the table size can be reduced. To further reduce theadditional computing time a second table with the gradients of the function is used for the inter-polation. The MATLAB file tanTabGenInterpol.m is used to generate these two tables. Figure 5.32shows the window plot of the direct lookup table with a table size of 128, the interpolated lookupwith two tables of 16 values, and the actual arctangent function. It shows that the interpolatedlookup is more accurate.In Section 6.2.1 various measurements with different table sizes are done and it showed that directlookup with table of 128 values and interpolated lookup with two tables of 16 values achieve agood effort and profit ratio.
Listing 5.4 shows the calculation of the argument. The signals before the division are stored inthe Q.31 format to avoid underflows and the division is scaled to a Q17.14 format. Therefore thethree local variables re_path, im_path and dem_arg are Integers (32bit).
Listing 5.4: Argument calculation fixed-point mixed demodulator1 re_path = ( im_buffer[i]*dem_z_re - re_buffer[i]*dem_z_im)<<1; /* Q.31 */2 im_path = ( re_buffer[i]*dem_z_re + im_buffer[i]*dem_z_im)<<1; /* Q.31 */34 /* shift delays */5 dem_z_re=re_buffer[i];6 dem_z_im=im_buffer[i];78 /* calculate the argument */9 dem_arg=re_path/(im_path>>14); /* Q17.14 */
5.3.4. PLL Demodulator
The fixed-point implementation of the PLL demodulator differs from the floating-point implemen-tation, specially in the calculation of the sine and cosine values of the summed demodulated signal
62
5.3. Fixed-Point Algorithm
0 0.05 0.1 0.15 0.2 0.25 0.3
0
0.05
0.1
0.15
0.2
0.25Direct Lookup Table Size 128Interpolation Lookup Table Size 2⋅16Arctangent Function
Figure 5.32.: Plot arc tangent lookup table
(arg). The rest of the algorithm involves normal change from floating-point to a convenient Q for-mat.
The calculation of the demodulated value is done in the Q15 format (Listing 5.5 line 12 to 20).The following summation of the demodulated signal is limited to 2 · π . That means that the Qformat has to change from Q15 to Q3.12 (Listing 5.5 line 23 to 39):
Q3.12max = (215 − 1) · 2−12 ≈ 8 > 2 · π
The next step is to compute the sine and cosine values of the summed demodulated signal (Listing5.5 line 42 to 162). The idea is to access a buffer, which contains the sine values. To calculate sineand cosine values of an argument between −2π and −2π , it is enough to save a fourth of a sinewave. This is first done in a M-file which is later integrated to the C code. The M-file delivers anarray, called sine_buffer with the array size BUFFERSIZE_SINE. sine_buffer contains sine valuesof sine arguments in a range from 0 to π/2.
To access the sine_buffer it is necessary to calculate an index to the argument (Listing 5.5 line44 to 60). In a floating-point application the index could be calculated as:
indexshort =arg f loat
step f loat
step f loat is the step between the sine arguments, declared in the M-file:
step f loat =π
2 · (BUFFERSIZE_SINE− 1)
arg f loat is the summed demodulated signal. Because arg f loat is limited to ±2 · π , the range of thereachable index is:
indexshort =[− 2 · π
step f loat, +
2 · πstep f loat
]
63
Implementation
or expressed in terms of the constant BUFFERSIZE_SINE:
indexshort = [−4 · (BUFFERSIZE_SINE− 1), +4 · (BUFFERSIZE_SINE− 1)]
The index range remains the same in the fixed point realization. To calculate the index, it is betterto use a multiplication instead of a division:
indexshort = (argQ_ f ormat ·STEP_INVERSEQ_ f ormat) >> (2 ·Q_FORMAT)
The needed Q format (Q_format) is also calculated in the M-file. It depends on the index range(BUFFERSIZE_SINE). The M-file delivers the shifting number of the Q format (Q_FORMAT). Theshifting always rounded down to the next smaller integer value. In the case that the index is nega-tive, the rounding is erroneous. That is why a negative index must be negated to become positivebefore shifting. After that the sign of the index can be changed to negative again.
Now the calculated index has to be prepared to access to the sine_buffer because the sine_bufferhas only an index range from zero to BUFFERSIZE_SINE-1 (Listing 5.5 line 62 to 162). The indexpreparation will now be explained with an example. Figure 5.33 shows a positive sine wave withbelonging arguments and indexes respectively. The fat printed part of sine wave represents theavailable sine values in sine_buffer. In Figure 5.34 the index preparation is explained pictorially.First an inquiry must be issued to find out in which area the index lies. The first picture shows thefound index area with associated sine values. The following pictures show the new index areaswith the expected values after the prior index manipulation. As described, there are two basicindex manipulations. If the index is in the index area 1 the sine_buffer access can be done directly
sine argument
sine value
0 PI/2 PI*3/2 PI*2PI
0 BUFFERSIZE_SINE-1 (BUFFERSIZE_SINE-1)*2 (BUFFERSIZE_SINE-1)*3 (BUFFERSIZE_SINE-1)*4 index
index%(BUFFERSIZE_SINE-1)
index%(BUFFERSIZE_SINE-1)
index%(BUFFERSIZE_SINE-1)
(BUFFERSIZE_SINE-1)-index
(BUFFERSIZE_SINE-1)-index
Area 1
Area 2
Area 4
Area 3
Area 1 Area 2
Area 4Area 3
Figure 5.33.: Sine values with belonging indexes
with the calculated index. An index in area 2 needs both manipulations. For indexes in area 3,only the first index manipulation is necessary but the found value after sine_buffer access has tobe multiplied with minus one. The same goes for indexes in area 4 with the exception that bothindex manipulations are also needed.
The same principe is applied to the negative sine wave as well as whole cosine wave.
64
5.3. Fixed-Point Algorithmsine argument
sine value
0 PI/2 PI*3/2 PI*2PI
0 BUFFERSIZE_SINE-1 (BUFFERSIZE_SINE-1)*2 (BUFFERSIZE_SINE-1)*3 (BUFFERSIZE_SINE-1)*4 index
index%(BUFFERSIZE_SINE-1)
index%(BUFFERSIZE_SINE-1)
index%(BUFFERSIZE_SINE-1)
(BUFFERSIZE_SINE-1)-index
(BUFFERSIZE_SINE-1)-index
Area 1
Area 2
Area 4
Area 3
Area 1 Area 2
Area 4Area 3
Figure 5.34.: Index manipulation
Listing 5.5: PLL demodulator1 void pll_demodulate( short re_buffer[] , short im_buffer[] ,
short out_buffer[])2 {3 int i;4 int flag=0;56 short demo; /*index for sine_buffer access*/7 short index; /*value of demodulation*/89
10 for (i=0;i<BUFFERSIZE_DEMODULATOR;i++)11 {12 /*__calculation of demodulated value, using Q15__*/1314 i_path=(re_buffer[i]*i_path)>>15;15 q_path=(im_buffer[i]*q_path)>>15;1617 demo=q_path-i_path;18 demo=(demo*P_PLL)>>15;1920 out_buffer[i]=(demo*GAIN_PLL)>>15;212223 /*__summation of demodulated signal, using Q3.12__*/2425 demo=demo>>3;26 arg=arg+((demo*K_PLL)>>12);272829 /*__limitation of argument to 2*PI, using Q3.12__*/3031 if (arg>TWO_PI)32 {33 arg=arg-TWO_PI;34 }3536 else if (arg<-TWO_PI)37 {38 arg=arg+TWO_PI;39 }404142 /*__calculation of sine and cosine value of argument__*/4344 /*calculating of index for sine_buffer access, using
new Q format*/4546 index=arg>>REDUCTION;4748 if (index<0)49 {50 index=-index;51 flag=1;52 }5354 index=(index*STEP_INVERSE)>>(2*Q_FORMAT);5556 if (flag==1)57 {
58 index=-index;59 flag=0;60 }6162 /*access on sine_buffer with index*/6364 if (index>=0)65 {66 if (index<(BUFFERSIZE_SINE-1))67 {68 /*sine value*/69 i_path=sine_buffer[index];70 /*cosine value*/71 index=(BUFFERSIZE_SINE-1)-index;72 q_path=sine_buffer[index];73 }74 else if (index<2*(BUFFERSIZE_SINE-1))75 {76 index=index % (BUFFERSIZE_SINE-1);77 /*sine value*/78 index=(BUFFERSIZE_SINE-1)-index;79 i_path=sine_buffer[index];80 /*cosine value*/81 index=(BUFFERSIZE_SINE-1)-index;82 q_path=-sine_buffer[index];83 }84 else if (index<3*(BUFFERSIZE_SINE-1))85 {86 index=index % (BUFFERSIZE_SINE-1);87 /*sine value*/88 i_path=-sine_buffer[index];89 /*cosine value*/90 index=(BUFFERSIZE_SINE-1)-index;91 q_path=-sine_buffer[index];92 }93 else if (index<4*(BUFFERSIZE_SINE-1))94 {95 index=index % (BUFFERSIZE_SINE-1);96 /*sine value*/97 index=(BUFFERSIZE_SINE-1)-index;98 i_path=-sine_buffer[index];99 /*cosine value*/
100 index=(BUFFERSIZE_SINE-1)-index;101 q_path=sine_buffer[index];102 }103 else104 {105 index=index % (BUFFERSIZE_SINE-1);106 /*sine value*/107 i_path=sine_buffer[index];108 /*cosine value*/109 index=(BUFFERSIZE_SINE-1)-index;110 q_path=sine_buffer[index];111 }112 }113 else114 {115 if (index>-(BUFFERSIZE_SINE-1))116 {117 index=-index;
65
Implementation
118 /*sine value*/119 i_path=-sine_buffer[index];120 /*cosine value*/121 index=(BUFFERSIZE_SINE-1)-index;122 q_path=sine_buffer[index];123 }124 else if (index>-2*(BUFFERSIZE_SINE-1))125 {126 index=-(index % (BUFFERSIZE_SINE-1));127 /*sine value*/128 index=(BUFFERSIZE_SINE-1)-index;129 i_path=-sine_buffer[index];130 /*cosine value*/131 index=(BUFFERSIZE_SINE-1)-index;132 q_path=-sine_buffer[index];133 }134 else if (index>-3*(BUFFERSIZE_SINE-1))135 {136 index=-(index % (BUFFERSIZE_SINE-1));137 /*sine value*/138 i_path=sine_buffer[index];139 /*cosine value*/140 index=(BUFFERSIZE_SINE-1)-index;141 q_path=-sine_buffer[index];
142 }143 else if (index>-4*(BUFFERSIZE_SINE-1))144 {145 index=-(index % (BUFFERSIZE_SINE-1));146 /*sine value*/147 index=(BUFFERSIZE_SINE-1)-index;148 i_path=sine_buffer[index];149 /*cosine value*/150 index=(BUFFERSIZE_SINE-1)-index;151 q_path=sine_buffer[index];152 }153 else154 {155 index=-(index % (BUFFERSIZE_SINE-1));156 /*sine value*/157 i_path=-sine_buffer[index];158 /*cosine value*/159 index=(BUFFERSIZE_SINE-1)-index;160 q_path=sine_buffer[index];161 }162 }163 }164 }
Interpolated Lookup Table
To get more precise sine values, an interpolation can be carried out between two saved sine values.As mentioned the Q format of the index depends on the chose BUFFERSIZE_SINE. An index canbe interpreted as a floating-point in the used Q format. Without interpolation, only the integerparts are considered. With interpolation the fraction is also included to calculate the sine value.The fraction is stored in the variable rest . How many digit of the fraction are known, depends onQ_FORMAT. A linear interpolation can be done with the fraction. For that, an extra buffer has to begenerated. This buffer is also prepared in a M-file and later integrated to the C code. It is knownas the sine_grad_buffer and it contains the differences of two adjacent values of the sine_buffer.Figure 5.35 explains how the linear interpolation is implemented. The smaller the step between
sine_buffer[i]
sine_buffer[i+1]
sine_grad_buffer[i]
rest
FORMAT=2Q_FORMAT
correction
Figure 5.35.: Linear interpolation
the saved sine values, the more accurate the sine value is approximated.
correctionrest
=sine_grad_bu f f er[i]
FORMAT
correction = (sine_grad_bu f f er[i] · rest) >> Q_FORMAT
The interpolated sine value is:
interpolated_sine_value = sine_bu f f er[i] + correction
66
5.3. Fixed-Point Algorithm
Listing 5.6 shows the part of sine_buffer_access with the necessary new instructions. In Listing5.6 line 14 the fraction of the index is saved in the variable rest before shifting. In Listing 5.6 theneeded correction is computed due to rest and sine_grad_buffer access (for example line 30).Attention has been paid to which sign the correction is added to the sine_buffer value. The signof rest and the values of sine_grad_buffer are always positive. Thus only the sign of the correc-tion must be manipulated. Figure 5.36 and 5.37 show two examples with different signs of thecorrection.
sine value
index
interpolated sine value
sine valuecorrection
sine value
interpolated sine value
sine value
correction
index
Figure 5.36.: Sign of correction changes
Listing 5.6: Interpolated Lookup Table1 /*__calculation of sine and cosine value of argument__*/23 /*calculating of index for sine_buffer access, using new Q
format*/45 index=arg>>REDUCTION;67 if (index<0)8 {9 index=-index;
10 flag=1;11 }1213 index=(index*STEP_INVERSE)>>Q_FORMAT;14 rest=index%FORMAT;15 index=index>>Q_FORMAT;1617 if (flag==1)18 {19 index=-index;20 flag=0;21 }2223 /*access on sine_buffer with index*/2425 if (index>=0)26 {27 if (index<(BUFFERSIZE_SINE-1))28 {29 /*sine value*/30 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/31 i_path=sine_buffer[index]+correction;32 /*cosine value*/
33 index=(BUFFERSIZE_SINE-1)-index;34 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/35 q_path=sine_buffer[index]+correction;36 }37 else if (index<2*(BUFFERSIZE_SINE-1))38 {39 index=index % (BUFFERSIZE_SINE-1);40 /*sine value*/41 index=(BUFFERSIZE_SINE-1)-index;42 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/43 i_path=sine_buffer[index]+correction;44 /*cosine value*/45 index=(BUFFERSIZE_SINE-1)-index;46 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/47 q_path=-(sine_buffer[index]+correction);48 }49 else if (index<3*(BUFFERSIZE_SINE-1))50 {51 index=index % (BUFFERSIZE_SINE-1);52 /*sine value*/53 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/54 i_path=-(sine_buffer[index]+correction);55 /*cosine value*/56 index=(BUFFERSIZE_SINE-1)-index;57 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/58 q_path=-(sine_buffer[index]+correction);59 }60 else if (index<4*(BUFFERSIZE_SINE-1))61 {62 index=index % (BUFFERSIZE_SINE-1);
67
Implementation
sine value
index
interpolated sine value
sine valuecorrection
sine value
interpolated sine value
sine value
correction
index
Figure 5.37.: Sign of correction does not change
63 /*sine value*/64 index=(BUFFERSIZE_SINE-1)-index;65 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/66 i_path=-(sine_buffer[index]+correction);67 /*cosine value*/68 index=(BUFFERSIZE_SINE-1)-index;69 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/70 q_path=sine_buffer[index]+correction;71 }72 else73 {74 index=index % (BUFFERSIZE_SINE-1);75 /*sine value*/76 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/77 i_path=sine_buffer[index]+correction;78 /*cosine value*/79 index=(BUFFERSIZE_SINE-1)-index;80 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/81 q_path=sine_buffer[index]+correction;82 }83 }84 else85 {86 if (index>-(BUFFERSIZE_SINE-1))87 {88 index=-index;89 /*sine value*/90 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/91 i_path=-(sine_buffer[index]+correction);92 /*cosine value*/93 index=(BUFFERSIZE_SINE-1)-index;94 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/95 q_path=sine_buffer[index]+correction;96 }97 else if (index>-2*(BUFFERSIZE_SINE-1))98 {99 index=-(index % (BUFFERSIZE_SINE-1));
100 /*sine value*/101 index=(BUFFERSIZE_SINE-1)-index;102 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/103 i_path=-(sine_buffer[index]+correction);
104 /*cosine value*/105 index=(BUFFERSIZE_SINE-1)-index;106 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/107 q_path=-(sine_buffer[index]+correction);108 }109 else if (index>-3*(BUFFERSIZE_SINE-1))110 {111 index=-(index % (BUFFERSIZE_SINE-1));112 /*sine value*/113 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/114 i_path=sine_buffer[index]+correction;115 /*cosine value*/116 index=(BUFFERSIZE_SINE-1)-index;117 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/118 q_path=-(sine_buffer[index]+correction);119 }120 else if (index>-4*(BUFFERSIZE_SINE-1))121 {122 index=-(index % (BUFFERSIZE_SINE-1));123 /*sine value*/124 index=(BUFFERSIZE_SINE-1)-index;125 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/126 i_path=sine_buffer[index]+correction;127 /*cosine value*/128 index=(BUFFERSIZE_SINE-1)-index;129 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/130 q_path=sine_buffer[index]+correction;131 }132 else133 {134 index=-(index % (BUFFERSIZE_SINE-1));135 /*sine value*/136 correction=(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*positive*/137 i_path=-(sine_buffer[index]+correction);138 /*cosine value*/139 index=(BUFFERSIZE_SINE-1)-index;140 correction=-(sine_grad_buffer[index]*rest)>>Q_FORMAT;
/*negative*/141 q_path=sine_buffer[index]+correction;142 }143 }144 }
68
5.3. Fixed-Point Algorithm
5.3.5. Out Filter
It was not possible to design a stable bandpass filter in fixed-point as in the floating-point imple-mentation. Therefore a low-pass filter was designed first. It includes the downsampling in the lastcascade. Then a high-pass filtering is applied at the lower frequency.
Low-Pass
The MATHLAB file lowpass_design_noisefilter.m is used to design the low-pass filter. The specifica-tions are given in Table 5.5. This results in a 13th order filter, which is again splited into one first
Table 5.5.: Filter specifications low-pass filterpass-band edge frequency 3500 Hzstop-band edge frequency 4000 Hzpass-band ripple 2dBstop-band ripple 20 dB
and six second order cascades. To reduce the computing load, the second downsampling is in-cluded in the last cascade of the filter as described in Section 5.3.2. The signal is again additionallydown scaled by 0.8 to avoid overflows in the filter.
High-Pass
The MATLAB file highpass_design_noisefilter.m is used to design the high-pass filter.The specifica-tions are given in Table 5.6. This filter implemented in the direct from II would have to include too
Table 5.6.: Filter specifications high-pass filterpass-band edge frequency 300 Hzstop-band edge frequency 50 Hzpass-band ripple 0.1 dBstop-band ripple 40 dB
much down scaling to avoid overflows. Therefore the implementation structure was changed tothe transposed form. This structure has the advantage, that the delay states range is quite close tothe range of the output signal. The splitting can be done by using [sos,g] =zp2sos(z,p,k,)
z-1 z-1
b2 b1
a1a2
b02
+
-++ ++
-
Figure 5.38.: Block diagram transposed filter structure
without the specific scaling argument. Because the transposed form is more sensitive to overflows
69
Implementation
an additional down scaling of 0.5 is applied prior to the high-pass. The total down scaling is stillmuch smaller than the one which would be needed by the direct from II. After the high-pass thesignal is multiplied by 2 to undo the additional down scaling.
5.4. Optimization
5.4.1. Adaptive Seeking of Carrier Angular Frequency
A general problem of FM demodulation is a DC offset due to inexact angular frequency of thequadrature mixer ωM. ωM depends on the FM carrier angular frequency ωT and the sample fre-quency ωA (see Eq.5.1). Because the FM modulation is done with analog components ωT is nota constant, it fluctuates. Thus ωM is also fluctuating. This drift causes the described DC offset inthe demodulated message signal. In the analog FM demodulation this error can be suppressedwith a high-pass filter after demodulation. That can also be done in the digital FM demodulation.A smarter solution is the adaptive seeking of carrier angular frequency. To implement adaptivecontrol algorithms it is necessary to describe mathematically the error which should be corrected.For that reason the Mixed demodulator is prefered to the PLL demodulator. The PLL demodulatoris more difficult to describe mathematically, due to its non linear closed loop.
Figure 5.39 shows a system with an adaptive behavior. The following equations explains how
H(a0,a1,a2,...,aN)
an=fan(e) e(a0,a1,a2,...,aN)=fy(y1,y2)
System representedby the coefficients an
Adapting thecoefficients an due to
the errore(a0,a1,a2,...,aN)
y1
y2
errore(a0,a1,a2,...,aN)
Figure 5.39.: Adapted System
the DC offset error results because of the inexact ωM. ωMe is the actual angular frequency and ωMsthe supposed angular frequency of the quadrature mixer, the I and the Q signal of the quadraturemixer are:
A2
cos((ωMe −ωMs) · T · n + ∆F · 2 · π · T ·n
∑i=0
sN(n)) =A2
cos(η(n))
70
5.4. Optimization
and:A2
sin((ωMe −ωMs) · T · n + ∆F · 2 · π · T ·n
∑i=0
sN(n)) =A2
sin(η(n))
Compare with Section 3.2.2.
After the demodulation with the mixed demodulator the demodulated signal is:
sD(n) =η(n)− η(n− 1)
T · ∆F · 2 · π =ωMe −ωMs
∆F · 2 · π + sN(n)
Compare with Section 3.3.4, especially with Eq.3.19.
Now the DC offset error is described due to ωMs:
e(ωMs) =ωMe −ωMs
∆F · 2 · πTherefore ωMe must be:
ωMe = ωMs + e(ωMs) · ∆F · 2 · πFor that, e(ωMs) must be known. A DC offset of a number sequence is calculated as:
e(ωMs) =1N
N−1
∑i=0
sD(i)
The lager N is, as exacter the error will be computed and as less computing time is needed. N alsodetermines the period of the adaptive algorithm. Thus the upper limit of N is given by the speedof the carrier angular frequency change.
ωMe is used to calculate the new coefficients of the IIR filter, which is used for sine and cosinegeneration:
bc2 = −cos(ωMe · T)bs2 = sin(ωMe · T)asc2 = −2 · cos(ωMe · T)
Compare with Section 5.2.1.
If these coefficients are regularly computed the offset error of the demodulated signal sD(n) willdisappear, due to the adaptive seeking of the carrier angular frequency.
Figure 5.40 gives an overview of the structure of the adaptive filter. The effort to implement thecalculation of the IIR Filter coefficients in fixed-point would be very big. Therefore the implemen-tation is only applied to the floating-point implementation.
The adaptive seeking of the carrier angular frequency brings some advantages: The output fil-ter can be reduced to a low-pass, because the DC offset error is corrected. It will improve thesignal quality, if the carrier frequencies of the transmitter and receiver do not match exactly.
5.4.2. Time Optimization
Texas Instruments recommends a three phase code development flow for the C6000 shown inFigure 5.41 citeProgGuide.Phase one is to translate algorithms into C Code, compile and profile the implementation to verifythe correct performance. This phase has been done in the previous section of this chapter. Phasetwo and three are matter of this section. Phase two is further divided into two steps, reducingcomputing load and using compiler specific optimizations.
71
Implementation
z-1z-1
bs2
bc2
-zs
c3zs
c1zs
c2
Subs
ampl
ing
Filte
rSe
cond
dow
nsam
plin
gM
ixed
dem
odul
ator
Firs
tdo
wns
ampl
ing
Qua
drat
ure
mix
er
asc2
-+
+
cosi
ne
sine
()
0
12
N
Me
Ms
Dn
sn
FN
ωω
π=
=+
⋅∆⋅
⋅
∑
asc2
=-2c
os(ω
MeT
)
bs2=
sin(
ωM
eT)
Adap
tive
IIR fi
lter f
orco
sine
and
sin
ege
nera
tion
Algo
rithm
for a
dapt
ive
IIR fi
lter
ωM
sω
Μe
=
bc2=
-cos
(ωM
eT)
Figure 5.40.: Adaptive seeking of carrier angular frequency
72
5.4. Optimization
Code Development Flow to Increase Performance
4-2
4.1 Code Development Flow to Increase Performance
You can achieve the best performance from your C6000 code if you follow thisflow when you are writing and debugging your code:
Yes
No
Complete
Yes
No
Efficientenough?
Write C/C++ codePhase 1:Develop C/C++code
Phase 2:Refine C/C++code
Phase 3:Write linearassembly
More C/C++ optimizations?
No
Yes
No
Yes
Complete
Compile
Profile
Refine C/C++ code
Compile
Profile
Complete
Write linear assembly
Profile
Assembly optimize
Efficientenough?
Efficientenough?
Figure 5.41.: development flow
Reducing Computing Load (Phase 2 - Step 1)
The implementation is reviewed to reduce the computing load of the implemented algorithms.The following changes are applied:
• The scaling of the low-pass filter in the quadrature mixer is included in the output of oscilla-tors of the quadrature mixer. Thus the two numerators of the oscillator IIR filter (see Eq. 5.3
73
Implementation
and Eq. 5.4) are multiplied by the scale factor of the low-pass filter.
• The scaling of the low-pass filter in the out filter is included in the arctangent lookup table.All the values in the arctangent lookup table are multiplied with the scaling factor. Thus thelookup table of the optimized implementation fulfils the equation:
out = lp_scale · 1T · kFM
· arctan (in)
• The scaling of high-pass filter in the out filter is included last cascade’s forward feed of thelow-pass filter in the out filter . Hence the numerator of the last cascade is multiplied withthe scale factor.
This changes reduce the used multiplications and therefore the computing load the gain in pro-cessing speed is measured and commented in Chapter 6.4.
Compiler Specific Optimizations (Phase 2 - Step 2)
The C6000 Compiler provides several keywords, pragma directives , and intrinsics to pass infor-mation to the compiler and optimizer.
Pragma directives tell the compile how to treat a certain function, object, or section of code.
Intrinsics are special functions that map directly to inlined C67x instructions or tell the optimizerthat a expression is true to give hints to the optimizer, to optimize the C code quickly.
The Restrict Keyword To help the compiler determine memory dependencies, pointers, refer-ences, or arrays can be qualified with the restrict keyword. The restrict keyword is a type qualifier.Its use represents a guarantee by the programmer that within the scope of the pointer declara-tion the object pointed to can be accessed only by that pointer. This practice helps the compileroptimize certain sections of the code because aliasing information can be more easily determined.The restrict keyword is applied to all the function definitions of the implementation, because allthe buffers passed to the functions are not aliasing.
void quad_mix( short in_buffer[restrict] , short re_buffer[restrict] , short im_buffer[restrict])
void mixed_demodulate( short re_buffer[restrict] , short im_buffer[restrict] , short out_buffer[restrict])
void pll_demodulate( short re_buffer[restrict] , short im_buffer[restrict] , short out_buffer[restrict])
void out_filter( short out_buffer[restrict] , short out_buffer_down[restrict])
The MUST_ITERATE Pragma The MUST_ITERATE pragma specifies to the compiler certainproperties of a loop. The maximum and the minimum trip count can be specified for a loop.In the implementation all loop counts are constants and therefore the compiler can retrieve theneeded information without the explicit declaration of the MUST_ITERATE pragma.
74
5.4. Optimization
The DATA_MEM_BANK Pragma The DATA_MEM_BANK pragma aligns a symbol or variableto a specified C6000 internal data memory bank boundary. All the buffers used are aligned that nomemory stall occurs (two access to the same memory bank).
#pragma DATA_MEM_BANK (in_buffer_A, 0);short in_buffer_A[BUFFERSIZE_INPUT];#pragma DATA_MEM_BANK (in_buffer_B, 0);short in_buffer_B[BUFFERSIZE_INPUT];
#pragma DATA_MEM_BANK (re_buffer, 2);short re_buffer[BUFFERSIZE_INPUT];#pragma DATA_MEM_BANK (im_buffer, 4);short im_buffer[BUFFERSIZE_INPUT];
#pragma DATA_MEM_BANK (out_buffer, 0);short out_buffer[BUFFERSIZE_DEMODULATOR];#pragma DATA_MEM_BANK (out_buffer_A, 6);short out_buffer_A[BUFFERSIZE_OUTPUT];#pragma DATA_MEM_BANK (out_buffer_B, 6);short out_buffer_B[BUFFERSIZE_OUTPUT];
This also assures that the buffers are word-aligned.
The _nassert Intrinsic The _nassert intrinsic generates no code. It tells the optimizer that theexpression declared with the assert function is true. This gives a hint to the compiler as to whatoptimizations might be valid.In the implementation we use the _nassert intrinsic to tell the compiler that the buffers passed tothe functions are word-aligned. The WORD_ALIGNEDmacro is defined as followed
#define WORD_ALIGNED(x) (_nassert((( int )(x) & 0x3) == 0))
and is used in the functions.WORD_ALIGNED(XX_buffer);
All this information helps the compiler and optimizer to perform better loop unrolling and soft-ware pipelining to parallelize loop iterations, Section6.4 outlines the time improvements due tothese optimizations.
Software pipelining is a technique used to schedule instructions from a loop so that multipleiterations execute in parallel. The parallel resources on the DSP make it possible to initiatea new loop iteration before previous iterations finish. The goal of software pipelining is tostart a new loop iteration as soon as possible.
Writing Linear Assembly (Phase 3)
In this phase, the time-critical areas are extracted from the C code and rewritten in linear assembly.The assembly optimizer is used to optimize this code. The code is written without being concernedwith the pipeline structure or with assigning registers, with the optimizer will handle.This phase is quite time intensive and therefore only the quadrature mixer is rewritten in linearassembly. The mixer algorithm runs at the highest frequency and uses the most computing time.The rewriting should show the improvement against the optimized C implementations.The complete quad_mix function is transformed to linear assembly. Linear assembly providesdirectives to write a C callable assembly function. The function has to start with the directive.cproc and ends with .endproc . Hence the structure of the quadrature mixer function is
_quad_mix: .cproc in_s , re_b_s , im_b_s....endproc
The time improvement against the C optimized code is rather small compared to the time investedfor the rewriting.The exact timings are measured in Chapter 6.4. Also the clarity of the code sinksand makes it harder for reuse.
75
Implementation
76
6. Tests And Results
To test and verify the implementations various measurements are carried out and described below.The instruments used are described in Appendix A.3
6.1. Spectrum
The spectrum of a signal gives a general statement about the signal. The Neutrik A2-D can calcu-late the Fast Fourier Transformation (FFT) of the measured signal.
Figure 6.1.: FFT print of demodulated signal
Figure 6.1 shows the FFT print of the demodulated signal with fixed-point mixed demodulator,direct lookup. The spectrum of the other implemented algorithms are quite similar. Comparedto Figure 6.2, which shows the spectrum of a pure sine signal generated with the DSP, it can beseen that the noise floor is mainly introduced by the demodulation algorithm and not by the useddevices. Figure 6.3 shows the spectrum of the same signal used in Figure 6.1 over the maximalrange the A2-D can handle. The Noise reduction between 3200 Hz and 4000 Hz is introduced bythe DAC interpolation filter. The noise above 4000 Hz is the noise level introduced by the devices.This noise level is more than 20dB lower than the noise level introduced by the demodulationalgorithms and will therefore not distort the following measurements.
77
Tests And Results
Figure 6.2.: FFT print of DSP generated sine wave
Figure 6.3.: FFT print of demodulated signal for the range of 0 to 20kHz
6.2. Signal Quality (SINAD)
In the simulations (Chapter 4) the SINAD was measured to make a statement about the signalquality. Therefore the SINAD is also measured for the DSP implementation.The Neutrik A2-D has a THD+N Function, which measures the total Harmonic Distortion andnoise by inserting a band-reject (notch) filter into the signal path (Figure 6.4). The THD+N value is
78
6.2. Signal Quality (SINAD)
calculated according to Eq. 6.1.
THD + N =(Distortion + Noise)
Signal + (Distortion + Noise)(6.1)
This definition is equal to the definition of the SINAD (see Eq. C.2 in the appendix) used in the
Figure 6.4.: Principle of THD+N Measurement
simulations. Hence the results of the THD+N Function are further referenced as SINAD to keepthe same reference to the simulation.
6.2.1. Mixed Demodulator
The quality of the output signal depends a lot on the accuracy of the implementation of the arct-angent function. First the implementation with the direct table lookup for the arctangent functionis measured with different table sizes. The input FM signal is generated with the HP functiongenerator (Appendix A.3.1), with the following parameters:
Carrier frequency fT 10.7 MHzFrequency deviation∆F 3000 HzMessage signal frequency 100-3700 Hz
Figure 6.5 shows the plot of the SINAD measured for tables’ sizes of 32, 64, 128, 256, and 512. Itshows that a table size greater than 128 does not increase the signal quality much. Thus the tablesize for the direct lookup table is set to 128.
Second the implementation with the interpolation is measured with different table sizes and thesame input signal parameters. Figure 6.6 shows the plot of the SINAD measured for tables’ sizesof 8, 16, and 32. It shows that a table size 16 is the most optimal.
Figure 6.7 shows the comparison of the two implemented versions of the arctangent functionand the floating-point implementation. The floating-point implementation uses the arctangent
79
Tests And Results
SINAD dB
-38.0-36.0-34.0-32.0-30.0-28.0-26.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]Table Size 32 Table Size 64 Table Size 128 Table Size 256 Table Size 512
Figure 6.5.: SINAD of fixed-point mixed demodulator with various table sizes for direct lookup
SINAD dB
-38.0-37.0-36.0-35.0-34.0-33.0-32.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]
Table Size 8 Table Size 16 Table Size 32
Figure 6.6.: SINAD of fixed-point mixed demodulator with various table sizes for interpolated lookup
SINAD dB
-38.0-37.0-36.0-35.0-34.0-33.0-32.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]
Interpolation with Table Size 16 Direct with Table Size 128 Floating-Point Implementation
Figure 6.7.: SINAD comparison of direct and interpolated lookup for fixed-point mixed demodulator and thefloating-point implementation
function of the standard math library, which provides several trigonometric, exponential, and hy-perbolic math functions. The direct lookup uses a lookup table with 128 values and the interpo-lated lookup uses two tables with 16 values in each of them. It shows that the interpolated versionachieves better results although it needs less storage. This advantage is paid by the additionalcomputing time used to perform the interpolation.
80
6.2. Signal Quality (SINAD)
6.2.2. PLL Demodulator
The signal quality of the PLL demodulator depends on the implementation of the sine and cosinefunction used in the loop and the constants P_PLL and K_PLL. First the implementation with thedirect lookup is measured for different table sizes. The input FM signal is generated with the HPfunction generator (Appendix A.3.1), with the following parameters:
Carrier frequency fT 10.7 MHzFrequency deviation∆F 3000 HzMessage signal frequency 100-3700 Hz
SINAD dB
-40.0
-35.0
-30.0
-25.0
-20.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]
Table Size 16 Table Size 32 Table Size 64 Table Size 128
Figure 6.8.: SINAD of fixed-point PLL demodulator with various table sizes for direct lookup
Figure 6.8 shows the plot of the SINAD measured for tables’ sizes of 16, 32, 64, 128. It shows thata table size of 64 is the most appropriate for the direct lookup implementation.
Second the implementation with the interpolation is measured with different table sizes and thesame input signal parameters. Figure 6.9 shows the plot of the SINAD measured for table sizes of
SINAD dB
-40.0
-35.0
-30.0
-25.0
-20.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]
Table Size 16 Table Size 32 Table Size 64 Table Size 128
Figure 6.9.: SINAD of fixed-point PLL demodulator with various table sizes for interpolated lookup
16, 32, 64, and 128.Figure 6.10 shows the comparison of the direct lookup, the interpolated lookup and the floating-point implementation which uses the math library functions. The direct lookup uses a lookuptable with 64 values and the interpolated lookup uses two tables with 32 values in each of them.It shows that the interpolated version is not achieving a better results although it uses the sameamount of storage and even more computing time. A general problem of a linear sine interpolationis described pictorially in Figure 6.11. The bigger the step between two saved sine values is chosen,
81
Tests And Results
SINAD dB
-40.0
-35.0
-30.0
-25.0
-20.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]Interpolation with Table Size 32 Direct with Table Size 64 Floating-Point Implementation
Figure 6.10.: SINAD comparison of direct and interpolated lookup for fixed-point PLL demodulator and thefloating-point implementation
sine_buffer[i]
sine_buffer[i+1]
correction
exact sine value
interpolatedsine value
error
Figure 6.11.: Error of linear interpolation
the bigger is the error of interpolation. After the careful investigation, it is found that this fact isnot responsible for the less than expected improvement. The main reason is that the PLL outputis not directly dependent on the sine and cosine values. Thus an exact sine and cosine calculationwith an interpolation does not bring along the expected improvement. Therefore the direct lookupimplementation is the best choice and will be used.
6.2.3. Comparison of Mixed and PLL Demodulator
Figure 6.12 compares the different demodulation implementations. The floating- and the fixed-point implementation of the mixed demodulator show nearly the same behavior. The fixed-pointimplementation of the PLL has shown a worse signal quality than that of the floating-point imple-mentation for lower frequencies. In general the PLL shows a worse behavior for low frequenciesthan that of the mixed demodulator, especially around 1000 Hz. All the implementations show aslight decrease of signal quality around the frequency of 1000 Hz.
82
6.3. Robustness (S/N)
SINAD dB
-40.0
-35.0
-30.0
-25.0
-20.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]
mixed floating-point PLL floating-point mixed fixed-point PLL fixed-point
Figure 6.12.: SINAD comparison of different demodulator implementations
6.3. Robustness (S/N)
To test the robustness of the implementations noise is added to the FM signal before it is applied tothe demodulator and the signal-to-noise ratio (S/N) is measured at the demodulated signal. Thenoise is generated with a second function generater.With Neutrik A2-D the S/N can not be measured directly, but it can be determined from theTHD+N measurement (see Section 6.2), when everything other than the signal (S) is considered asnoise (NT), including the distortions (D).
1− (THD + N)(THD + N)
=1− D+N
S+D+ND+N
S+D+N
=S + D + N − (D + N)
D + N=
SD + N
=S
NT
This calculation is equal to the one used in the simulations.The implementations are tested with two different noise levels. For the first the S/N of the FMsignal is set to 20dB and for the second it is set to 15dB. Figure 6.13 shows the oscilloscope view ofthe FM signal without noise as it is generated by the function generator. Figure 6.14 shows the FMsignal with added noise which is applied to the input for the robustness measurements.
Figure 6.13.: Oscilloscope print FM sig-nal normal
Figure 6.14.: Oscilloscope print FM sig-nal with noise added
Figure 6.15 shows the spectrum of the demodulated signal with an FM input signal which has anS/N ratio of 20dB. The fixed-point mixed implementation with the direct table lookup is used.Compared to Figure 6.1 which shows the same spectrum for an FM signal without noise, it showsclearly that the noise naturally grows. A slight deformation of the noise due to the derivation canalso be observed.
83
Tests And Results
Figure 6.15.: Spectrum of an demodulated signal with an S/N ratio of 20dB by the FM signal
6.3.1. Mixed Demodulator
For the mixed demodulator algorithm the robustness of the fixed-point implementation with thedirect lookup and the one with the interpolated lookup is measured. Further also the floating-point implementation is tested. Figure 6.16 shows the results, when the input FM signal has a S/N
S/N dB
15.0
20.0
25.0
30.0
35.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
S/N
[dB
]
Floating-Point Fixed-Point Direct Lookup Fixed-Point Interpolated Input S/N
Figure 6.16.: S/N of the mixed demodulated signal with a S/N of 20dB at the input FM signal
of 20dB. Figure 6.16 shows the results, when the input FM signal has a S/N of 15dB. Both figuresalso show the S/N of the input FM signal as a reference.It can be seen that all the implementations have an almost identical behavior. The S/N ratio isimproved compared to the input ratio for all frequencies. It is slightly better for higher frequenciesthan for lower ones.
6.3.2. PLL Demodulator
For the PLL demodulator algorithm the fixed-point with the direct lookup and the floating-pointimplementation are tested with noise added to the input signal. Figure 6.16 shows the results,when the input FM signal has a S/N of 20dB. Figure 6.16 shows the results, when the input FM
84
6.3. Robustness (S/N)
S/N dB
10.0
15.0
20.0
25.0
30.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
S/N
[dB
]
Floating-Point Fixed-Point Direct Lookup Fixed-Point Interpolated Input S/N
Figure 6.17.: S/N of the mixed demodulated signal with a S/N of 15dB at the FM input signalS/N dB
15.0
20.0
25.0
30.0
35.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
S/N
[dB
]
Floating-Point Fixed-Point Direct Lookup Input S/N
Figure 6.18.: S/N of the PLL demodulated signal with a S/N of 20dB at the input FM signalS/N dB
10.012.014.016.018.020.022.024.026.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
S/N
[dB
]
Floating-Point Fixed-Point Direct Lookup Input S/N
Figure 6.19.: S/N of the PLL demodulated signal with a S/N of 15dB at the FM input signal
signal has a S/N of 15dB. Again both figures also show the S/N of the input FM signal for refer-ence.
6.3.3. Comparison of Mixed and PLL Demodulator
Figure 6.20 compares the different fixed-point demodulation implementations. The mixed demod-ulator algorithm is more robust than the PLL demodulator algorithm. It can be seen that the PLLshows a poor behavior at around 1000 Hz, which also could be observed by the signal qualitymeasurements in Section 6.2.
85
Tests And Results
SINAD dB
10.0
15.0
20.0
25.0
30.0
35.0
0 500 1000 1500 2000 2500 3000 3500 4000Frequency [HZ]
SIN
AD
[dB
]Mixed Dem. -20dB Mixed Dem. -15dB PLL Dem. -20dB PLL Dem. -15dB
Figure 6.20.: S/N of the PLL demodulated signal with a S/N of 15dB at the FM input signal
6.4. Computing Time
6.4.1. Demodulation Functions
To benchmark the implementation each of the called functions is timed. This is made with theDSP/BIOS STS module (statistics objects manager) and the CLK_gethtime function of theDSP/BIOS. CLK_gethtim e returns the number of high resolution clock cycles that have occurred.The time measurement are included between preprocessor directives to easily turn it on and off.Therefore function calls look like:
#if FM_DEM_CF_FUNC_TIME_STSSTS_set(&mix_sts,CLK_gethtime());
#endifquad_mix(in_buffer_ptr,re_buffer,im_buffer);#if FM_DEM_CF_FUNC_TIME_STS
STS_delta(&mix_sts,CLK_gethtime());#endif
#if FM_DEM_CF_FUNC_TIME_STSSTS_set(&dem_sts,CLK_gethtime());
#endif#if (FM_DEMODULATOR==FM_PLL_DEM)
pll_demodulate(re_buffer,im_buffer,out_buffer);#elif (FM_DEMODULATOR==FM_MIXED_DEM)
mixed_demodulate(re_buffer,im_buffer,out_buffer);#else
#error No demodulator algorithm defined#endif#if FM_DEM_CF_FUNC_TIME_STS
STS_delta(&dem_sts,CLK_gethtime());#endif
#if FM_DEM_CF_FUNC_TIME_STSSTS_set(&filter_sts,CLK_gethtime());
#endifout_filter(out_buffer,out_buffer_ptr);#if FM_DEM_CF_FUNC_TIME_STS
STS_delta(&filter_sts,CLK_gethtime());#endif
STS_set can be used in conjunction with STS_delta to benchmark program performance.STS_set saves a value as the previous value in an STS object. STS_delta subtracts this savedvalue from the value it is passed.
The functions of the different implementations of the phases explained in Section 5.4.2 are com-piled with the different optimization levels of the compiler. Additionally the debug information isturned off combined with the highest optimization level (-o3 & no Debug).
86
6.4. Computing Time
-o0
• Performs control-flow-graph simplification
• Allocates variables to registers
• Performs loop rotation
• Eliminates unused code
• Simplifies expressions and statements
• Expands calls to functions declared inline
-o1 Performs all -o0 optimizations, and:
• Performs local copy/constant propagation
• Removes unused assignments
• Eliminates local common expressions
-o2 Performs all -o1 optimizations, and:
• Performs software pipelining
• Performs loop optimizations
• Eliminates global common subexpressions
• Eliminates global unused assignments
• Converts array references in loops to incrementedpointer form
• Performs loop unrolling
-o3 Performs all -o2 optimizations, and:
• Removes all functions that are never called
• Simplifies functions with return values that are neverused
• Inlines calls to small functions
• Reorders function declarations so that the attributesof called functions are known when the caller is opti-mized
• Propagates arguments into function bodies when allcalls pass the same value in the same argument posi-tion
• Identifies file-level variable characteristics
The results are shown in Figures 6.21 to 6.25. It shows that the demodulation functions did notimprove as much as the quadrature mixer and out filter functions. In the mixed demodulator thisis caused by the division which is as a function call. Therefore a branch occurs in the loop andthe optimizer is not able to parallelize the loop with software pipelining. In the PLL demodulatorimplementation the if-then-else structure to determine the sine and cosine also makes it impossibleto perform those optimization.
050
100150200250300350400450
compiler optimization level
time
[µs]
simple C impl. (Phase 1) 421 356 298 194 193 163.4optimized C (Phase2 Step1) 392 337 282 174 174 147.4comp. spez. C (Phase2 Step2) 391 338 261 37 37 35.9Linear Assembly (Phase3) 203 202 131 29 29 27.1
none -o0 -o1 -o2 -o3 -o3 & no Debug
Figure 6.21.: Time measurement results Quadrature mixer ( quad_mix )
Figure 6.26 compares the performance of mixed demodulation function with direct lookup, themixed demodulation function with interpolated lookup and the PLL demodulation function. Thecomparison is carried out with the most time optimized implementation. The difference betweenthe direct lookup and the interpolated lookup implementation of the mixed demodulator is verysmall, less than 9% when compiled with the highest optimization level. Hence the additionalcomputing load due to the interpolation is rather small compared to the benefit of less storage andbetter signal quality (see Section 6.2.1).The PLL demodulator uses clearly more computing time then the two mixed demodulators al-though it does not use a division. The computing load is introduced by the complex if-then-elsestructure to perform the sine and cosine functions.
87
Tests And Results
0
5
10
15
20
25
30
35
compiler optimization level
time
[µs]
simple C impl. (Phase 1) 32 23 19 17 17 12.6optimized C (Phase2 Step1) 32 23 19 17 17 12.6comp. spez. C (Phase2 Step2) 32 23 19 17 16 12.4
none -o0 -o1 -o2 -o3 -o3 & no Debug
Figure 6.22.: Time measurement results mixed demodulator direct lookup ( mixed_demodulate )
0
5
10
15
20
25
30
35
40
compiler optimization level
time
[µs]
simple C impl. (Phase 1) 35 34 21 19 19 13.5optimized C (Phase2 Step1) 35 34 21 19 19 13.5comp. spez. C (Phase2 Step2) 35 34 21 19 19 13.5
none -o0 -o1 -o2 -o3 -o3 & no Debug
Figure 6.23.: Time measurement results mixed demodulator interpolated lookup ( mixed_demodulate )
0
10
20
30
40
50
60
70
compiler optimization level
time
[µs]
simple C impl. (Phase 1) 64 43 33 31 31 21.6optimized C (Phase2 Step1) 64 43 33 31 31 21.6comp. spez. C (Phase2 Step2) 63 41 33 31 31 21.6
none -o0 -o1 -o2 -o3 -o3 & no Debug
Figure 6.24.: Time measurement results PLL demodulator direct lookup ( pll_demodulate )
88
6.4. Computing Time
020406080
100120140160180200
compiler optimization level
time
[µs]
simple C impl. (Phase 1) 189 140 103 48 48 46.4optimized C (Phase2 Step1) 162 120 91 47 47 45.1comp. spez. C (Phase2 Step2) 175 126 95 16 16 15.6
none -o0 -o1 -o2 -o3 -o3 & no Debug
Figure 6.25.: Time measurement results out filter ( out_filter )
0
10
20
30
40
50
60
70
compiler optimization level
time
[µs]
mixed_demodulate 32 23 19 17 16 12.4mixed_demodulate (inter.) 35 34 21 19 19 13.5pll_demodulate 63 41 33 31 31 21.6
none -o0 -o1 -o2 -o3 -o3 & no Debug
Figure 6.26.: Time comparison of the demodulation functions
89
Tests And Results
6.4.2. Interrupt Routines
To measure the executing time of the interrupt routines (EDMA interrupt ,DAC interrupt anddemodulate software interrupt (SWI)) the same measurement proceed as in Section 6.4.1 is applied.At the beginning of the routine a STS_set call is added. The STS_delta call is included at theend of the routine.
3.3 1.0
55.9
3.3 1.0
57.1
3.3 1.0
69.6
0.010.020.030.040.050.060.070.080.0
EDMA INT ADC INT SWI INTinterrupt routine
time
[µs]
mixed direct mixed interpolated pll
Figure 6.27.: Executing time of interrupt routines
The results are shown in Figure 6.27. The executing time for the hardware interrupt routines(EDMA INT , DAC INT) is for all implementations the same, because they are implementedequally, the difference is in the software interrupt where the actual demodulation is performed.The execution time of the hardware interrupts is very short compared to the time used by the soft-ware interrupt. This is as mentioned in Section 5.1.6 because the hardware interrupts are kept asshort as possible and all the computing is executed in the software interrupt.
6.4.3. CPU Processing Load
The DSP/BOIS tool CPU Load Graph displays a graph of the target CPU processing load. TheCPU load is defined as the amount of time not spent performing the low-priority task that runswhen no other thread needs to run (idle loop). Thus all the other instrumenting is turned off andthe CPU load graph shows the CPU load introduced by the FM demodulation.Figure 6.28 shows the CPU processing load for the time optimized implementations compiledwith the highest optimization level. All the implemented algorithms use less than 6% of the CPUprocessing. The difference between the different implementations is less than 0.1%.
90
6.4. Computing Time
5.30 5.31 5.360.00
10.0020.0030.0040.0050.0060.0070.0080.0090.00
100.00
CPU
pro
cess
ing
load
[%]
mixed direct mixed interpolated pll
Figure 6.28.: CPU processing load
91
Tests And Results
92
7. Conclusions and Recommendations
The given and planned objectives have been achieved. The mixed and the PLL demodulator al-gorithms are implemented on a DSP. The implementations are optimized in computing load andhave been tested for signal quality and robustness.
The PLL demodulator function needs nearly twice as much computing time as the mixed demod-ulator function. Hence the total computing time of the PLL implementation is about 20% higherthan the one of the mixed demodulator. Also the signal quality of the PLL is worse. There aresome distortions around 1000Hz. The distortion are due to the non-linear closed loop.For the given specifications, the mixed demodulator is clear a better choice. The difference in com-puting time between the implementation with the direct lookup and the interpolated lookup tableis smaller than 3%, but the used storage space is lower and the signal quality is better. Thereforethe implementation with the interpolated lookup table is preferred.The PLL would be useful for applications with a lower frequency range. That would reduce thesignal size in the PLL and so avoid the distortions. A smaller derivation brings along the sameeffect.
The CPU processing load is lower than 6% for all the optimized implementations. This couldstill be reduced by also rewriting the demodulation and the filter functions in linear assembly oreven hand optimized assembly.An implementation of the adaptive seeking of the carrier angular frequency in fixed-point wouldimprove the signal quality. The output filter could then be reduced to a low-pass filter becausethere is no DC offset yet. That will also decrease the computing time.Some improvements could be done in the PLL implementation. In the lookup table includes onlythe values of a fourth of sine wave. That brings along more queries and calculations to calculatethe sine values. If more sine values are stored in the lookup table less queries and calculations areneeded. Hence the computing time will be reduced but the needed storage space increases.
The floating-point implementations are not as slow as excepted. In this work the floating-pointimplementations are not time optimized. Because the latest DSP generations support both thefloating-point and fixed-point, it is worth optimizing them. The effort of a floating-point imple-mentation is much lesser than a fixed-point implementation.
Singapore 11.1.2002 Christoph Haller Franz Schnyder
93
Conclusions and Recommendations
94
A. Equipment
A.1. Hardware
A.1.1. DSP Board
Name No. TMS320C6711DSK
Manufacturer Texas Instruments
Description DSP Starter Kit : The DSK is a parallel port interfaced platform that allows TI, its cus-tomers, and third-parties, to efficiently develop and test applications for the C6711. The DSKconsists of a C6711-based printed circuit board that will serve as a hardware reference designfor TI’s customers’ products. With extensive host PC and target DSP software support, in-cluding bundled TI tools, the DSK provides ease-of-use and capabilities that are attractive toDSP engineers.
Key Features
• 150-MHz C6711DSP capable of executing 900 million floating-point operations per sec-ond (MFLOPS)
• Dual clock support; CPU at 150MHz and external memory interface (EMIF) at 100MHz
• Parallel port controller (PPC) interface to standard parallel port on a host PC (EEP orbi-directional SPP support)
• 16M Bytes of 100 MHz synchronous dynamic random access memory (SDRAM)
• 128K Bytes of flash programmable and erasable read only memory (ROM)
• 8-bit memory-mapped I/O port
• Embedded JTAG emulation via the parallel port and external XDS510 support
• Host port interface (HPI) access to all DSP memory via the parallel port
• 16-bit audio codec
• Onboard switching voltage regulators for 1.8 volts direct current (VDC) and 3.3 VDC
• Six light emitting diode (LED) indicators (one power-on indicator, one TBC-in-use indi-cator, one reset-active indicator, and three user-defined indicators)
• External desktop operation utilizing an external power supply and IEEE1284 parallelcable or an XDS510 emulator. Power supply and IEEE1284 parallel cable are providedwith the DSK.
• Expansion memory and peripheral connectors for daughterboard support
95
Equipment
A.1.2. Analog-to-Digital Converter
Name No. THS1408EVM
Manufacturer Texas Instruments
Description Analog Digital Converter: The THS1408 evaluation module (EVM) provides a plat-form for evaluating the THS1408 analog-to-digital converter (ADC) under various signal,reference, and supply conditions.
Key Features
• 14-Bit Resolution
• 8 MSPS
• Internal Reference
• Timing Compatible with TMS320C6000 DSP
A.2. Software
A.2.1. DSP IDE
Name No. Code Composer Studio
Version 2.00.00
Manufacturer Texas Instruments
Description Integrated Development Environment (IDE) : Code Composer Studio (CCS) softwareis a fully IDE supporting Texas Instruments industry leading DSP platforms. Code ComposerStudio integrates all host and target tools in a unified environment to simplify DSP systemconfiguration and application design. This easy to use development environment allows DSPdesigners of all experience levels full access to all phases of the code development process.
A.2.2. MATLAB
Name No. MATLAB & SIMULINK
Version 6.0.0.88 Release 12
Manufacturer The MathWorks
Description MATLAB is a high-performance language for technical computing. It integrates com-putation, visualization, and programming in an easy-to-use environment where problemsand solutions are expressed in familiar mathematical notation.
A.3. Signal And Measure Instruments
A.3.1. Signal Generator
Name No. 33120A
Manufacturer Hewlett Packard
Description 15 MHz Function / Arbitrary Waveform Generator
96
A.3. Signal And Measure Instruments
A.3.2. Oscilloscope
Name No. 54645A
Manufacturer Hewlett Packard
Description 100 MHz Oscilloscope (200 MSa/s)
A.3.3. Audio Measurement System
Name No. A2-D Audio Measurement System
Manufacturer Neutrik Cortex Instruments
Description High performance two-channel audio test set. With a high performance analyzerproviding a wide variety of measurement functions.
97
Equipment
98
B. Abbreviations and Symbols
B.1. Formula Symbols
b bandwidth HzfA sample rate HzfN message frequency HzfT carrier frequency HzJn(x) bessel functionk harmonic distortionkFM FM Constantq quantization intervalsbasis complex baseband signalsD demodulated message signalsFM FM modulated signalsN message signalsimag Imaginary baseband signal (cos)sreal Real baseband signal (cos)sT carrierS/N signal to noise ratio dBT sample time sec∆F frequency derivationφFM FM argument functionωT carrier frequency rad/secωN message frequency rad/secµ Modulation index
99
Abbreviations and Symbols
B.2. AbbreviationsADC Analog to Digital ConverterBSL Board Support LibraryCCS Code Composer Studioclk ClockCPU Center Processing UnitCSL Chip Support LibraryDAC Digital to Analog ConverterDSK DSP Starter KitDSP Digital Signal ProcessorEDMA Enhanced Direct Memory AccessEMIF External Memory InterfaceEq EquationEVM Evaluation ModuleFFT Fast Fourier TransformFIR Finite Inpulse ResponseFM Frequency ModulationGSM-R Global System for Mobile Communication - RailwayHSR Fachhochschule RapperswilHW HardwareHWI Hardware InterruptI InphaseIDE Integrated Development EnvironmentIIR Infinite Inpulse ResponseINT InterruptIRQ Interrupt RequestMcBSP Multichannel Buffered Serial PortNTU Nanyang Technological UniversityPLL Phase-Locked LoopPMR Private (Professional) Mobile RadioQ QuadraturephaseS/N Signal to Noise RatioSINAD Signal, Noise and DistortionSWI Software InterruptTCC Transfer Complete CodeTERRA Terrestrial Trunked RadioTERRAPOL Digital PMR technologyTHD+N Total Harmonic Distortion and NoiseTi Texas InstrumentsVCO Voltage Controlled OscillatorVHF Very High Frequency
100
C. Simulation Measure Algorithms
C.1. Harmonic distortion k and SINAD
A statement about the signal quality can be done by the harmonic distortion factor k. It shows therate of nonlinear distortions in a signal. It is defined as:
k =
√√√√ A22· f + A2
3· f + A24· f · · ·
A2f + A2
2· f + A23· f + A2
4· f · · ·(C.1)
It is rather difficult to measure all the single amplitudes of the oscillation. Therefore the followingis used:
k =
√Ptot − Pf
Ptot(C.2)
The power is calculated over a time period. Ptot is the power of the hole signal. To calculatethe power Ptot − Pf the signal is first filtered with a band-stop and calculated afterwards. Theso calculated factor corresponds to the harmonic distortion if there are just the harmonics andno noise. If this is not the case, not only the harmonics are included, but also the noise. The socalculated factor is called SINAD ( signal, noise and distortion ).For the simulation the formula can be written as:
k =
√√√√ TTsim
· ∑ (s (n) ∗ BSP (z))2
TTsim
· s2 (n)=
√∑ (s (n) ∗ hBSP (n))2
s2 (n)
A MATLAB function was kfaktor created.
kfaktor.m
function k=kfaktor(signal,f0,fa)
% k=kfaktor(signal,f0,fa)%% Berechnet den Klirrfaktor k eines Signals mit frequenz f0 welches% mit einer Frequenz von fa abgetastet wurde mit der Hilfe einer% Bandsperre bei f0% Wichtig signal muss mindestens 2000 Werte beinhalten
buffer= size (signal);buffer=buffer(1); %SignallaengefN=fa/2; %BezugsfrequenzN=1000; %FIR Filterl"ange
if (buffer < (2*N))error (’Signal Vektor muss mindestens 2000 Werte enthalten’ );end
%FIR BandsperreB=fir1(N,[(f0-100)/fN (f0+100)/fN ],’stop’ ,kaiser(N+1,8));
101
Simulation Measure Algorithms
signal2= filter (B,1,signal);
%Abschneiden des Einschwingen des Filterssignal = signal(N:buffer);signal2 = signal2(N:buffer);
k=sqrt (( sum(signal2.^2))/( sum(signal.^2)));
C.2. Signal to noise ratio S/N
Also to measure the signal to noise ratio a MATLAB function snr was programmed. It calculatesthe S/N ration in dB. With a bandpass the message signal is filtered out of the hole signal. This issubtracted from the hole signal. The result is the noise.
snr.m
function sn=snr(signal,f0,fa)% sn=snr(signal,f0,fa) [in dB]%% snr berechnet den Signal Noise abstand in einem signal% das mit fa abgetastet ist f0 ist die Frequenz des Signal oder% die Start- und und Endfrequenz des [fstart fstop] Signals.% sn ist eine Angabe in dB.
buffer= size (signal);buffer=buffer(1); %SignallaengefN=fa/2; %BezugsfrequenzN=1000; %FIR Filterl"ange
if (buffer < (2*N))error (’Signal Vektor muss mindestens 2000 Werte enthalten’ );end
%Filter berechnungif ( size (f0)==[ 1 2])
B=fir1(N,[(f0(1))/fN (f0(2))/fN],kaiser(N+1,8));else
B=fir1(N,[(f0-100)/fN (f0+100)/fN],kaiser(N+1,8));endreinsignal = filter (B,1,signal); noise = signal-reinsignal;
%Abschneiden des Einschwingen des Filtersreinsignal = reinsignal(N:buffer); noise = noise(N:buffer); signal = signal(N:
buffer);
psig= sum(reinsignal.^2); pnoi= sum(noise.^2);sn=psig/pnoi; sn=10* log10 (sn);
102
D. Bibliography
D.1. English Books
[1] N. Kehtarnavaz and B. Simsek, C6x-Based Digital Signal Processing, Prentice Hall, New Jersey2000.
[2] N. Dahnoun, DSP implementation using the TMS320C6000 DSP platform, Prentice Hall, HarlowEngland 2000.
[3] MathWorks, Simulink r Dynamic System Simulation for Matlab r (Version 4), MathWorks, NatickNovember 2000.
D.2. German Books
[4] P. Gerdsen and P. Kröger, Digitale Signalverarbeitung in der Nachrichtenübertragung, Springer-Verlag, Berlin-Heidelberg 1993.
[5] Dr. A. Schüeli, Digitale Signalverarbeitung, Rapperswil, Version 2001.
[6] K. D. Kammeyer and K. Kroschel, Digitale Signalverarbeitung, Teuber Studienbücher, Stuttgart1996.
[7] E. Pehl, Digitale und analoge Nachrichtenübertragung, Hüntig, Heidelberg 1998.
[8] E. Stadler, Modulationsverfahren, Vogel-Verlag ,Würzburg 1976.
[9] H.D. Lüke, Signalübertragung, Springer-Verlag, Berlin-Heidelberg 1985.
D.3. Texas Instruments Documentation
[10] SPRA509 Aaron Kofi Aboagye, Overflow Avoidance Techniques in Cascaded IIR Filter Implemen-tations on the TMS320 DSP’s Texas Instruments , May 1999.
[11] SLAU045A , THS14xx/5691 EVM for the THS14xx ADC and THS56xx DAC Families User’s GuideTexas Instruments , September 2000.
[12] SLAS248 , Data Sheet THS1408 Analog-to-Digital Converter Texas Instruments , December 1999.
[13] SLAS202B , Data Manual TLC320AD535C/I Dual Channel Voice/Data Codec Texas Instruments ,2000.
[14] SPRS088B , Data Sheet TMS320C6711, TMS320C6711B floating-point digital signal processorsTexas Instruments , February 1999.
103
Bibliography
[15] SPRU198F , TMS320C6000 Programmer’s Guide Texas Instruments , February 2001.
[16] SPRU190D , TMS320C6000 PeripheralsReference Guide Texas Instruments , February 2001.
[17] SPRU401B , TMS320C6000 Chip Support Library API UserŠs Guide Texas Instruments , April2001.
[18] SPRU432 , TMS320C6000 DSK Board Support Library API UserŠs Guide Texas Instruments ,October 2000.
104
E. Simulink models
E.1. Baseband-Delaydemodulator
Idealer Basisband-Verzögerungsdemodulator
Callback Routines:InitFcn -> init_verzoegerungIdeal.m StopFcn -> stop_verzoegerungIdeal.m
asin
arkussinus
imag
To Workspace7
real
To Workspace6
imagnorm
To Workspace5
realnorm
To Workspace4
fmsignal
To Workspace3
tvec
To Workspace2
outsignal
To Workspace1
insignal
To Workspace
s
Real (Cos)
Imag (Sin)
QuadraturMischer
Quad Mischer
Product1
Product
1/(T*K)
Normierung auf 1
1
Gain2
sN sFMFMModulator
FM Modulator
Out1
Eingangssignal
z-1
Delay1
z-1
Delay
Clock
In1
In2
Out1
Out2
ReelerAmplituden
Normalisierer
Amplituden Normalisierer1
PUSH
Alle Graphen Schliessen
sFM
sImag
sReal
sN
sRealNV
sImagNV
sRealN
SImagN
Figure E.1.: Blockschaltbild Simulink Aufbau Idealer Baseband-Delaydemodulator
105
Simulink models
DSP
Bas
isba
nd-V
erzö
geru
ngsd
emod
ulat
orC
allb
ack
Rou
tines
:In
itFcn
-> in
it_ve
rzoe
geru
ngQ
ant.m
Stop
Fcn
-> s
top_
verz
oege
rung
Qua
nt.m
imag
To W
orks
pace
7
real
To W
orks
pace
6
imag
norm
To W
orks
pace
5
real
norm
To W
orks
pace
4
fmsi
gnal
To W
orks
pace
3
tvec
To W
orks
pace
2
outs
igna
l
To W
orks
pace
1
insi
gnal
To W
orks
pace
Satu
ratio
n7
Satu
ratio
n6
Satu
ratio
n5
Satu
ratio
n4
Satu
ratio
n3
Satu
ratio
n2
Satu
ratio
n1
Satu
ratio
n
Qua
ntiz
er9
Qua
ntiz
er7
Qua
ntiz
er6
Qua
ntiz
er5
Qua
ntiz
er4
Qua
ntiz
er3
Qua
ntiz
er2
Qua
ntiz
er1
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
d M
isch
er
Prod
uct1
Prod
uct
1/(T
*K)
Nor
mie
rung
au
f 1
1 Gai
n2
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
Out
1
Eing
angs
sign
al
butte
r
Dig
ital I
IRFi
lter
z-1
Del
ay1
z-1
Del
ay
Clo
ck
asin
Tabe
lle
Arku
ssin
usTa
belle
2
In1
In2
Out
1
Out
2
Ree
ler
Ampl
itude
nN
orm
alis
iere
r
Ampl
itude
n N
orm
alis
iere
r
PUSH
Alle
Gra
phen
Sch
liess
en
sRea
l
sIm
ag
sRea
lNV
sIm
agN
V
sNsF
M
Figure E.2.: Blockschaltbild Simulink Aufbau DSP Baseband-Delaydemodulator
106
E.1. Baseband-Delaydemodulator
DSP
Bas
isba
nd-V
erzö
geru
ngsd
emod
ulat
or m
it N
oise
Cal
lbac
k R
outin
es:
InitF
cn ->
init_
verz
oege
rung
Noi
se.m
Stop
Fcn
-> s
top_
verz
oege
rung
Noi
se.m
fmU
nois
e
To W
orks
pace
4
fmsi
gnal
To W
orks
pace
3
tvec
To W
orks
pace
2
nois
e
To W
orks
pace
10
outs
igna
l
To W
orks
pace
1
insi
gnal
To W
orks
pace
Satu
ratio
n7
Satu
ratio
n6
Satu
ratio
n5
Satu
ratio
n4
Satu
ratio
n3
Satu
ratio
n2
Satu
ratio
n1
Satu
ratio
n
Qua
ntiz
er9
Qua
ntiz
er7
Qua
ntiz
er6
Qua
ntiz
er5
Qua
ntiz
er4
Qua
ntiz
er3
Qua
ntiz
er2
Qua
ntiz
er1
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
d M
isch
er
Prod
uct1
Prod
uct
1/(T
*K)
Nor
mie
rung
au
f 1
Gau
ssia
n
Gau
ssia
n N
oise
Gen
erat
or
1 Gai
n2
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
Out
1
Eing
angs
sign
al
butte
r
Dig
ital I
IRFi
lter1
z-1
Del
ay1
z-1
Del
ay
Clo
ck
asin
Tabe
lle
Arku
ssin
usTa
belle
2
In1
In2
Out
1
Out
2
Ree
ler
Ampl
itude
nN
orm
alis
iere
r
Ampl
itude
n N
orm
alis
iere
r
PUSH
Alle
Gra
phen
Sch
liess
en
sRea
l
sIm
ag
sRea
lNV
sIm
agN
V
sNsF
M
Figure E.3.: Blockschaltbild Simulink Aufbau DSP Baseband-Delaydemodulator mit gausschem Rauschen
107
Simulink models
E.2. Phase-Adapter-Demodulator
Idea
ler P
hase
nwan
dler
Dem
odul
ator
Cal
lbac
k R
outin
es:
InitF
cn ->
init_
phas
enw
andl
erId
eal.m
Stop
Fcn
-> s
top_
phas
enw
andl
erId
eal.m
1/(T
*K)
norm
ieru
ng a
uf 1
imag
To W
orks
pace
7
real
To W
orks
pace
6
fmsi
gnal
To W
orks
pace
3
tvec
To W
orks
pace
2
outs
igna
l
To W
orks
pace
1
insi
gnal
To W
orks
pace
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
d M
isch
er
1 Gai
n2sN
sFM
FMM
odul
ator
FM M
odul
ator
Out
1
Eing
angs
sign
al
Div
ison
z-1
Del
ay
Clo
ck
atan
Arku
stan
gens
PUSH
Alle
Gra
phen
Sch
liess
en
sFM
sN
sRea
l
sIm
ag
Figure E.4.: Blockschaltbild Simulink Aufbau Idealer Phase-Adapter-Demodulator
108
E.3. Phasenregelschleife
E.3. Phasenregelschleife
Dem
odul
ierte
s N
achr
icht
ensi
gnal
-K-
kFM
-1 gain
sin
Trig
onom
etric
Func
tion1
cos
Trig
onom
etric
Func
tion
t2
To W
orks
pace
2
t1
To W
orks
pace
1
t
To W
orks
pace
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
drat
urm
isch
erPr
oduc
t1
Prod
uct
2
PN
achr
icht
ensi
gnal
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
T z-1
Dis
cret
e-Ti
me
Inte
grat
or
Clo
ck
Figure E.5.: Blockschaltbild Simulink Aufbau Idealer PLL
109
Simulink models
Dem
odul
ierte
s N
achr
icht
ensi
gnal
Qua
ntiz
er 5
Satu
ratio
n
-K-
kFM
-1 gain
sin
Trig
onom
etric
Func
tion1
cos
Trig
onom
etric
Func
tion
t2
To W
orks
pace
2
t1
To W
orks
pace
1
t
To W
orks
pace
Satu
ratio
n1
Qua
ntiz
er7
Qua
ntiz
er6
Qua
ntiz
er4
Qua
ntiz
er3
Qua
ntiz
er2
Qua
ntiz
er1
Qua
ntiz
er
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
drat
urm
isch
er
Prod
uct1
Prod
uct
-K- P
Nac
hric
hten
sign
al
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
T z-1
Dis
cret
e-Ti
me
Inte
grat
or
butte
r
Dig
ital I
IRFi
lter D
esig
n
Clo
ck
Figure E.6.: Blockschaltbild Simulink Aufbau DSP PLL
110
E.3. Phasenregelschleife
Dem
odul
ierte
s N
achr
icht
ensi
gnal
Qua
ntiz
er 5
Satu
ratio
n
-K-
kFM
-1 gain
sin
Trig
onom
etric
Func
tion1
cos
Trig
onom
etric
Func
tion
t3
To W
orks
pace
3
t2
To W
orks
pace
2
t1
To W
orks
pace
1
t
To W
orks
pace
Satu
ratio
n1
Qua
ntiz
er7
Qua
ntiz
er6
Qua
ntiz
er4
Qua
ntiz
er3
Qua
ntiz
er2
Qua
ntiz
er1
Qua
ntiz
er
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
drat
urm
isch
er
Prod
uct1
Prod
uct
-K- P
Nac
hric
hten
sign
al
Gau
ssia
n
Gau
ssia
n N
oise
Gen
erat
or
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
T z-1
Dis
cret
e-Ti
me
Inte
grat
or
butte
r
Dig
ital I
IRFi
lter D
esig
n
Clo
ck
Figure E.7.: Blockschaltbild Simulink Aufbau DSP PLL mit gausschem Rauschen
111
Simulink models
E.4. Mix Demodulator
Idea
ler M
ix D
emod
ulat
orC
allb
ack
Rou
tines
:
InitF
cn ->
init_
mix
Idea
l.mSt
opFc
n ->
sto
p_m
ixId
eal.m
imag
To W
orks
pace
7
real
To W
orks
pace
6
fmsi
gnal
To W
orks
pace
3
tvec
To W
orks
pace
2
outs
igna
l
To W
orks
pace
1
insi
gnal
To W
orks
pace
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
d M
isch
er
Prod
uct3
Prod
uct2
Prod
uct1
Prod
uct
1/(T
*K)
Nor
mie
rung
auf 1
1 Gai
n2
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
Out
1
Eing
angs
sign
al
Div
isio
nz-1
Del
ay1
z-1
Del
ay
Clo
ck
atan
Arku
stan
gens
PUSH
Alle
Gra
phen
Sch
liess
en
sFM
sIm
ag
sRea
l
sN
sRea
lNV
sRea
lNV
sIm
agN
V
sIm
agN
VsI
mag
NV
Figure E.8.: Blockschaltbild Simulink Aufbau Idealer Mix Demodulator
112
E.4. Mix Demodulator
DSP
Mix
Dem
odul
ator
Cal
lbac
k R
outin
es:
InitF
cn ->
init_
mix
Qua
nt.m
Stop
Fcn
-> s
top_
mix
Qua
nt.m
imag
To W
orks
pace
7
real
To W
orks
pace
6
help
var
To W
orks
pace
4
fmsi
gnal
To W
orks
pace
3
tvec
To W
orks
pace
2
outs
igna
l
To W
orks
pace
1
insi
gnal
To W
orks
pace
Satu
ratio
n7
Satu
ratio
n6
Satu
ratio
n5
Satu
ratio
n4
Satu
ratio
n3
Satu
ratio
n2Sa
tura
tion1
Qua
ntiz
er8
Qua
ntiz
er7
Qua
ntiz
er6
Qua
ntiz
er5
Qua
ntiz
er4
Qua
ntiz
er3
Qua
ntiz
er2
Qua
ntiz
er10
Qua
ntiz
er1
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
d M
isch
er
Prod
uct3
Prod
uct2
Prod
uct1
Prod
uct
1/(T
*K)
Nor
mie
rung
auf 1
1 Gai
n2
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
Out
1
Eing
angs
sign
al
Div
isio
n
butte
r
Dig
ital I
IRFi
lter1
z-1
Del
ay1
z-1
Del
ay
Clo
ck
atan
Tabe
lle
Arku
stan
gend
sTa
belle
PUSH
Alle
Gra
phen
Sch
liess
en
sFM
sIm
ag
sRea
l
sN
sRea
lNV
sRea
lNV
sIm
agN
V
sIm
agN
V
sIm
agN
V
Figure E.9.: Blockschaltbild Simulink Aufbau DSP Mix Demodulator
113
Simulink models
DSP
Mix
Dem
odul
ator
mit
Noi
seC
allb
ack
Rou
tines
:
InitF
cn ->
init_
mix
Noi
se.m
Stop
Fcn
-> s
top_
mix
Noi
se.m
fmU
nois
e
To W
orks
pace
4
fmsi
gnal
To W
orks
pace
3
tvec
To W
orks
pace
2
nois
e
To W
orks
pace
10
outs
igna
l
To W
orks
pace
1
insi
gnal
To W
orks
pace
Satu
ratio
n7
Satu
ratio
n6
Satu
ratio
n5
Satu
ratio
n4
Satu
ratio
n3
Satu
ratio
n2Sa
tura
tion1
Qua
ntiz
er8
Qua
ntiz
er7
Qua
ntiz
er6
Qua
ntiz
er5
Qua
ntiz
er4
Qua
ntiz
er3
Qua
ntiz
er2
Qua
ntiz
er10
Qua
ntiz
er1
s
Rea
l (C
os)
Imag
(Sin
)
Qua
drat
urM
isch
er
Qua
d M
isch
er
Prod
uct3
Prod
uct2
Prod
uct1
Prod
uct
1/(T
*K)
Nor
mie
rung
auf 1
Gau
ssia
n
Gau
ssia
n N
oise
Gen
erat
or
1 Gai
n2
sNsF
MFM
Mod
ulat
or
FM M
odul
ator
Out
1
Eing
angs
sign
al
Div
isio
n
butte
r
Dig
ital I
IRFi
lter2
z-1
Del
ay1
z-1
Del
ay
Clo
ck
atan
Tabe
lle
Arku
stan
gend
sTa
belle
PUSH
Alle
Gra
phen
Sch
liess
en
sIm
ag
sRea
l
sN
sRea
lNV
sRea
lNV
sIm
agN
V
sIm
agN
V
sIm
agN
V
Figure E.10.: Blockschaltbild Simulink Aufbau DSP Mix Demodulator mit gausschem Rauschen
114
F.Li
stin
gs
Inth
efo
llow
ing
sect
ions
the
C,a
ssem
bler
,and
MA
TLA
Blis
ting
sar
ein
clud
ed.
F.1.
CLi
stin
gs
F.1.
1.A
DC
and
DA
C
adc_
TH
S140
8
List
ing
F.1:
adc_
THS1
408.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
AN
AL
OG
DIG
ITA
LC
ON
VE
RT
ER
TH
S1
40
8-
VE
RS
ION
13 4
file
:a
dc_
TH
S1
40
8.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_A
DC
_T
HS
14
08
_12
#d
efin
e_
AD
C_
TH
S1
40
8_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17 18
#in
clu
de
<cs
l_tim
er
.h
>19
#in
clu
de
<cs
l_e
mif
.h
>20
#in
clu
de
<cs
l_irq
.h
>21
#in
clu
de
<cs
l_e
dm
a.
h>
22 23#
incl
ud
e"g
lob
al_
settin
gs.
h"
24 25/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--26
de
bu
gd
efin
es
27--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/28
#d
efin
eT
HS
14
08
_E
NA
BL
E_
SE
T_
FR
EQ
029
/*e
na
ble
or
dis
ab
leth
efu
nct
ion
ths1
40
8_
setF
req
*/30 31
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
32d
efin
es
ED
MA
TC
Cfo
rth
etw
ob
uffe
rs33
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
34#
de
fine
TH
S1
40
8_
BU
FF
ER
_A
_T
CC
(4)
/**/
35#
de
fine
TH
S1
40
8_
BU
FF
ER
_B
_T
CC
(5)
/**/
36 37/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--38
de
fine
sfo
rC
on
tro
lR
eg
iste
ro
fth
eT
HS
14
08
(re
fer
SL
AS
24
8)
39--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/40
/*P
ow
er
Do
wn
D1
3*/
41#
de
fine
TH
S1
40
8_
PW
D_
NO
RM
AL
(0)
/*n
orm
al
op
era
tion
*/
42#
de
fine
TH
S1
40
8_
PW
D_
DO
WN
(1)
/*p
ow
er
do
wn
*/43
/*R
efe
ren
ceS
ele
ctD
12
*/44
#d
efin
eT
HS
14
08
_R
EF
_IN
TE
RN
AL
(0)
/*in
tern
al
refe
ren
ce*/
45#
de
fine
TH
S1
40
8_
RE
F_
EX
TE
RN
AL
(1)
/*e
xte
rna
lre
fere
nce
*/46
/*O
utp
ut
Fo
rma
tD
11
*/47
#d
efin
eT
HS
14
08
_F
OR
_S
TR
AIG
HT
(0)
/*st
raig
ht
bin
ary
*/48
#d
efin
eT
HS
14
08
_F
OR
_2
SC
OM
PL
(1)
/*2
sco
mp
lem
en
t*/
49/*
Te
stM
od
eD
8-D
10
*/50
#d
efin
eT
HS
14
08
_T
M_
NO
RM
AL
(0x0
)/*
no
rma
lo
pe
ratio
n*/
51#
de
fine
TH
S1
40
8_
TM
_R
EF
N_
RE
FN
(0x1
)/*
bo
thin
pu
ts=
RE
F-
*/52
#d
efin
eT
HS
14
08
_T
M_
VR
EF
_R
EF
N(0
x2)
/*IN
+=
Vre
f/2
,IN
-=R
EF
-*/
53#
de
fine
TH
S1
40
8_
TM
_R
EF
P_
RE
FN
(0x3
)/*
IN+
=R
EF
+,IN
-=R
EF
-*/
54#
de
fine
TH
S1
40
8_
TM
_N
OR
MA
L2
(0x4
)/*
no
rma
lo
pe
ratio
n*/
55#
de
fine
TH
S1
40
8_
TM
_R
EF
P_
RE
FP
(0x5
)/*
bo
thin
pu
ts=
RE
F+
*/56
#d
efin
eT
HS
14
08
_T
M_
RE
FN
_V
RE
F(0
x6)
/*IN
+=
RE
F-,
IN-=
Vre
f/2
*/57
#d
efin
eT
HS
14
08
_T
M_
RE
FN
_R
EF
P(0
x7)
/*IN
+=
RE
F-,
IN-=
RE
F+
*/58
/*O
ffse
tco
rre
ctio
nD
7*/
59#
de
fine
TH
S1
40
8_
OF
_E
NA
BL
E(0
)/*
en
ab
le*/
60#
de
fine
TH
S1
40
8_
OF
_D
ISA
BL
E(1
)/*
dis
ab
le*/
61/*
Re
serv
ed
Fie
lds
D0
-D6
*/62
#d
efin
eT
HS
14
08
_L
SB
_R
ES
ER
VE
D(0
x00
)/*
zero
es
for
RE
SF
ield
*/63
/*R
ese
rve
dF
iled
sD
14
-D1
5*/
64#
de
fine
TH
S1
40
8_
MS
B_
RE
SE
RV
ED
(0x0
)/*
zero
es
for
RE
SF
ield
*/65 66
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
67P
ara
me
ters
for
the
TH
S1
40
8E
VM
An
alo
gD
igita
lC
on
vert
er
68to
TM
S3
20
C6
71
169
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
70/*
--H
an
dle
pa
ram
ete
rs--
*/71
#d
efin
eT
HS
14
08
_R
ES
_A
DD
R(0
xA0
00
00
40
)/*
ad
ress
of
RE
Sre
gis
ter
*/72
#d
efin
eT
HS
14
08
_P
GA
_A
DD
R(0
xA0
00
00
44
)/*
ad
ress
of
PG
Are
gis
ter
*/73
#d
efin
eT
HS
14
08
_O
FF
_A
DD
R(0
xA0
00
00
48
)/*
ad
ress
of
OF
Fre
gis
ter
*/74
#d
efin
eT
HS
14
08
_C
TL
_A
DD
R(0
xA0
00
00
4C
)/*
ad
ress
of
CT
Lre
gis
ter
*/75
/*--
EM
IFIn
terf
ace
pa
ram
ete
rs--
*//*
Org
*/76
#d
efin
eT
HS
14
08
_R
DS
ET
UP
(1)
/*re
ad
*/77
#d
efin
eT
HS
14
08
_R
DS
TR
B(3
)78
#d
efin
eT
HS
14
08
_R
DH
LD
(1)
79#
de
fine
TH
S1
40
8_
WR
SE
TU
P(4
)/*
wri
te*/
80#
de
fine
TH
S1
40
8_
WR
HL
D(6
)81
#d
efin
eT
HS
14
08
_W
RS
TR
B(3
)82
/*--
Glo
ba
lP
ara
me
ters
*/83
#d
efin
eT
HS
14
08
_D
SP
_T
YP
ET
MS
32
0C
67
11
/*D
SP
Typ
e*/
84#
de
fine
TH
S1
40
8_
DS
P_
FR
EQ
(15
0)
/*in
MH
z*/
85 86/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--87
De
fau
ltIn
itia
lP
ara
me
ters
88--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/89
/*S
am
ple
Fre
qu
en
cy*/
90#
de
fine
TH
S1
40
8_
SA
MP
LE
_F
RE
Q(6
4)
/*in
kHz
*/91
/*D
SP
_F
RE
Q*/
92#
de
fine
TH
S1
40
8_
TIM
_P
ER
IOD
(0x1
25
)/*
=--
----
----
---
*/93
/*8
*SA
MP
LE
_F
RE
Q*/
94/*
Re
gis
ter
Pa
ram
ete
rs*/
95/*
CT
L*/
96#
de
fine
TH
S1
40
8_
PO
WT
HS
14
08
_P
WD
_N
OR
MA
L/*
no
rma
lo
pe
ratio
n*/
97#
de
fine
TH
S1
40
8_
RE
FT
HS
14
08
_R
EF
_IN
TE
RN
AL
/*in
tern
al
refe
ren
ce*/
98#
de
fine
TH
S1
40
8_
FO
RM
AT
TH
S1
40
8_
FO
R_
2S
CO
MP
L/*
2s
com
ple
me
nt
*/99
#d
efin
eT
HS
14
08
_T
MT
HS
14
08
_T
M_
NO
RM
AL
/*n
orm
al
op
era
tion
*/10
0#
de
fine
TH
S1
40
8_
OF
FT
HS
14
08
_O
F_
EN
AB
LE
/*e
na
ble
*/10
1/*
PG
A*/
102
#d
efin
eT
HS
14
08
_P
GA
(0x0
)/*
ga
ino
f7
dB
*/10
3/*
-O
FF
-*/
104
#d
efin
eT
HS
14
08
_O
FF
SE
T(0
)/*
no
offse
t*/
105
106
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
107
stru
cts
an
du
nio
ns
108
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
109
typ
ed
ef
un
ion
110
{11
1u
nsi
gn
ed
sho
rtva
lue
;11
2st
ruct
113
{11
4u
nsi
gn
ed
int
lsb
_re
serv
ed
:7;
115
un
sig
ne
din
to
ff:1
;11
6u
nsi
gn
ed
int
tm:3
;11
7u
nsi
gn
ed
int
form
at
:1;
118
un
sig
ne
din
tre
f:1
;11
9u
nsi
gn
ed
int
pw
d:1
;12
0u
nsi
gn
ed
int
msb
_re
serv
ed
:2;
121
}co
ntr
ol_
bit
;
115
Listings12
2}
TH
S1
40
8_
CT
RL;
/*th
eC
on
tro
lR
eg
iste
ro
fA
DC
(re
fer
SL
AS
24
8P
.15
)*/
123
124
typ
ed
ef
stru
ct12
5{
126
un
sig
ne
dsh
ort
pg
a;
127
un
sig
ne
dsh
ort
offse
t;
128
TH
S1
40
8_
CT
RL
ctrl
;12
9U
int3
2tim
_p
erio
d;
130
}T
HS
14
08
_C
ON
FIG
;/*
Co
nfig
ura
tion
Str
uct
*/13
113
2ty
pe
de
fst
ruct
133
{13
4vo
latil
esh
ort
*co
nst
res_
ad
dr
;13
5vo
latil
esh
ort
*co
nst
pg
a_
ad
dr
;13
6vo
latil
esh
ort
*co
nst
off_
ad
dr
;13
7vo
latil
esh
ort
*co
nst
ctl_
ad
dr
;13
8}
TH
S1
40
8_
HA
ND
LE;
/*H
an
dle
toth
eA
DC
*/13
914
0/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--14
1g
lob
al
varia
ble
s(
ext
ern
de
fine
din
.c)
142
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
143
ext
ern
TH
S1
40
8_
HA
ND
LE
hT
hs1
40
8;/*
ha
nd
leto
the
AD
Co
nve
rte
r*/
144
ext
ern
TIM
ER
_H
an
dle
hT
ime
r0;
/*h
an
dle
toth
eT
ime
r0
*/14
5e
xte
rnE
DM
A_
Ha
nd
leh
Ed
ma
In;
/*h
an
dle
toth
eIn
pu
tE
DM
A*/
146
147
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
148
glo
ba
lfu
nct
ion
s14
9--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/15
0/*
151
No
tice
:15
2=
==
==
==
153
154
-T
he
fun
ctio
n’C
SL
_in
it()’
mu
sth
ave
be
en
calle
db
efo
rea
ny
155
of
the
follo
win
gfu
nct
ion
sca
nb
eca
lled
.15
615
7-
First
call
’ths1
40
8_
init’
be
fore
usi
ng
the
oth
er
fun
ctio
ns
158
159
*/16
016
1/*
162
Initi
aliz
eth
eT
HS
14
08
:16
3S
ets
the
valu
es
for
the
EM
IFa
nd
the
Tim
er
acc
ord
ing
164
toth
eD
efa
ult
Initi
al
Pa
ram
ete
rs.
165
Se
tsu
pth
eE
DM
Afo
rP
ing
-Po
ng
-Bu
ffe
rin
g(in
Bu
ffe
rAu
nd
166
inB
uffe
rB).
167
Ma
ps
the
ED
MA
inte
rru
pt
an
de
na
ble
sit.
168
169
Pa
ram
ete
rs:
170
inB
uffe
rAp
oin
ter
toP
ing
Bu
ffe
r17
1in
Bu
ffe
rBp
oin
ter
toP
on
gB
uffe
r17
2*/
173
void
ths1
40
8_
init
(sh
ort
inB
uffe
rA[],
sho
rtin
Bu
ffe
rB[]);
174
175
/*17
6C
ha
ng
es
the
con
figu
ratio
no
fth
eT
HS
14
08
:17
7S
ets
the
the
TH
S1
40
8R
eg
iste
rsa
nd
the
Tim
er
Pe
rio
d17
8a
cco
rdin
gto
the
con
figst
ruct
.17
918
0P
ara
me
ters
:18
1co
nfig
ne
wco
nfig
ura
tion
calu
es
182
*/18
3vo
idth
s14
08
_co
nfig
(T
HS
14
08
_C
ON
FIG
con
fig);
184
185
/*18
6S
tart
sth
eT
HS
14
08
:18
7S
tart
sth
eT
ime
r0
an
de
na
ble
sth
eE
DM
Ain
terr
up
t18
8*/
189
void
ths1
40
8_
sta
rt()
;19
019
1#
ifT
HS
14
08
_E
NA
BL
E_
SE
T_
FR
EQ
192
/*19
3C
ha
ng
es
the
sam
ple
fre
qu
en
cyo
fth
eT
HS
14
08
:19
4S
ets
an
ew
Tim
er
Pe
rio
d.
195
!!O
nly
ava
ilab
leif
TH
S1
40
8_
EN
AB
LE
_S
ET
_F
RE
Q=
1!!
196
197
Pa
ram
ete
rs:
198
fre
qw
an
ted
fre
qu
en
cy19
9R
etu
rn:
200
(do
ub
le)
exa
ctfr
eq
ue
ncy
of
TH
S1
40
820
1*/
202
do
ub
leth
s14
08
_se
tFre
q(
do
ub
lefr
eq
);20
3#
en
dif
204
205
#e
nd
if/*
_A
DC
_T
HS
14
08
_*/
206
207
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_20
8E
ND
OF
TH
EF
ILE
ad
c_T
HS
14
08
.h20
9_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.2:
adc_
THS1
408.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
AN
AL
OG
DIG
ITA
LC
ON
VE
RT
ER
TH
S1
40
8-
VE
RS
ION
13 4
file
:a
dc_
TH
S1
40
8.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
de
bu
gd
efin
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#d
efin
eT
HS
14
08
_C
F_
ER
RO
R_
DIS
P1
15/*
En
ab
leE
rro
rL
og
16If
en
ab
led
a’e
rro
r_lo
g’
LO
Gn
ee
ds
tob
ed
efin
ed
inth
e17
DS
P/B
IOS
Co
nfig
->L
og
Ma
na
ge
r18
*/19 20
#if
TH
S1
40
8_
CF
_E
RR
OR
_D
ISP
21#
incl
ud
e<
std
.h
>22
#in
clu
de
<lo
g.
h>
23e
xte
rnfa
rL
OG
_O
bj
err
or_
log
;24
#e
nd
if25 26
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
27in
clu
de
s28
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
29#
incl
ud
e"a
dc_
TH
S1
40
8.h
"30 31
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
32lo
cal
fun
ctio
ns
33--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/34
void
em
if_in
it_T
HS
14
08
();
35vo
idtim
er_
init_
TH
S1
40
8()
;36
void
ad
c_e
dm
a_
init
(sh
ort
inB
uffe
rA_
ptr
[],
sho
rtin
Bu
ffe
rB_
ptr
[]);
37vo
ida
dc_
irq
_in
it()
;38 39
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
40g
lob
al
varib
les
41--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/42
TH
S1
40
8_
HA
ND
LE
hT
hs1
40
8={
43(
vola
tile
sho
rt*)
TH
S1
40
8_
RE
S_
AD
DR,
44(
vola
tile
sho
rt*)
TH
S1
40
8_
PG
A_
AD
DR,
45(
vola
tile
sho
rt*)
TH
S1
40
8_
OF
F_
AD
DR,
46(
vola
tile
sho
rt*)
TH
S1
40
8_
CT
L_
AD
DR,
47};
/*h
an
dle
toth
eA
DC
on
vert
er
*/48 49
TIM
ER
_H
an
dle
hT
ime
r0;
/*h
an
dle
toth
eT
ime
r0
*/50
ED
MA
_H
an
dle
hE
dm
aIn
;/*
ha
nd
leto
the
Inp
ut
ED
MA
*/51
ED
MA
_H
an
dle
hE
dm
aIn
Lin
kA;
/*E
DM
Alin
kfo
rB
uffe
rA
*/52
ED
MA
_H
an
dle
hE
dm
aIn
Lin
kB;
/*E
DM
Alin
kfo
rB
uffe
rB
*/53 54
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
55im
ple
me
nta
tion
of
fun
ctio
ns
56--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/57
void
ths1
40
8_
init
(sh
ort
inB
uffe
rA[],
sho
rtin
Bu
ffe
rB[])
58{
59T
HS
14
08
_C
ON
FIG
de
fco
nfig
;/*
de
fau
ltco
nfig
*/60 61
/*S
etu
pth
ee
mif
pa
ram
ete
rs*/
62e
mif_
init_
TH
S1
40
8()
;63 64
/*O
pe
na
nd
init
the
Tim
er0
*/65
time
r_in
it_T
HS
14
08
();
66 67/*
Se
tup
the
ED
MA
*/68
ad
c_e
dm
a_
init
(in
Bu
ffe
rA,
inB
uffe
rB);
116
F.1. C Listings
69 70/*
Co
nfig
ure
the
TH
S1
40
8*/
71d
efc
on
fig.
ctrl
.co
ntr
ol_
bit
.p
wd=
TH
S1
40
8_
PO
W;72
de
fco
nfig
.ct
rl.
con
tro
l_b
it.
ref
=T
HS
14
08
_R
EF;
73d
efc
on
fig.
ctrl
.co
ntr
ol_
bit
.fo
rma
t=
TH
S1
40
8_
FO
RM
AT;
74d
efc
on
fig.
ctrl
.co
ntr
ol_
bit
.tm
=T
HS
14
08
_T
M;
75d
efc
on
fig.
ctrl
.co
ntr
ol_
bit
.o
ff=
TH
S1
40
8_
OF
F;76
de
fco
nfig
.ct
rl.
con
tro
l_b
it.
msb
_re
serv
ed
=T
HS
14
08
_M
SB
_R
ES
ER
VE
D;77
de
fco
nfig
.ct
rl.
con
tro
l_b
it.
lsb
_re
serv
ed
=T
HS
14
08
_L
SB
_R
ES
ER
VE
D;78
de
fco
nfig
.o
ffse
t=
TH
S1
40
8_
OF
FS
ET;
79d
efc
on
fig.
pg
a=
TH
S1
40
8_
PG
A;80
de
fco
nfig
.tim
_p
erio
d=
TH
S1
40
8_
TIM
_P
ER
IOD
;81
ths1
40
8_
con
fig(
de
fco
nfig
);82 83
/*IR
Qse
tup
*/84
ad
c_irq
_in
it()
;85
}86 87
void
ths1
40
8_
con
fig(
TH
S1
40
8_
CO
NF
IGco
nfig
)88
{89
*h
Th
s14
08
.ct
l_a
dd
r=
con
fig.
ctrl
.va
lue
;90
*h
Th
s14
08
.o
ff_
ad
dr
=co
nfig
.o
ffse
t;
91*
hT
hs1
40
8.
pg
a_
ad
dr
=co
nfig
.p
ga
;92 93
TIM
ER
_se
tPe
rio
d(
hT
ime
r0,
con
fig.
tim_
pe
rio
d);
94/*
set
Co
un
tto
0b
eca
use
itco
uld
be
big
ge
rth
an
Pe
rio
d95
->w
ou
ldn
ee
do
ne
ove
rflo
w*/
96T
IME
R_
setC
ou
nt
(h
Tim
er0
,0x0
00
0);
97}
98 99vo
ide
mif_
init_
TH
S1
40
8()
100
{10
1/*
set
the
EM
IFp
ara
me
ters
for
the
CE
2(T
HS
14
08
)*/
102
EM
IF_
FS
ET(
CE
CT
L2,
WR
SE
TU
P,T
HS
14
08
_W
RS
ET
UP);
103
EM
IF_
FS
ET(
CE
CT
L2,
WR
ST
RB,
TH
S1
40
8_
WR
ST
RB);
104
EM
IF_
FS
ET(
CE
CT
L2,
WR
HL
D,
TH
S1
40
8_
WR
HL
D);10
5E
MIF
_F
SE
T(C
EC
TL
2,R
DS
ET
UP
,T
HS
14
08
_R
DS
ET
UP);
106
EM
IF_
FS
ET(
CE
CT
L2,
RD
ST
RB
,T
HS
14
08
_R
DS
TR
B);10
7E
MIF
_F
SE
T(C
EC
TL
2,R
DH
LD
,T
HS
14
08
_R
DH
LD)
;10
8E
MIF
_F
SE
T(C
EC
TL
2,M
TY
PE
,E
MIF
_C
EC
TL
_M
TY
PE
_A
SY
NC
32);
109
EM
IF_
FS
ET(
CE
CT
L2,
TA
,E
MIF
_C
EC
TL
_T
A_
OF(0
x00
00
00
00
));
110
}11
111
2vo
idtim
er_
init_
TH
S1
40
8()
113
{11
4T
IME
R_
Co
nfig
time
rCo
nfig
;11
5U
int3
2o
pt
;11
611
7/*
Op
en
up
time
r0
de
vice
*/11
8h
Tim
er0
=T
IME
R_
op
en
(T
IME
R_
DE
V0,
TIM
ER
_O
PE
N_
RE
SE
T);11
9T
IME
R_
rese
t(
hT
ime
r0);
120
121
#if
TH
S1
40
8_
CF
_E
RR
OR
_D
ISP
122
if(
hT
ime
r0=
=IN
V)
123
{12
4L
OG
_p
rin
tf(&
err
or_
log
,"E
rro
rT
HS
14
08
:C
ou
ldN
ot
Op
en
Tim
er
0!"
);12
5}
126
#e
nd
if12
712
8/*
Co
nfig
ure
the
time
rd
evi
ce*/
129
op
t=
TIM
ER
_F
MK(
CT
L,F
UN
C,
TIM
ER
_C
TL
_F
UN
C_
TO
UT)
130
|T
IME
R_
FM
K(C
TL,
INV
OU
T,
TIM
ER
_C
TL
_IN
VO
UT
_N
O)13
1|
TIM
ER
_F
MK(
CT
L,D
AT
OU
T,
TIM
ER
_C
TL
_D
AT
OU
T_
0)13
2|
TIM
ER
_F
MK(
CT
L,P
WID
,T
IME
R_
CT
L_
PW
ID_
ON
E)13
3|
TIM
ER
_F
MK(
CT
L,G
O,
TIM
ER
_C
TL
_G
O_
NO)
134
|T
IME
R_
FM
K(C
TL,
HL
D,
TIM
ER
_C
TL
_H
LD
_Y
ES)
135
|T
IME
R_
FM
K(C
TL,
CP
,T
IME
R_
CT
L_
CP
_C
LO
CK)
136
|T
IME
R_
FM
K(C
TL,
CL
KS
RC
,T
IME
R_
CT
L_
CL
KS
RC
_C
PU
OV
R4
)13
7|
TIM
ER
_F
MK(
CT
L,IN
VIN
P,
TIM
ER
_C
TL
_IN
VIN
P_
NO
);13
813
9tim
erC
on
fig.
ctl
=o
pt
;14
0tim
erC
on
fig.
prd
=T
HS
14
08
_T
IM_
PE
RIO
D;
141
time
rCo
nfig
.cn
t=
0;
142
TIM
ER
_co
nfig
(h
Tim
er0
,&tim
erC
on
fig);
143
}14
414
5vo
ida
dc_
ed
ma
_in
it(
sho
rtin
Bu
ffe
rA_
ptr
[],
sho
rtin
Bu
ffe
rB_
ptr
[])
146
{14
7E
DM
A_
Co
nfig
ed
ma
Co
nfig
_A
;14
8E
DM
A_
Co
nfig
ed
ma
Co
nfig
_B
;
149
150
/*o
pe
no
ne
ED
MA
Ch
an
ne
l*/
151
hE
dm
aIn
=E
DM
A_
op
en(
ED
MA
_C
HA
_T
INT
0,E
DM
A_
OP
EN
_R
ES
ET
);15
215
3#
ifT
HS
14
08
_C
F_
ER
RO
R_
DIS
P15
4if
(h
Ed
ma
In=
=E
DM
A_
HIN
V)15
5{
156
LO
G_
prin
tf(&
err
or_
log
,"E
rro
rT
HS
14
08
:C
ou
ldN
ot
Op
en
ED
MA
Ch
an
ne
l!"
);15
7}
158
#e
nd
if15
916
0/*
Ge
ta
link
tab
lefo
rA
*/16
1h
Ed
ma
InL
inkA
=E
DM
A_
allo
cTa
ble
(-1
);16
216
3#
ifT
HS
14
08
_C
F_
ER
RO
R_
DIS
P16
4if
(h
Ed
ma
InL
inkA
==
ED
MA
_H
INV)
165
{16
6L
OG
_p
rin
tf(&
err
or_
log
,"E
rro
rT
HS
14
08
:C
ou
ldN
ot
Allo
cate
ED
MA
LIN
KA
!");
167
}16
8#
en
dif
169
170
/*G
et
alin
kta
be
lfo
rB
*/17
1h
Ed
ma
InL
inkB
=E
DM
A_
allo
cTa
ble
(-1
);17
2#
ifT
HS
14
08
_C
F_
ER
RO
R_
DIS
P17
3if
(h
Ed
ma
InL
inkB
==
ED
MA
_H
INV)
174
{17
5L
OG
_p
rin
tf(&
err
or_
log
,"E
rro
rT
HS
14
08
:C
ou
ldN
ot
Allo
cate
ED
MA
LIN
KB
!");
176
}17
7#
en
dif
178
179
/*co
nfig
ura
tion
for
in_
bu
ffe
rA*/
180
ed
ma
Co
nfig
_A
.o
pt
=E
DM
A_
FM
K(O
PT
,P
RI
,E
DM
A_
OP
T_
PR
I_H
IGH)
181
|E
DM
A_
FM
K(O
PT
,E
SIZ
E,
ED
MA
_O
PT
_E
SIZ
E_
16
BIT
)18
2|
ED
MA
_F
MK(O
PT
,2
DS
,E
DM
A_
OP
T_
2D
S_
NO)
183
|E
DM
A_
FM
K(O
PT
,S
UM
,E
DM
A_
OP
T_
SU
M_
NO
NE
)18
4|
ED
MA
_F
MK(O
PT
,2
DD
,E
DM
A_
OP
T_
2D
D_
NO)
185
|E
DM
A_
FM
K(O
PT
,D
UM
,E
DM
A_
OP
T_
DU
M_
INC)
186
|E
DM
A_
FM
K(O
PT
,T
CIN
T,
ED
MA
_O
PT
_T
CIN
T_
YE
S)18
7|
ED
MA
_F
MK(O
PT
,T
CC
,E
DM
A_
OP
T_
TC
C_
OF(T
HS
14
08
_B
UF
FE
R_
A_
TC
C))18
8|
ED
MA
_F
MK(O
PT
,L
INK
,E
DM
A_
OP
T_
LIN
K_
YE
S)18
9|
ED
MA
_F
MK(O
PT
,F
S,
ED
MA
_O
PT
_F
S_
NO);
190
ed
ma
Co
nfig
_A
.sr
c=
(U
int3
2)
hT
hs1
40
8.
res_
ad
dr
;19
1e
dm
aC
on
fig_
A.
cnt
=B
UF
FE
RS
IZE
_IN
PU
T;19
2e
dm
aC
on
fig_
A.
dst
=(
Uin
t32
)in
Bu
ffe
rA_
ptr
;19
3e
dm
aC
on
fig_
A.
idx
=E
DM
A_
FM
K(ID
X,
FR
MID
X,
ED
MA
_ID
X_
FR
MID
X_
DE
FA
UL
T)19
4|
ED
MA
_F
MK(ID
X,
EL
EID
X,
ED
MA
_ID
X_
EL
EID
X_
DE
FA
UL
T);19
5e
dm
aC
on
fig_
A.
rld
=E
DM
A_
FM
K(R
LD
,E
LE
RL
D,
ED
MA
_R
LD
_E
LE
RL
D_
DE
FA
UL
T)
196
|E
DM
A_
FM
K(R
LD
,L
INK
,E
DM
A_
RL
D_
LIN
K_
OF(
hE
dm
aIn
Lin
kB))
;19
719
8/*
con
figu
ratio
nfo
rin
_b
uffe
rB*/
199
ed
ma
Co
nfig
_B
.o
pt
=E
DM
A_
FM
K(O
PT
,P
RI
,E
DM
A_
OP
T_
PR
I_H
IGH)
200
|E
DM
A_
FM
K(O
PT
,E
SIZ
E,
ED
MA
_O
PT
_E
SIZ
E_
16
BIT
)20
1|
ED
MA
_F
MK(O
PT
,2
DS
,E
DM
A_
OP
T_
2D
S_
NO)
202
|E
DM
A_
FM
K(O
PT
,S
UM
,E
DM
A_
OP
T_
SU
M_
NO
NE
)20
3|
ED
MA
_F
MK(O
PT
,2
DD
,E
DM
A_
OP
T_
2D
D_
NO)
204
|E
DM
A_
FM
K(O
PT
,D
UM
,E
DM
A_
OP
T_
DU
M_
INC)
205
|E
DM
A_
FM
K(O
PT
,T
CIN
T,
ED
MA
_O
PT
_T
CIN
T_
YE
S)20
6|
ED
MA
_F
MK(O
PT
,T
CC
,E
DM
A_
OP
T_
TC
C_
OF(T
HS
14
08
_B
UF
FE
R_
B_
TC
C))20
7|
ED
MA
_F
MK(O
PT
,L
INK
,E
DM
A_
OP
T_
LIN
K_
YE
S)20
8|
ED
MA
_F
MK(O
PT
,F
S,
ED
MA
_O
PT
_F
S_
NO);
209
ed
ma
Co
nfig
_B
.sr
c=
(U
int3
2)
hT
hs1
40
8.
res_
ad
dr
;21
0e
dm
aC
on
fig_
B.
cnt
=B
UF
FE
RS
IZE
_IN
PU
T;21
1e
dm
aC
on
fig_
B.
dst
=(
Uin
t32
)in
Bu
ffe
rB_
ptr
;21
2e
dm
aC
on
fig_
B.
idx
=E
DM
A_
FM
K(ID
X,
FR
MID
X,
ED
MA
_ID
X_
FR
MID
X_
DE
FA
UL
T)21
3|
ED
MA
_F
MK(ID
X,
EL
EID
X,
ED
MA
_ID
X_
EL
EID
X_
DE
FA
UL
T);21
4e
dm
aC
on
fig_
B.
rld
=E
DM
A_
FM
K(R
LD
,E
LE
RL
D,
ED
MA
_R
LD
_E
LE
RL
D_
DE
FA
UL
T)
215
|E
DM
A_
FM
K(R
LD
,L
INK
,E
DM
A_
RL
D_
LIN
K_
OF(
hE
dm
aIn
Lin
kA))
;21
621
7/*
con
figu
rech
an
ne
la
nd
links
*/21
8E
DM
A_
con
fig(
hE
dm
aIn
,&e
dm
aC
on
fig_
A);
219
ED
MA
_co
nfig
(h
Ed
ma
InL
inkA
,&e
dm
aC
on
fig_
A);
220
ED
MA
_co
nfig
(h
Ed
ma
InL
inkB
,&e
dm
aC
on
fig_
B);
221
222
/*e
na
ble
tra
nsf
er
com
ple
tion
inte
rru
pt
for
Aa
nd
B*/
223
ED
MA
_in
tEn
ab
le(
TH
S1
40
8_
BU
FF
ER
_A
_T
CC);
224
ED
MA
_in
tEn
ab
le(
TH
S1
40
8_
BU
FF
ER
_B
_T
CC);
225
}22
622
7vo
ida
dc_
irq
_in
it()
228
{
117
Listings22
9/*
Ma
pa
nd
en
ab
leE
DM
Ain
terr
up
t*/
230
IRQ
_m
ap(
IRQ
_E
VT
_E
DM
AIN
T,8
);23
1IR
Q_
en
ab
le(
IRQ
_E
VT
_E
DM
AIN
T);
232
}23
323
4vo
idth
s14
08
_st
art
()23
5{
236
TIM
ER
_st
art
(h
Tim
er0
);23
7E
DM
A_
en
ab
leC
ha
nn
el
(h
Ed
ma
In);
238
}23
924
0#
ifT
HS
14
08
_E
NA
BL
E_
SE
T_
FR
EQ
241
do
ub
leth
s14
08
_se
tFre
q(
do
ub
lefr
eq
)24
2{
243
Uin
t32
pe
rio
d=
0;
244
do
ub
lere
t=
0;
245
pe
rio
d=
(10
00
.0*
TH
S1
40
8_
DS
P_
FR
EQ)/(
8*
fre
q);
246
ret
=(1
00
0.0
*T
HS
14
08
_D
SP
_F
RE
Q)/(
8*
pe
rio
d);
247
248
TIM
ER
_se
tPe
rio
d(
hT
ime
r0,
pe
rio
d);
249
/*se
tC
ou
nt
to0
be
cau
seit
cou
ldb
eb
igg
er
tha
nP
erio
d25
0->
wo
uld
ne
ed
on
eo
verf
low
*/25
1T
IME
R_
setC
ou
nt
(h
Tim
er0
,0x0
00
0);
252
253
retu
rnre
t;
254
}25
5#
en
dif
256
257
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_25
8E
ND
OF
TH
EF
ILE
ad
c_T
HS
14
08
.c25
9_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
dac_
code
c
List
ing
F.3:
dac_
code
c.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2D
IGIT
AL
AN
AL
OG
CO
NV
ER
TE
RO
NB
OA
RD
CO
DE
C-
VE
RS
ION
13 4
file
:d
ac_
cod
ec.
h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
DA
C_
CO
DE
C_
12#
de
fine
_D
AC
_C
OD
EC
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17 18#
incl
ud
e<
csl_
irq
.h
>19
#in
clu
de
<cs
l_m
cbsp
.h
>20
#in
clu
de
<b
sl_
ad
53
5.
h>
21 22/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--23
glo
ba
lva
ria
ble
s(
ext
ern
de
fine
din
.c)
24--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/25 26
ext
ern
AD
53
5_
Ha
nd
leo
utA
D5
35
h;
27 28/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--29
glo
ba
lfu
nct
ion
s30
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
31 32/*
33In
itia
lize
the
cod
ec:
34S
ets
up
the
con
figa
nd
ma
ps
an
de
na
ble
sth
ein
terr
up
t35
*/36
void
cod
ec_
init
();
37 38/*
39S
tart
sth
eco
de
cto
pro
du
cein
terr
up
ts
40*/
41vo
idco
de
c_st
art
();
42 43/*
44W
rite
sva
lue
toth
ein
pu
to
fth
eD
AC
.U
nlik
e45
the
AD
53
5_
wri
teA
PI,
itd
oe
sn
ot
use
po
llin
gto
est
ab
lish
46th
at
the
McB
SP
isre
ad
yto
write
an
oth
er
sam
ple
.R
ath
er,
it47
req
uire
sth
eM
cBS
Pto
alre
ad
yb
ere
ad
y.In
oth
er
wo
rds,
48th
eA
D5
35
_w
rite
Hw
iis
for
use
with
ina
nIn
terr
up
tS
erv
ice
49R
ou
tine
.T
he
face
tha
tyo
ua
rriv
ed
at
an
McB
SP
tra
nsm
itIS
R50
sig
nifi
es
tha
tth
eM
cBS
Pis
rea
dy
with
an
oth
er
sam
ple
.51 52
Pa
ram
ete
rs:
53h
an
dle
ha
nd
leto
cod
ec
cha
nn
el
54o
ut_
da
tava
lue
tob
ew
ritte
nto
DA
C.
55*/
56vo
idA
D5
35
_H
WI_
write
(A
D5
35
_H
an
dle
ha
nd
le,
sho
rto
ut_
da
ta);
57 58/*
59S
ets
1to
the
FR
EE
field
of
the
SP
CR
reg
iste
ro
fth
e60
giv
en
McB
SP
po
rt.
Wh
en
FR
EE
isse
tto
1,
the
seria
l61
clo
cks
con
tinu
eto
run
du
rin
ga
ne
mu
latio
nh
alt.
62 63P
ara
me
ters
:64
po
rtM
cBS
Pp
ort
(0
or
1)
65*/
66vo
idM
CB
SP
_se
tfre
e(
int
po
rt);
67 68 69#
en
dif
/*_
DA
C_
CO
DE
C_
*/70 71
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_72
EN
DO
FT
HE
FIL
E73
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.4:
dac_
code
c.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2D
IGIT
AL
AN
AL
OG
CO
NV
ER
TE
RO
NB
OA
RD
CO
DE
C-
VE
RS
ION
13 4
file
:d
ac_
cod
ec.
c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14 15#
incl
ud
e"d
ac_
cod
ec.
h"
16 17 18/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--19
glo
ba
lva
rib
les
20--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/21
AD
53
5_
Ha
nd
leo
utA
D5
35
h;
22 23/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--24
imp
lem
en
tatio
no
ffu
nct
ion
s25
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
26 27vo
idco
de
c_in
it()
28{
29A
D5
35
_C
on
figo
utA
D5
35
c=
{30
AD
53
5_
LO
OP
BA
CK
_D
ISA
BL
E,/*L
oo
pb
ack
mo
de
*/31
AD
53
5_
MIC
GA
IN_
OF
F,/*
Mic
rop
ho
ne
ga
in*/
32A
D5
35
_G
AIN
_0
DB,
/*A
DC
inp
ut
ga
in*/
33A
D5
35
_G
AIN
_0
DB
/*D
AC
ou
tpu
tg
ain
*/34
};35 36
ou
tAD
53
5h
=A
D5
35
_o
pe
n(
AD
53
5_
loca
lId);
/*o
pe
nth
eA
D5
35
for
cod
ec
use
*/37
AD
53
5_
rese
t(
ou
tAD
53
5h
);/*
rese
tit
*/38
AD
53
5_
con
fig(
ou
tAD
53
5h
,&o
utA
D5
35
c);
/*se
tup
acc
ord
ing
too
utA
D5
35
c*/
39M
CB
SP
_se
tfre
e(
MC
BS
P_
DE
V0);
40 41IR
Q_
ma
p(IR
Q_
EV
T_
XIN
T0
,9);
/*m
ap
the
cod
ec
inte
rru
pt
toth
ed
sp*/
42IR
Q_
en
ab
le(
IRQ
_E
VT
_X
INT
0);
/*e
na
ble
the
cod
ec
inte
rru
pt
*/
118
F.1. C Listings
43}
44 45vo
idco
de
c_st
art
()46
{47
AD
53
5_
write
(o
utA
D5
35
h,0
);/*
cod
ec
sta
rts
toa
fte
rth
efis
rtva
lue
is48
writte
nto
it*/
49}
50 51vo
idA
D5
35
_H
WI_
write
(A
D5
35
_H
an
dle
ha
nd
le,
sho
rto
ut_
da
ta)
52{
53M
CB
SP
_H
an
dle
h;54
h=
AD
53
5_
ge
tMcb
spH
an
dle
(h
an
dle
);55
ou
t_d
ata
&=
0xF
FF
E;
56M
CB
SP
_w
rite
(h
,(in
t)
ou
t_d
ata
);57
}58 59
void
MC
BS
P_
setfre
e(
int
po
rt)
60{
61sw
itch
(p
ort
)62
{63
case
0:
64M
CB
SP
_F
SE
T(S
PC
R0,
FR
EE,
1);
65 66b
rea
k;
67ca
se1
:68
MC
BS
P_
FS
ET(S
PC
R0,
FR
EE,
1);
69b
rea
k;
70}
71}
72 73/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
74E
ND
OF
TH
EF
ILE
75_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
F.1.
2.Fl
oati
ng-P
oint
glob
al_s
etti
ngs Li
stin
gF.
5:Fl
oatin
g-Po
int:
:glo
bal_
sett
ings
.h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
GL
OB
AL
SE
TT
ING
S-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:g
lob
al_
settin
gs.
h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#d
efin
eB
UF
FE
RS
IZE
12
812
#d
efin
eD
OW
NS
AM
PL
E_
ON
E413
#d
efin
eD
OW
NS
AM
PL
E_
TW
O214 15
#d
efin
eB
UF
FE
RS
IZE
_IN
PU
T(
BU
FF
ER
SIZ
E)16
#d
efin
eB
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR(
BU
FF
ER
SIZ
E/D
OW
NS
AM
PL
E_
ON
E)
17#
de
fine
BU
FF
ER
SIZ
E_
OU
TP
UT
(B
UF
FE
RS
IZE/
(D
OW
NS
AM
PL
E_
ON
E*
DO
WN
SA
MP
LE
_T
WO
))18 19
#d
efin
eP
I3
.14
15
92
65
35
9
fm_d
em_m
ain
List
ing
F.6:
Floa
ting-
Poin
t::f
m_d
em_m
ain.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
FM
DE
MO
DU
LA
TIO
NM
AIN
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
fm_
de
m_
ma
in.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
de
mo
du
lato
rd
efin
e13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
de
fine
FM
_M
IXE
D_
DE
M1
015
#d
efin
eF
M_
PL
L_
DE
M2
016 17
#d
efin
eF
M_
DE
MO
DU
LA
TO
RF
M_
MIX
ED
_D
EM
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
incl
ud
es
21--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/22 23
#in
clu
de
<st
d.
h>
24#
incl
ud
e<
swi
.h
>25
#in
clu
de
<cs
l.
h>
26#
incl
ud
e<
bsl
.h
>27 28
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
29#
incl
ud
e"a
dc_
TH
S1
40
8.h
"30
#in
clu
de
"da
c_co
de
c.h
"31
#in
clu
de
"qu
ad
_m
ix.h
"32
#in
clu
de
"do
wn
sam
ple
_o
ne
.h"
33#
if(
FM
_D
EM
OD
UL
AT
OR
==
FM
_P
LL
_D
EM)
34#
incl
ud
e"p
ll_d
em
od
ula
te.h
"35
#e
lif(
FM
_D
EM
OD
UL
AT
OR
==
FM
_M
IXE
D_
DE
M)36
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"37
#e
lse
38#
err
or
No
de
mo
du
lato
ra
lgo
rith
md
efin
ed
39#
en
dif
40#
incl
ud
e"o
ut_
filte
r.h
"41
#in
clu
de
"do
wn
sam
ple
_tw
o.h
"42 43
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
44d
eb
ug
de
fine
s45
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
46#
de
fine
FM
_D
EM
_C
F_
DE
BU
G0
47/*
top
rin
tco
mm
en
tsto
de
bu
g_
log
*/48 49
#d
efin
eF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D0
50/*
Le
dto
gg
les
wh
en
an
inte
rru
pt
occ
urs
*/51
/*L
ED
1co
de
cin
terr
up
t(o
utp
ut)
*/52
/*L
ED
2e
dm
ain
terr
up
t(in
pu
t)*/
53/*
LE
D3
timm
ing
err
or
*/54 55
#d
efin
eF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D0
56/*
Le
dO
Nb
yin
terr
up
tst
art
OF
Fa
tth
ee
nd
*/57
/*L
ED
1co
de
cin
terr
up
t(o
utp
ut)
*/58
/*L
ED
2e
dm
ain
terr
up
t(in
pu
t)*/
59/*
LE
D3
soft
wa
rein
terr
up
t*/
60 61#
de
fine
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
062
/*E
na
ble
ST
SO
bje
cts:
*/63
/*-d
ac_
sts
*/64
/*-d
em
od
ula
te_
sts
*/65
/*-e
dm
a_
sts
*/66
/*to
me
asu
reth
ed
ura
tion
time
of
the
inte
rru
pts
*/67 68
#d
efin
eF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S1
69/*
En
ab
leS
TS
Ob
ject
s:*/
70/*
-mix
_st
s*/
71/*
-de
m_
sts
*/72
/*-f
ilte
r_st
s*/
73/*
tom
ea
sure
the
du
ratio
ntim
eo
fth
efu
nct
ion
s*/
74 75#
ifF
M_
DE
M_
CF
_D
EB
UG
76#
incl
ud
e<
log
.h
>77
ext
ern
far
LO
G_
Ob
jd
eb
ug
_lo
g;
78#
en
dif
79 80#
ifF
FM
_D
EM
_C
F_
INT
_O
CC
UR
_L
ED
81#
incl
ud
e<
bsl
_le
d.
h>
82#
en
dif
83 84#
ifF
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
119
Listings85
#in
clu
de
<b
sl_
led
.h
>86
#e
nd
if87 88
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
89#
incl
ud
e<
clk
.h
>90
#in
clu
de
<st
s.
h>
91e
xte
rnfa
rS
TS
_O
bj
da
c_st
s;
92e
xte
rnfa
rS
TS
_O
bj
de
mo
du
late
_st
s;
93e
xte
rnfa
rS
TS
_O
bj
ed
ma
_st
s;
94#
en
dif
95 96#
ifF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S97
#in
clu
de
<cl
k.
h>
98#
incl
ud
e<
sts
.h
>99
ext
ern
far
ST
S_
Ob
jm
ix_
sts
;10
0e
xte
rnfa
rS
TS
_O
bj
de
m_
sts
;10
1e
xte
rnfa
rS
TS
_O
bj
filte
r_st
s;
102
ext
ern
far
ST
S_
Ob
jd
ow
n_
on
e_
sts
;10
3e
xte
rnfa
rS
TS
_O
bj
do
wn
_tw
o_
sts
;10
4#
en
dif
105
106
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
107
DS
P/B
IOS
ext
ern
varib
les
108
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
109
110
ext
ern
far
SW
I_O
bj
de
mo
du
late
_sw
i;
111
ext
ern
HW
I_e
na
ble
();
112
ext
ern
HW
I_d
isa
ble
();
113
114
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
115
glo
ba
lva
rib
les
116
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
117
118
sho
rtin
_b
uffe
r_A
[B
UF
FE
RS
IZE
_IN
PU
T];
119
sho
rtin
_b
uffe
r_B
[B
UF
FE
RS
IZE
_IN
PU
T];
120
121
floa
tin
_b
uffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;12
212
3flo
at
re_
bu
ffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;12
4flo
at
im_
bu
ffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;12
512
6flo
at
re_
bu
ffe
r_d
ow
n_
on
e[
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R];
127
floa
tim
_b
uffe
r_d
ow
n_
on
e[
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R];
128
129
floa
to
ut_
bu
ffe
r_d
ow
n_
on
e[
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R];
130
floa
to
ut_
bu
ffe
r_d
ow
n_
two
[B
UF
FE
RS
IZE
_O
UT
PU
T];13
113
2sh
ort
ou
t_b
uffe
r_A
[B
UF
FE
RS
IZE
_O
UT
PU
T];13
3sh
ort
ou
t_b
uffe
r_B
[B
UF
FE
RS
IZE
_O
UT
PU
T];13
413
513
613
7sh
ort
*in
_b
uffe
r_p
tr;
138
sho
rt*
ou
t_b
uffe
r_p
tr;
139
Bo
ol
a_
inE
DM
A=
TR
UE;
140
sho
rto
utc
ou
nte
r=
0;
141
142
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
143
the
ma
infu
nct
ion
144
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
145
void
ma
in()
146
{14
7H
WI_
dis
ab
le()
;14
814
9#
ifF
M_
DE
M_
CF
_D
EB
UG
150
LO
G_
prin
tf(&
de
bu
g_
log
,"In
fo:
Be
gin
Of
ma
in")
;15
1#
en
dif
152
153
CS
L_
init
();
/*o
nch
ipin
it*/
154
BS
L_
init
();
/*o
nb
oa
rdin
it*/
155
156
ths1
40
8_
init
(in
_b
uffe
r_A
,in
_b
uffe
r_B
);15
7co
de
c_in
it()
;15
815
9H
WI_
en
ab
le()
;16
016
1th
s14
08
_st
art
();
162
cod
ec_
sta
rt()
;16
316
4#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D
165
LE
D_
off
(L
ED
_A
LL)
;16
6#
en
dif
167
168
#if
FM
_D
EM
_C
F_
DE
BU
G16
9L
OG
_p
rin
tf(&
de
bu
g_
log
,"In
fo:
En
dO
fm
ain
");
170
#e
nd
if17
1}
172
173
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
174
ha
rdw
are
inte
rru
pt
fun
ctio
ns
175
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
176
177
void
ed
ma
Int
(vo
id)
178
{17
9#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D18
0L
ED
_to
gg
le(
LE
D_
2);
181
#e
nd
if18
218
3#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D18
4L
ED
_o
n(
LE
D_
2);
185
#e
nd
if18
618
7#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S18
8S
TS
_se
t(&
ed
ma
_st
s,
CL
K_
ge
thtim
e()
);18
9#
en
dif
190
191
/*re
set
ou
tco
un
ter
*/19
2o
utc
ou
nte
r=
0;
193
194
/*se
lect
ED
MA
cha
nn
el
*/19
5if
(E
DM
A_
intT
est
(T
HS
14
08
_B
UF
FE
R_
A_
TC
C))19
6{
197
#if
FM
_D
EM
_C
F_
DE
BU
G19
8L
OG
_p
rin
tf(&
de
bu
g_
log
,"In
_A
");
199
#e
nd
if20
0/*
Cle
ar
tra
nsf
er
com
ple
tion
inte
rru
pt
flag
*/20
1E
DM
A_
intC
lea
r(
TH
S1
40
8_
BU
FF
ER
_A
_T
CC);
202
203
/*se
tb
uffe
rp
oin
ters
*/20
4a
_in
ED
MA
=F
AL
SE;
205
in_
bu
ffe
r_p
tr=
in_
bu
ffe
r_A
;20
6o
ut_
bu
ffe
r_p
tr=
ou
t_b
uffe
r_A
;20
720
8/*
po
stso
ftw
are
inte
rru
pt
->st
art
de
mo
du
latio
n*/
209
SW
I_p
ost
(&d
em
od
ula
te_
swi
);21
0}
211
if(
ED
MA
_in
tTe
st(
TH
S1
40
8_
BU
FF
ER
_B
_T
CC))
212
{21
3#
ifF
M_
DE
M_
CF
_D
EB
UG
214
LO
G_
prin
tf(&
de
bu
g_
log
,"In
_B
");
215
#e
nd
if21
6/*
Cle
ar
tra
nsf
er
com
ple
tion
inte
rru
pt
flag
*/21
7E
DM
A_
intC
lea
r(
TH
S1
40
8_
BU
FF
ER
_B
_T
CC);
218
219
/*se
tb
uffe
rp
oin
ters
*/22
0a
_in
ED
MA
=T
RU
E;22
1in
_b
uffe
r_p
tr=
in_
bu
ffe
r_B
;22
2o
ut_
bu
ffe
r_p
tr=
ou
t_b
uffe
r_B
;22
322
4/*
po
stso
ftw
are
inte
rru
pt
->st
art
de
mo
du
latio
n*/
225
SW
I_p
ost
(&d
em
od
ula
te_
swi
);22
6}
227
228
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
229
ST
S_
de
lta(&
ed
ma
_st
s,
CL
K_
ge
thtim
e()
);23
0#
en
dif
231
232
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
233
LE
D_
off
(L
ED
_2)
;23
4#
en
dif
235
}23
623
7vo
idd
acI
nt
(vo
id)
238
{23
9#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D24
0L
ED
_to
gg
le(
LE
D_
1);
241
#e
nd
if24
224
3#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D24
4L
ED
_o
n(
LE
D_
1);
120
F.1. C Listings
245
#e
nd
if24
624
7#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S24
8S
TS
_se
t(&
da
c_st
s,
CL
K_
ge
thtim
e()
);24
9#
en
dif
250
251
/*in
terp
ola
tea
mis
sin
gsa
mp
le*/
252
if(
ou
tco
un
ter
>1
5)
253
{25
4#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D25
5L
ED
_to
gg
le(
LE
D_
3);
256
#e
nd
if25
7/*
sele
ctth
eb
uffe
r*/
258
if(
a_
inE
DM
A)
259
{26
0A
D5
35
_H
WI_
write
(o
utA
D5
35
h,(
(o
ut_
bu
ffe
r_A
[15
]+o
ut_
bu
ffe
r_B
[0])
/2))
;26
1#
ifF
M_
DE
M_
CF
_D
EB
UG
262
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
Ae
rro
r:%
d",
ou
tco
un
ter
);26
3#
en
dif
264
}e
lse
265
{26
6A
D5
35
_H
WI_
write
(o
utA
D5
35
h,(
(o
ut_
bu
ffe
r_B
[15
]+o
ut_
bu
ffe
r_A
[0])
/2))
;26
7#
ifF
M_
DE
M_
CF
_D
EB
UG
268
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
Be
rro
r:%
d",
ou
tco
un
ter
);26
9#
en
dif
270
}27
1}
els
e/*
ou
tpu
ta
valu
e*/
272
{27
3/*
sele
ctth
eb
uffe
r*/
274
if(
a_
inE
DM
A)
275
{27
6A
D5
35
_H
WI_
write
(o
utA
D5
35
h,
ou
t_b
uffe
r_A
[o
utc
ou
nte
r])
;27
7#
ifF
M_
DE
M_
CF
_D
EB
UG
278
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
A:%
d",
ou
tco
un
ter
);27
9#
en
dif
280
}e
lse
281
{28
2A
D5
35
_H
WI_
write
(o
utA
D5
35
h,
ou
t_b
uffe
r_B
[o
utc
ou
nte
r])
;28
3#
ifF
M_
DE
M_
CF
_D
EB
UG
284
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
B:%
d",
ou
tco
un
ter
);28
5#
en
dif
286
}28
7/*
up
da
teo
utc
ou
nte
r*/
288
ou
tco
un
ter
++
;28
9}
290
291
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
292
ST
S_
de
lta(&
da
c_st
s,
CL
K_
ge
thtim
e()
);29
3#
en
dif
294
295
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
296
LE
D_
off
(L
ED
_1)
;29
7#
en
dif
298
}29
930
0/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--30
1so
ftw
are
inte
rru
pt
fun
ctio
ns
302
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
303
304
void
de
mo
du
late
Sw
iFu
nc
(vo
id)
305
{30
6in
ti
;30
730
8#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D30
9L
ED
_o
n(
LE
D_
3);
310
#e
nd
if31
131
2#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S31
3S
TS
_se
t(&
de
mo
du
late
_st
s,
CL
K_
ge
thtim
e()
);31
4#
en
dif
315
316
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)31
7{
318
in_
bu
ffe
r_p
tr[
i]=
in_
bu
ffe
r_p
tr[
i]<
<2
;31
9}
320
321
/*co
nve
rtsh
ort
toflo
at*
/32
2fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
INP
UT;
i+
+)
323
{32
4in
_b
uffe
r[
i]=
((flo
at
)in
_b
uffe
r_p
tr[
i])
/32
76
7;
325
}32
632
7#
ifF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S32
8S
TS
_se
t(&
mix
_st
s,
CL
K_
ge
thtim
e()
);32
9#
en
dif
330
qu
ad
_m
ix(
in_
bu
ffe
r,
re_
bu
ffe
r,
im_
bu
ffe
r);
331
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
332
ST
S_
de
lta(&
mix
_st
s,
CL
K_
ge
thtim
e()
);33
3#
en
dif
334
335
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
336
ST
S_
set
(&d
ow
n_
on
e_
sts
,C
LK
_g
eth
time
());
337
#e
nd
if33
8d
ow
nsa
mp
le_
on
e(
re_
bu
ffe
r,
im_
bu
ffe
r,
re_
bu
ffe
r_d
ow
n_
on
e,
im_
bu
ffe
r_d
ow
n_
on
e);
339
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
340
ST
S_
de
lta(&
do
wn
_o
ne
_st
s,
CL
K_
ge
thtim
e()
);34
1#
en
dif
342
343
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
344
ST
S_
set
(&d
em
_st
s,
CL
K_
ge
thtim
e()
);34
5#
en
dif
346
#if
(F
M_
DE
MO
DU
LA
TO
R=
=F
M_
PL
L_
DE
M)34
7p
ll_d
em
od
ula
te(
re_
bu
ffe
r_d
ow
n_
on
e,
im_
bu
ffe
r_d
ow
n_
on
e,
ou
t_b
uffe
r_d
ow
n_
on
e);
348
#e
lif(
FM
_D
EM
OD
UL
AT
OR
==
FM
_M
IXE
D_
DE
M)34
9m
ixe
d_
de
mo
du
late
(re
_b
uffe
r_d
ow
n_
on
e,
im_
bu
ffe
r_d
ow
n_
on
e,
ou
t_b
uffe
r_d
ow
n_
on
e);
350
#e
lse
351
#e
rro
rN
od
em
od
ula
tor
alg
orith
md
efin
ed
352
#e
nd
if35
3#
ifF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S35
4S
TS
_d
elta
(&d
em
_st
s,
CL
K_
ge
thtim
e()
);35
5#
en
dif
356
357
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
358
ST
S_
set
(&fil
ter_
sts
,C
LK
_g
eth
time
());
359
#e
nd
if36
0o
ut_
filte
r(
ou
t_b
uffe
r_d
ow
n_
on
e);
361
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
362
ST
S_
de
lta(&
filte
r_st
s,
CL
K_
ge
thtim
e()
);36
3#
en
dif
364
365
366
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
367
ST
S_
set
(&d
ow
n_
two
_st
s,
CL
K_
ge
thtim
e()
);36
8#
en
dif
369
do
wn
sam
ple
_tw
o(
ou
t_b
uffe
r_d
ow
n_
on
e,
ou
t_b
uffe
r_d
ow
n_
two
);37
0#
ifF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S37
1S
TS
_d
elta
(&d
ow
n_
two
_st
s,
CL
K_
ge
thtim
e()
);37
2#
en
dif
373
374
/*co
vert
fro
mflo
at
tosh
ort
*/37
5fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
OU
TP
UT;i
++
)37
6{
377
ou
t_b
uffe
r_p
tr[
i]=
ou
t_b
uffe
r_d
ow
n_
two
[i
]*3
27
67
;37
8}
379
380
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
381
ST
S_
de
lta(&
de
mo
du
late
_st
s,
CL
K_
ge
thtim
e()
);38
2#
en
dif
383
384
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
385
LE
D_
off
(L
ED
_3)
;38
6#
en
dif
387
}
quad
_mix
List
ing
F.7:
Floa
ting-
Poin
t::q
uad_
mix
.h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
QU
AD
RA
TU
RE
MIX
ER
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
qu
ad
_m
ix.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
121
Listings9
*/10 11
#ifn
de
f_
QU
AD
_M
IX_
12#
de
fine
_Q
UA
D_
MIX
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23T
he
in_
bu
ffe
ris
qu
ad
ratu
rem
ixe
dto
the
two
24b
uffe
rsre
_b
uffe
ra
nd
im_
bu
ffe
r.25 26
Pa
ram
ete
rs:
27 28in
_b
uffe
rb
uffe
ro
fin
pu
tsi
gn
al
29re
_b
uffe
rb
uffe
ro
fI
sig
na
l30
im_
bu
ffe
rb
uffe
ro
fQ
sig
na
l31
*/32
void
qu
ad
_m
ix(
floa
tin
_b
uffe
r[]
,flo
at
re_
bu
ffe
r[]
,flo
at
im_
bu
ffe
r[]);
33 34#
en
dif
/*_
QU
AD
_M
IX_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.8:
Floa
ting-
Poin
t::q
uad_
mix
.c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
QU
AD
RA
TU
RE
MIX
ER
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
qu
ad
_m
ix.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"qu
ad
_m
ix.h
"15 16 17
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
18g
lob
al
varib
les
19--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/20
/*co
effic
ien
tso
fiir
filte
rfo
rco
sin
e/s
ine
ge
ne
ratio
n*/
21 22flo
at
bc2
=-0
.27
69
79
26
50
5;/*c
osi
ne
*/23
floa
tb
s2=
0.9
60
87
58
95
59
3;/*s
ine
*/24
floa
ta
sc2
=-0
.55
39
58
53
01
;/*s
ine
/co
sin
e*/
25 26/*
de
lay
varia
be
lso
fiir
filte
rfo
rco
sin
e/s
ine
ge
ne
ratio
n*/
27 28flo
at
zsc1
=0
.0;
29flo
at
zsc2
=0
.0;
30flo
at
zsc3
=1
.0;/*f
or
first
valu
eo
fd
elta
fun
ctio
n*/
31 32/*
coe
ffic
ien
tso
fiir
filte
rfo
rlo
wp
ass
filte
rin
g*/
33 34flo
at
blp
1=
0.0
01
5;
35flo
at
blp
2=
0.0
07
6;
36flo
at
blp
3=
0.0
15
1;
37flo
at
blp
4=
0.0
15
1;
38flo
at
blp
5=
0.0
07
6;
39flo
at
blp
6=
0.0
01
5;
40flo
at
alp
2=
-2.8
95
7;
41flo
at
alp
3=
3.6
34
4;
42flo
at
alp
4=
-2.3
92
8;
43flo
at
alp
5=
0.8
17
6;
44flo
at
alp
6=
-0.1
15
1;
45 46/*
de
lay
varia
be
lso
fiir
filte
rfo
rlo
wp
ass
filte
rin
gth
eI-
pa
th*/
47 48flo
at
zlp
c1=
0.0
;49
floa
tzl
pc2
=0
.0;
50flo
at
zlp
c3=
0.0
;51
floa
tzl
pc4
=0
.0;
52flo
at
zlp
c5=
0.0
;53
floa
tzl
pc6
=0
.0;
54 55/*
de
lay
varia
be
lso
fiir
filte
rfo
rlo
wp
ass
filte
rin
gth
eQ
-pa
th*/
56 57flo
at
zlp
s1=
0.0
;58
floa
tzl
ps2
=0
.0;
59flo
at
zlp
s3=
0.0
;60
floa
tzl
ps4
=0
.0;
61flo
at
zlp
s5=
0.0
;62
floa
tzl
ps6
=0
.0;
63 64/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--65
imp
lem
en
tatio
no
ffu
nct
ion
66--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/67
void
qu
ad
_m
ix(
floa
tin
_b
uffe
r[]
,flo
at
re_
bu
ffe
r[]
,flo
at
im_
bu
ffe
r[])
68{
69in
ti
;70 71
/*_
_co
sin
e/s
ine
ge
ne
ratio
n_
_*/
72 73fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
INP
UT;
i+
+)
74{
75/*
fee
db
ack
*/76
zsc1
=-(
zsc2
*a
sc2
+zs
c3);
77 78/*
fore
wa
rd*/
79re
_b
uffe
r[
i]=
zsc1
+zs
c2*
bc2
;/*c
osi
ne
*/80
im_
bu
ffe
r[
i]=
zsc2
*b
s2;/*s
ine
*/81 82
/*sh
iftd
ela
ys*/
83zs
c3=
zsc2
;84
zsc2
=zs
c1;
85}
86 87/*
__
mix
ing
__
*/88 89
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)90
{91
/*m
ixin
g*/
92re
_b
uffe
r[
i]=
re_
bu
ffe
r[
i]*
in_
bu
ffe
r[
i];/*
I-p
ath
*/93
im_
bu
ffe
r[
i]=
im_
bu
ffe
r[
i]*
in_
bu
ffe
r[
i];/*
Q-p
ath
*/94
}95 96
/*_
_lo
wp
ass
__
*/97 98
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)99
{10
0/*
fee
db
ack
*/10
1zl
pc1
=re
_b
uffe
r[
i]-
(a
lp2
*zl
pc2
+a
lp3
*zl
pc3
+a
lp4
*zl
pc4
+a
lp5
*zl
pc5
+a
lp6
*zl
pc6
);/*
I-p
ath
*/10
2zl
ps1
=im
_b
uffe
r[
i]-
(a
lp2
*zl
ps2
+a
lp3
*zl
ps3
+a
lp4
*zl
ps4
+a
lp5
*zl
ps5
+a
lp6
*zl
ps6
);/*
Q-p
ath
*/10
310
4/*
fore
wa
rd*/
105
re_
bu
ffe
r[
i]=
blp
1*
zlp
c1+
blp
2*
zlp
c2+
blp
3*
zlp
c3+
blp
4*
zlp
c4+
blp
5*
zlp
c5+
blp
6*
zlp
c6;/*I
-pa
th*/
106
im_
bu
ffe
r[
i]=
-(b
lp1
*zl
ps1
+b
lp2
*zl
ps2
+b
lp3
*zl
ps3
+b
lp4
*zl
ps4
+b
lp5
*zl
ps5
+b
lp6
*zl
ps6
);/*
Q-p
ath
*/10
710
8/*
shift
de
lays
*/10
9/*
I-p
ath
*/11
0zl
pc6
=zl
pc5
;11
1zl
pc5
=zl
pc4
;11
2zl
pc4
=zl
pc3
;11
3zl
pc3
=zl
pc2
;11
4zl
pc2
=zl
pc1
;11
5/*
Q-p
ath
*/11
6zl
ps6
=zl
ps5
;11
7zl
ps5
=zl
ps4
;11
8zl
ps4
=zl
ps3
;11
9zl
ps3
=zl
ps2
;12
0zl
ps2
=zl
ps1
;12
1}
122
}
122
F.1. C Listings
123
124
125
126
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_12
7E
ND
OF
TH
EF
ILE
128
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
dow
nsam
ple_
one
List
ing
F.9:
Floa
ting-
Poin
t::d
owns
ampl
e_on
e.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2D
OW
NS
AM
PL
EO
NE
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
do
wn
sam
ple
_o
ne
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
DO
WN
SA
MP
LE
_O
NE
_12
#d
efin
e_
DO
WN
SA
MP
LE
_O
NE
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23T
he
re_
bu
ffe
ra
nd
im_
bu
ffe
ra
red
ow
nsa
mp
led
24to
the
re_
bu
ffe
r_d
ow
n_
on
ea
nd
im_
bu
ffe
r_d
ow
n_
on
e.
25 26P
ara
me
ter
:27 28
re_
bu
ffe
rb
uffe
ro
fI
sig
na
l29
re_
bu
ffe
rb
uffe
ro
fQ
sig
na
l30
re_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Isi
gn
al
31im
_b
uffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Qsi
gn
al
32 33*/
34vo
idd
ow
nsa
mp
le_
on
e(
floa
tre
_b
uffe
r[]
,flo
at
im_
bu
ffe
r[]
,flo
at
re_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]);
35 36#
en
dif
/*_
DO
WN
SA
MP
LE
_O
NE
_*/
37 38/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
39E
ND
OF
TH
EF
ILE
40_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.10
:Flo
atin
g-Po
int:
:dow
nsam
ple_
one.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
DO
WN
SA
MP
LE
ON
E-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:d
ow
nsa
mle
_o
ne
.c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
incl
ud
e"d
ow
nsa
mp
le_
on
e.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17im
ple
me
nta
tion
of
fun
ctio
n18
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
19vo
idd
ow
nsa
mp
le_
on
e(
floa
tre
_b
uffe
r[]
,flo
at
im_
bu
ffe
r[]
,flo
at
re_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[])
20{
21in
ti
;22 23
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)24
{25
re_
bu
ffe
r_d
ow
n_
on
e[
i]=
re_
bu
ffe
r[
i*
DO
WN
SA
MP
LE
_O
NE
];26
im_
bu
ffe
r_d
ow
n_
on
e[
i]=
im_
bu
ffe
r[
i*
DO
WN
SA
MP
LE
_O
NE
];27
}28
}29 30
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_31
EN
DO
FT
HE
FIL
E32
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
mix
ed_d
emod
ulat
e
List
ing
F.11
:Flo
atin
g-Po
int:
:mix
ed_d
emod
ulat
e.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2M
IXE
DD
EM
OD
UL
AT
E-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:m
ixe
d_
de
mo
du
late
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
MIX
ED
_D
EM
OD
UL
AT
E_
12#
de
fine
_M
IXE
D_
DE
MO
DU
LA
TE
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18#
incl
ud
e<
ma
th.
h>
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24T
he
re_
bu
ffe
r_d
ow
n_
on
ea
nd
im_
bu
ffe
r_d
ow
n_
on
ea
red
em
od
ula
ted
25w
ithth
em
ixe
dd
em
od
ula
tor
alg
orith
mto
ou
t_b
uffe
r_d
ow
n_
on
e.
26 27P
ara
me
ters
:28 29
re_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Isi
gn
al
30im
_b
uffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Qsi
gn
al
31o
ut_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
em
od
ula
ted
sig
na
l32
*/33
void
mix
ed
_d
em
od
ula
te(
floa
tre
_b
uffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[]);
34 35#
en
dif
/*_
MIX
ED
_D
EM
OD
UL
AT
E_
*/36 37
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_38
EN
DO
FT
HE
FIL
E39
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.12
:Flo
atin
g-Po
int:
:mix
ed_d
emod
ulat
e.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2M
IXE
DD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
mix
ed
_d
em
od
ula
te.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--
123
Listings12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
/*va
ria
be
lso
fd
em
od
ula
ting
(atte
nsi
on
div
isio
nb
yze
ro!)
*/20 21
floa
tco
old
=0
.0;/*o
ldva
lue
of
I-p
ath
*/22
floa
tco
ne
w=
1.0
;/*n
ew
valu
eo
fI-
pa
th*/
23flo
at
sio
ld=
0.0
;/*o
ldva
lue
of
Q-p
ath
*/24
floa
tsi
ne
w=
1.0
;/*n
ew
valu
eo
fQ
-pa
th*/
25flo
at
de
mo=
0.0
;/*v
alu
ed
em
od
ula
ting
*/26 27
/*co
nst
an
to
fd
em
od
ula
ting
*/28 29
floa
td
eco
n=
0.7
;30 31 32
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
33im
ple
me
nta
tion
of
fun
ctio
n34
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
35vo
idm
ixe
d_
de
mo
du
late
(flo
at
re_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[])
36{
37in
ti
;38 39
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)40
{41
/*_
_sh
iftin
gva
lue
s__
*/42
coo
ld=
con
ew
;43
sio
ld=
sin
ew
;44
con
ew
=re
_b
uffe
r_d
ow
n_
on
e[
i];
45si
ne
w=
im_
bu
ffe
r_d
ow
n_
on
e[
i];
46 47/*
__
calc
ula
ting
de
mo
du
late
dva
lue
__
*/48
de
mo=
(co
old
*si
ne
w-
sio
ld*
con
ew
)/(
coo
ld*
con
ew
+si
old
*si
ne
w);
/*a
tan
arg
um
en
t*/
49d
em
o=a
tan
f(
de
mo)
;/*a
tan
valu
e*/
50d
em
o=d
em
o*d
eco
n;/*d
em
od
ula
ted
valu
e*/
51o
ut_
bu
ffe
r_d
ow
n_
on
e[
i]=
de
mo;
52}
53}
54 55 56/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
57E
ND
OF
TH
EF
ILE
58_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
pll_
dem
odul
ate List
ing
F.13
:Flo
atin
g-Po
int:
:pll_
dem
odul
ate.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
PL
LD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
pll_
de
mo
du
late
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
PL
L_
DE
MO
DU
LA
TE
_12
#d
efin
e_
PL
L_
DE
MO
DU
LA
TE
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
sett
ing
s.h
"18
#in
clu
de
<m
ath
.h
>19 20
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
21g
lob
al
fun
ctio
ns
22--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/
23/*
24T
he
re_
bu
ffe
r_d
ow
n_
on
ea
nd
im_
bu
ffe
r_d
ow
n_
on
ea
red
em
od
ula
ted
25w
ithth
ep
lla
lgo
rith
mto
the
ou
t_b
uffe
r_d
ow
n_
on
e.
26 27P
ara
me
ters
:28 29
re_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Isi
gn
al
30im
_b
uffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Qsi
gn
al
31o
ut_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
em
od
ula
ted
sig
na
l32
*/33
void
pll_
de
mo
du
late
(flo
at
re_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[]);
34 35#
en
dif
/*_
PL
L_
DE
MO
DU
LA
TE
_*/
36 37 38/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
39E
ND
OF
TH
EF
ILE
40_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.14
:Flo
atin
g-Po
int:
:pll_
dem
odul
ate.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
PL
LD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.0
3 4fil
e:
pll_
de
mo
du
late
.c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
incl
ud
e"p
ll_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
/*co
nst
an
tsfo
rd
em
od
ula
te*/
20 21flo
at
P_
PL
L=
2.0
;22
floa
tK
_P
LL=
2.5
;23
floa
tG
AIN
_P
LL
=1
.5;
24 25/*
varia
ble
sfo
rd
em
od
ula
te*/
26 27flo
at
arg
=0
.0;
/*a
rgu
me
nt
of
sin
ea
nd
cosi
ne
*/28
floa
ti_
pa
th=
0.0
;/*
Ip
ath
*/29
floa
tq
_p
ath
=0
.0;
/*Q
pa
th*/
30 31/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--32
imp
lem
en
tatio
no
ffu
nct
ion
33--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/34
void
pll_
de
mo
du
late
(flo
at
re_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[])
35{
36in
ti
;37 38
floa
td
em
o;/*
valu
eo
fd
em
od
ula
tion
*/39 40
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)41
{42
/*_
_ca
lcu
latio
no
fd
em
od
ula
tion
__
*/43
i_p
ath
=re
_b
uffe
r_d
ow
n_
on
e[
i]*
sin
f(
arg
);44
q_
pa
th=
im_
bu
ffe
r_d
ow
n_
on
e[
i]*
cosf
(a
rg);
45 46d
em
o=q
_p
ath
-i_
pa
th;
47d
em
o=d
em
o*P
_P
LL;
48 49o
ut_
bu
ffe
r_d
ow
n_
on
e[
i]=
de
mo*
GA
IN_
PL
L;
50 51/*
__
sum
ma
tion
of
arg
um
en
t__
*/52
arg
=a
rg+
K_
PL
L*
de
mo;
53 54/*
__
limita
tion
of
arg
um
en
t__
*/55
if(
arg
>2
*P
I)
56{
124
F.1. C Listings
57a
rg=
arg
-2*
PI;
58}
59 60e
lse
if(
arg
<-2
*P
I)
61{
62a
rg=
arg
+2
*P
I;
63}
64}
65}
66 67 68/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
69E
ND
OF
TH
EF
ILE
70_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
out_
filte
r
List
ing
F.15
:Flo
atin
g-Po
int:
:out
_filte
r.h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
OU
TP
UT
FIL
TE
R-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:o
ut_
filte
r.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_O
UT
_F
ILT
ER
_12
#d
efin
e_
OU
T_
FIL
TE
R_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23T
he
ou
t_b
uffe
r_d
ow
n_
on
eis
ba
nd
pa
ssfil
tere
d.
24 25P
ara
me
ters
:26 27
ou
t_b
uffe
r_d
ow
n_
on
eb
uffe
ro
fd
em
od
ula
ted
sig
na
l28 29
*/30
void
ou
t_fil
ter
(flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[]);
31 32#
en
dif
/*_
OU
T_
FIL
TE
R_
*/33 34
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_35
EN
DO
FT
HE
FIL
E36
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.16
:Flo
atin
g-Po
int:
:out
_filte
r.c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
OU
TP
UT
FIL
TE
R-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:o
ut_
filte
r.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"ou
t_fil
ter.
h"
15
16 17/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--18
glo
ba
lva
rib
les
19--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/20 21
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
22co
effic
ien
tso
fo
utp
ut
filte
r(b
an
dp
ass
)a
fte
rd
em
od
ula
tion
23--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/24
/*b
an
dp
ass
ord
er
:1
0*/
25/*
cuto
fffr
eq
ue
ncy
1:
20
0H
z*/
26/*
cuto
fffr
eq
ue
ncy
2:
36
00
Hz
*/27 28
/*co
effic
ien
tso
fiir
filte
rin
gfo
rb
an
dp
ass
filte
rin
g*/
29 30flo
at
ab
p2
=-5
.36
55
39
64
54
90
91
;31
floa
ta
bp
3=
12
.78
39
53
81
80
39
02
;32
floa
ta
bp
4=
-18
.34
33
87
36
25
31
70
;33
floa
ta
bp
5=
18
.18
66
98
91
32
45
87
;34
floa
ta
bp
6=
-13
.24
20
09
59
38
92
55
;35
floa
ta
bp
7=
7.0
52
86
41
37
54
87
3;
36flo
at
ab
p8
=-2
.65
50
01
94
44
49
43
;37
floa
ta
bp
9=
0.6
90
66
23
17
76
40
3;
38flo
at
ab
p1
0=
-0.1
15
83
31
70
16
50
0;
39flo
at
ab
p1
1=
0.0
07
59
59
14
72
84
6;
40flo
at
bb
p1
=0
.02
78
82
06
88
95
08
;41
floa
tb
bp
2=
0.0
;42
floa
tb
bp
3=
-0.1
39
41
03
44
47
53
8;
43flo
at
bb
p4
=0
.0;
44flo
at
bb
p5
=0
.27
88
20
68
89
50
75
;45
floa
tb
bp
6=
0.0
;46
floa
tb
bp
7=
-0.2
78
82
06
88
95
07
5;
47flo
at
bb
p8
=0
.0;
48flo
at
bb
p9
=0
.13
94
10
34
44
75
38
;49
floa
tb
bp
10
=0
.0;
50flo
at
bb
p1
1=
-0.0
27
88
20
68
89
50
8;
51 52/*
de
lay
varia
be
lso
fiir
filte
rin
gfo
rb
an
dp
ass
filte
rin
g*/
53 54flo
at
zbp
1=
0.0
;55
floa
tzb
p2
=0
.0;
56flo
at
zbp
3=
0.0
;57
floa
tzb
p4
=0
.0;
58flo
at
zbp
5=
0.0
;59
floa
tzb
p6
=0
.0;
60flo
at
zbp
7=
0.0
;61
floa
tzb
p8
=0
.0;
62flo
at
zbp
9=
0.0
;63
floa
tzb
p1
0=
0.0
;64
floa
tzb
p1
1=
0.0
;65 66 67
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
68im
ple
me
nta
tion
of
fun
ctio
n69
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
70vo
ido
ut_
filte
r(
floa
to
ut_
bu
ffe
r_d
ow
n_
on
e[])
71{
72in
ti
;73 74
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)75
{76
/*fe
ed
ba
ck*/
77zb
p1
=o
ut_
bu
ffe
r_d
ow
n_
on
e[
i]-
(a
bp
2*
zbp
2+
ab
p3
*zb
p3
+a
bp
4*
zbp
4+
ab
p5
*zb
p5
+a
bp
6*
zbp
6+
ab
p7
*zb
p7
+a
bp
8*
zbp
8+
ab
p9
*zb
p9
+a
bp
10
*zb
p1
0+
ab
p1
1*
zbp
11
);78 79
/*fo
rew
ard
*/80
ou
t_b
uffe
r_d
ow
n_
on
e[
i]=
bb
p1
*zb
p1
+b
bp
2*
zbp
2+
bb
p3
*zb
p3
+b
bp
4*
zbp
4+
bb
p5
*zb
p5
+b
bp
6*
zbp
6+
bb
p7
*zb
p7
+b
bp
8*
zbp
8+
bb
p9
*zb
p9
+b
bp
10
*zb
p1
0+
bb
p1
1*
zbp
11
;81 82
/*sh
iftd
ela
ys*/
83zb
p1
1=
zbp
10
;84
zbp
10
=zb
p9
;85
zbp
9=
zbp
8;
86zb
p8
=zb
p7
;87
zbp
7=
zbp
6;
88zb
p6
=zb
p5
;89
zbp
5=
zbp
4;
90zb
p4
=zb
p3
;91
zbp
3=
zbp
2;
92zb
p2
=zb
p1
;93
}
125
Listings94
}95 96
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_97
EN
DO
FT
HE
FIL
E98
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
dow
nsam
ple_
two
List
ing
F.17
:Flo
atin
g-Po
int:
:dow
nsam
ple_
two.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
DO
WN
SA
MP
LE
TW
O-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:d
ow
nsa
mp
le_
two
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
DO
WN
SA
MP
LE
_T
WO
_12
#d
efin
e_
DO
WN
SA
MP
LE
_T
WO
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23T
he
ou
t_b
uff
er_
do
wn
_o
ne
isd
ow
nsa
mp
led
toth
e24
ou
t_b
uffe
r_d
ow
n_
two
.25 26
Pa
ram
ete
rs:
27 28o
ut_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
em
od
ula
ted
sig
na
l.29
ou
t_b
uffe
r_d
ow
n_
two
bu
ffe
ro
fd
ow
nsa
mp
led
de
mo
du
late
dsi
gn
al
30 31 32*/
33vo
idd
ow
nsa
mp
le_
two
(flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
two
[]);
34#
en
dif
/*_
DO
WN
SA
MP
LE
_T
WO
_*/
35 36/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
37E
ND
OF
TH
EF
ILE
38_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.18
:Flo
atin
g-Po
int:
:dow
nsam
ple_
two.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
DO
WN
SA
MP
LE
TW
O-
VE
RS
ION
FL
OA
TIN
GP
OIN
T1
.03 4
file
:d
ow
nsa
mle
_tw
o.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"do
wn
sam
ple
_tw
o.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17im
ple
me
nta
tion
of
fun
ctio
n18
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
19vo
idd
ow
nsa
mp
le_
two
(flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
two
[])
20{
21in
ti
;22
23fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
OU
TP
UT;i
++
)24
{25
ou
t_b
uffe
r_d
ow
n_
two
[i
]=o
ut_
bu
ffe
r_d
ow
n_
on
e[
i*
DO
WN
SA
MP
LE
_T
WO
];26
}27
}28 29
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_30
EN
DO
FT
HE
FIL
E31
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
F.1.
3.Fi
xed-
Poin
t
glob
al_s
etti
ngs Li
stin
gF.
19:F
ixed
-Poi
nt::
glob
al_s
ettin
gs.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2G
LO
BA
LS
ET
TIN
GS
--
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
glo
ba
l_se
ttin
gs.
h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#d
efin
eB
UF
FE
RS
IZE
12
812
#d
efin
eD
OW
NS
AM
PL
E_
ON
E413
#d
efin
eD
OW
NS
AM
PL
E_
TW
O214 15
#d
efin
eB
UF
FE
RS
IZE
_IN
PU
T(
BU
FF
ER
SIZ
E)16
#d
efin
eB
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR(
BU
FF
ER
SIZ
E/D
OW
NS
AM
PL
E_
ON
E)
17#
de
fine
BU
FF
ER
SIZ
E_
OU
TP
UT
(B
UF
FE
RS
IZE/
(D
OW
NS
AM
PL
E_
ON
E*
DO
WN
SA
MP
LE
_T
WO
))18 19
#d
efin
eP
I3
.14
15
92
65
35
9
fm_d
em_m
ain
List
ing
F.20
:Fix
ed-P
oint
::fm
_dem
_mai
n.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2F
MD
EM
OD
UL
AT
ION
MA
IN-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
fm_
de
m_
ma
in.c
5d
ate
:n
ov
20
01
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
de
mo
du
lato
rd
efin
e13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
de
fine
FM
_M
IXE
D_
DE
M1
015
#d
efin
eF
M_
PL
L_
DE
M2
016 17
#d
efin
eF
M_
DE
MO
DU
LA
TO
RF
M_
MIX
ED
_D
EM
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
incl
ud
es
21--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/22 23
#in
clu
de
<st
d.
h>
24#
incl
ud
e<
swi
.h
>25
#in
clu
de
<cs
l.
h>
26#
incl
ud
e<
bsl
.h
>27 28
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
29#
incl
ud
e"a
dc_
TH
S1
40
8.h
"
126
F.1. C Listings
30#
incl
ud
e"d
ac_
cod
ec.
h"
31#
incl
ud
e"q
ua
d_
mix
.h"
32#
incl
ud
e"o
ut_
filte
r.h
"33
#if
(F
M_
DE
MO
DU
LA
TO
R=
=F
M_
PL
L_
DE
M)34
#in
clu
de
"pll_
de
mo
du
late
.h"
35#
elif
(F
M_
DE
MO
DU
LA
TO
R=
=F
M_
MIX
ED
_D
EM)
36#
incl
ud
e"m
ixe
d_
de
mo
du
late
.h"
37#
els
e38
#e
rro
rN
od
em
od
ula
tor
alg
orith
md
efin
ed
39#
en
dif
40 41/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--42
de
bu
gd
efin
es
43--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/44
#d
efin
eF
M_
DE
M_
CF
_D
EB
UG
045
/*to
prin
tco
mm
en
tsto
de
bu
g_
log
*/46 47
#d
efin
eF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D0
48/*
Le
dto
gg
les
wh
en
an
inte
rru
pt
occ
urs
*/49
/*L
ED
1co
de
cin
terr
up
t(o
utp
ut)
*/50
/*L
ED
2e
dm
ain
terr
up
t(in
pu
t)*/
51/*
LE
D3
timm
ing
err
or
*/52 53
#d
efin
eF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D0
54/*
Le
dO
Nb
yin
terr
up
tst
art
OF
Fa
tth
ee
nd
*/55
/*L
ED
1co
de
cin
terr
up
t(o
utp
ut)
*/56
/*L
ED
2e
dm
ain
terr
up
t(in
pu
t)*/
57/*
LE
D3
soft
wa
rein
terr
up
t*/
58 59#
de
fine
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
060
/*E
na
ble
ST
SO
bje
cts:
*/61
/*-d
ac_
sts
*/62
/*-d
em
od
ula
te_
sts
*/63
/*-e
dm
a_
sts
*/64
/*to
me
asu
reth
ed
ura
tion
time
of
the
inte
rru
pts
*/65 66
#d
efin
eF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S1
67/*
En
ab
leS
TS
Ob
ject
s:*/
68/*
-mix
_st
s*/
69/*
-de
m_
sts
*/70
/*-f
ilte
r_st
s*/
71/*
tom
ea
sure
the
du
ratio
ntim
eo
fth
efu
nct
ion
s*/
72 73#
ifF
M_
DE
M_
CF
_D
EB
UG
74#
incl
ud
e<
log
.h
>75
ext
ern
far
LO
G_
Ob
jd
eb
ug
_lo
g;
76#
en
dif
77 78#
ifF
FM
_D
EM
_C
F_
INT
_O
CC
UR
_L
ED
79#
incl
ud
e<
bsl
_le
d.
h>
80#
en
dif
81 82#
ifF
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
83#
incl
ud
e<
bsl
_le
d.
h>
84#
en
dif
85 86#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S87
#in
clu
de
<cl
k.
h>
88#
incl
ud
e<
sts
.h
>89
ext
ern
far
ST
S_
Ob
jd
ac_
sts
;90
ext
ern
far
ST
S_
Ob
jd
em
od
ula
te_
sts
;91
ext
ern
far
ST
S_
Ob
je
dm
a_
sts
;92
#e
nd
if93 94
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
95#
incl
ud
e<
clk
.h
>96
#in
clu
de
<st
s.
h>
97e
xte
rnfa
rS
TS
_O
bj
mix
_st
s;
98e
xte
rnfa
rS
TS
_O
bj
de
m_
sts
;99
ext
ern
far
ST
S_
Ob
jfil
ter_
sts
;10
0#
en
dif
101
102
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
103
DS
P/B
IOS
ext
ern
varib
les
104
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
105
106
ext
ern
far
SW
I_O
bj
de
mo
du
late
_sw
i;
107
ext
ern
HW
I_e
na
ble
();
108
ext
ern
HW
I_d
isa
ble
();
109
110
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
111
glo
ba
lva
rib
les
112
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
113
114
sho
rtin
_b
uffe
r_A
[B
UF
FE
RS
IZE
_IN
PU
T];
115
sho
rtin
_b
uffe
r_B
[B
UF
FE
RS
IZE
_IN
PU
T];
116
117
sho
rtre
_b
uffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;11
8sh
ort
im_
bu
ffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;11
912
0sh
ort
ou
t_b
uffe
r[
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R];
121
sho
rto
ut_
bu
ffe
r_A
[B
UF
FE
RS
IZE
_O
UT
PU
T];12
2sh
ort
ou
t_b
uffe
r_B
[B
UF
FE
RS
IZE
_O
UT
PU
T];12
312
412
512
6sh
ort
*in
_b
uffe
r_p
tr;
127
sho
rt*
ou
t_b
uffe
r_p
tr;
128
Bo
ol
a_
inE
DM
A=
TR
UE;
129
sho
rto
utc
ou
nte
r=
0;
130
131
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
132
the
ma
infu
nct
ion
133
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
134
void
ma
in()
135
{13
6H
WI_
dis
ab
le()
;13
713
8#
ifF
M_
DE
M_
CF
_D
EB
UG
139
LO
G_
prin
tf(&
de
bu
g_
log
,"In
fo:
Be
gin
Of
ma
in")
;14
0#
en
dif
141
142
CS
L_
init
();
/*o
nch
ipin
it*/
143
BS
L_
init
();
/*o
nb
oa
rdin
it*/
144
145
ths1
40
8_
init
(in
_b
uffe
r_A
,in
_b
uffe
r_B
);14
6co
de
c_in
it()
;14
714
8H
WI_
en
ab
le()
;14
915
0th
s14
08
_st
art
();
151
cod
ec_
sta
rt()
;15
215
3#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D15
4L
ED
_o
ff(
LE
D_
AL
L);
155
#e
nd
if15
615
7#
ifF
M_
DE
M_
CF
_D
EB
UG
158
LO
G_
prin
tf(&
de
bu
g_
log
,"In
fo:
En
dO
fm
ain
");
159
#e
nd
if16
0}
161
162
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
163
ha
rdw
are
inte
rru
pt
fun
ctio
ns
164
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
165
166
void
ed
ma
Int
(vo
id)
167
{16
8#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D16
9L
ED
_to
gg
le(
LE
D_
2);
170
#e
nd
if17
117
2#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D17
3L
ED
_o
n(
LE
D_
2);
174
#e
nd
if17
517
6#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S17
7S
TS
_se
t(&
ed
ma
_st
s,
CL
K_
ge
thtim
e()
);17
8#
en
dif
179
180
/*re
set
ou
tco
un
ter
*/18
1o
utc
ou
nte
r=
0;
182
183
/*se
lect
ED
MA
cha
nn
el
*/18
4if
(E
DM
A_
intT
est
(T
HS
14
08
_B
UF
FE
R_
A_
TC
C))18
5{
186
#if
FM
_D
EM
_C
F_
DE
BU
G18
7L
OG
_p
rin
tf(&
de
bu
g_
log
,"In
_A
");
188
#e
nd
if18
9/*
Cle
ar
tra
nsf
er
com
ple
tion
inte
rru
pt
flag
*/
127
Listings19
0E
DM
A_
intC
lea
r(
TH
S1
40
8_
BU
FF
ER
_A
_T
CC);
191
192
/*se
tb
uffe
rp
oin
ters
*/19
3a
_in
ED
MA
=F
AL
SE;
194
in_
bu
ffe
r_p
tr=
in_
bu
ffe
r_A
;19
5o
ut_
bu
ffe
r_p
tr=
ou
t_b
uffe
r_A
;19
619
7/*
po
stso
ftw
are
inte
rru
pt
->st
art
de
mo
du
latio
n*/
198
SW
I_p
ost
(&d
em
od
ula
te_
swi
);19
9}
200
if(
ED
MA
_in
tTe
st(
TH
S1
40
8_
BU
FF
ER
_B
_T
CC))
201
{20
2#
ifF
M_
DE
M_
CF
_D
EB
UG
203
LO
G_
prin
tf(&
de
bu
g_
log
,"In
_B
");
204
#e
nd
if20
5/*
Cle
ar
tra
nsf
er
com
ple
tion
inte
rru
pt
flag
*/20
6E
DM
A_
intC
lea
r(
TH
S1
40
8_
BU
FF
ER
_B
_T
CC);
207
208
/*se
tb
uffe
rp
oin
ters
*/20
9a
_in
ED
MA
=T
RU
E;21
0in
_b
uffe
r_p
tr=
in_
bu
ffe
r_B
;21
1o
ut_
bu
ffe
r_p
tr=
ou
t_b
uffe
r_B
;21
221
3/*
po
stso
ftw
are
inte
rru
pt
->st
art
de
mo
du
latio
n*/
214
SW
I_p
ost
(&d
em
od
ula
te_
swi
);21
5}
216
217
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
218
ST
S_
de
lta(&
ed
ma
_st
s,
CL
K_
ge
thtim
e()
);21
9#
en
dif
220
221
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
222
LE
D_
off
(L
ED
_2)
;22
3#
en
dif
224
}22
522
6vo
idd
acI
nt
(vo
id)
227
{22
8#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D22
9L
ED
_to
gg
le(
LE
D_
1);
230
#e
nd
if23
123
2#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D23
3L
ED
_o
n(
LE
D_
1);
234
#e
nd
if23
523
6#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S23
7S
TS
_se
t(&
da
c_st
s,
CL
K_
ge
thtim
e()
);23
8#
en
dif
239
240
/*in
terp
ola
tea
mis
sin
gsa
mp
le*/
241
if(
ou
tco
un
ter
>1
5)
242
{24
3#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D24
4L
ED
_to
gg
le(
LE
D_
3);
245
#e
nd
if24
6/*
sele
ctth
eb
uffe
r*/
247
if(
a_
inE
DM
A)
248
{24
9A
D5
35
_H
WI_
write
(o
utA
D5
35
h,(
(o
ut_
bu
ffe
r_A
[15
]+o
ut_
bu
ffe
r_B
[0])
/2))
;25
0#
ifF
M_
DE
M_
CF
_D
EB
UG
251
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
Ae
rro
r:%
d",
ou
tco
un
ter
);25
2#
en
dif
253
}e
lse
254
{25
5A
D5
35
_H
WI_
write
(o
utA
D5
35
h,(
(o
ut_
bu
ffe
r_B
[15
]+o
ut_
bu
ffe
r_A
[0])
/2))
;25
6#
ifF
M_
DE
M_
CF
_D
EB
UG
257
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
Be
rro
r:%
d",
ou
tco
un
ter
);25
8#
en
dif
259
}26
0}
els
e/*
ou
tpu
ta
valu
e*/
261
{26
2/*
sele
ctth
eb
uffe
r*/
263
if(
a_
inE
DM
A)
264
{26
5A
D5
35
_H
WI_
write
(o
utA
D5
35
h,
ou
t_b
uffe
r_A
[o
utc
ou
nte
r])
;26
6#
ifF
M_
DE
M_
CF
_D
EB
UG
267
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
A:%
d",
ou
tco
un
ter
);26
8#
en
dif
269
}e
lse
270
{27
1A
D5
35
_H
WI_
wri
te(
ou
tAD
53
5h
,o
ut_
bu
ffe
r_B
[o
utc
ou
nte
r])
;27
2#
ifF
M_
DE
M_
CF
_D
EB
UG
273
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
B:%
d",
ou
tco
un
ter
);27
4#
en
dif
275
}27
6/*
up
da
teo
utc
ou
nte
r*/
277
ou
tco
un
ter
++
;27
8}
279
280
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
281
ST
S_
de
lta(&
da
c_st
s,
CL
K_
ge
thtim
e()
);28
2#
en
dif
283
284
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
285
LE
D_
off
(L
ED
_1)
;28
6#
en
dif
287
}28
828
9/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--29
0so
ftw
are
inte
rru
pt
fun
ctio
ns
291
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
292
293
void
de
mo
du
late
Sw
iFu
nc
(vo
id)
294
{29
5in
ti
;29
629
7#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D29
8L
ED
_o
n(
LE
D_
3);
299
#e
nd
if30
030
1#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S30
2S
TS
_se
t(&
de
mo
du
late
_st
s,
CL
K_
ge
thtim
e()
);30
3#
en
dif
304
305
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)30
6{
307
in_
bu
ffe
r_p
tr[
i]=
in_
bu
ffe
r_p
tr[
i]<
<2
;30
8}
309
310
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
311
ST
S_
set
(&m
ix_
sts
,C
LK
_g
eth
time
());
312
#e
nd
if31
3q
ua
d_
mix
(in
_b
uffe
r_p
tr,
re_
bu
ffe
r,
im_
bu
ffe
r);
314
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
315
ST
S_
de
lta(&
mix
_st
s,
CL
K_
ge
thtim
e()
);31
6#
en
dif
317
318
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
319
ST
S_
set
(&d
em
_st
s,
CL
K_
ge
thtim
e()
);32
0#
en
dif
321
#if
(F
M_
DE
MO
DU
LA
TO
R=
=F
M_
PL
L_
DE
M)32
2p
ll_d
em
od
ula
te(
re_
bu
ffe
r,
im_
bu
ffe
r,
ou
t_b
uffe
r);
323
#e
lif(
FM
_D
EM
OD
UL
AT
OR
==
FM
_M
IXE
D_
DE
M)32
4m
ixe
d_
de
mo
du
late
(re
_b
uffe
r,
im_
bu
ffe
r,
ou
t_b
uffe
r);
325
#e
lse
326
#e
rro
rN
od
em
od
ula
tor
alg
orith
md
efin
ed
327
#e
nd
if32
8#
ifF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S32
9S
TS
_d
elta
(&d
em
_st
s,
CL
K_
ge
thtim
e()
);33
0#
en
dif
331
332
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
333
ST
S_
set
(&fil
ter_
sts
,C
LK
_g
eth
time
());
334
#e
nd
if33
5o
ut_
filte
r(
ou
t_b
uffe
r,
ou
t_b
uffe
r_p
tr);
336
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
337
ST
S_
de
lta(&
filte
r_st
s,
CL
K_
ge
thtim
e()
);33
8#
en
dif
339
340
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
341
ST
S_
de
lta(&
de
mo
du
late
_st
s,
CL
K_
ge
thtim
e()
);34
2#
en
dif
343
344
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
345
LE
D_
off
(L
ED
_3)
;34
6#
en
dif
347
}
128
F.1. C Listings
quad
_mix
List
ing
F.21
:Fix
ed-P
oint
::qu
ad_m
ix.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2Q
UA
DR
AT
UR
EM
IXE
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
qu
ad
_m
ix.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_Q
UA
D_
MIX
_12
#d
efin
e_
QU
AD
_M
IX_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23th
esi
gn
al
inth
ein
_b
uffe
ris
qu
ad
ratu
rem
ixe
dto
the
two
24b
uffe
rsre
_b
uffe
ra
nd
im_
bu
ffe
ra
nd
isa
lso
do
wn
sam
ple
db
y25
DO
WN
SA
MP
LE
_O
NE
26 27P
ara
me
ters
:28
in_
bu
ffe
rb
uffe
rw
ithin
pu
tsi
gn
al
29re
_b
uffe
rb
uffe
ro
fsi
gn
al
mix
ed
with
cosi
ne
30o
ut_
bu
ffe
rb
uffe
ro
fsi
gn
al
mix
ed
with
sin
e31
*/32
void
qu
ad
_m
ix(
sho
rtin
_b
uffe
r[]
,sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]);
33 34#
en
dif
/*_
QU
AD
_M
IX_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.22
:Fix
ed-P
oint
::qu
ad_m
ix.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2Q
UA
DR
AT
UR
EM
IXE
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
qu
ad
_m
ix.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"qu
ad
_m
ix.h
"15 16 17
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
18g
lob
al
varib
les
19--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/20 21 22
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
23co
effic
ien
tso
fsi
ne
an
dco
sin
eo
szila
tor
24--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/25
/*F
req
ue
ncy
:1
31
39
.93
HZ
*/26 27
sho
rtg
en
_b
1_
cos
=-9
07
6;
/*co
s*/
28sh
ort
ge
n_
b1
_si
n=
31
48
6;
/*si
n*/
29sh
ort
ge
n_
a1
=-1
81
52
;/*
sin
/co
s*/
30 31/*
de
lay
varia
be
ls*/
32sh
ort
ge
n_
z[3
]=
{0,0
,26
21
3};
/*fir
stva
lue
(de
ltafu
nct
ion
)*/
33/*
0.8
toa
void
ove
rflo
ws
*/34 35
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
36co
effic
ien
tso
fm
ixe
rlo
w-p
ass
(mix
_lp
)37
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
38/*
Ord
er
:5
*/39
/*P
ass
-ba
nd
:2
dB
@6
30
0.0
0H
z*/
40/*
Sto
p-b
an
d:
60
dB
@1
90
00
.00
Hz
*/41 42
#d
efin
eM
IX_
LP
_C
AS
CA
DE
S3
43sh
ort
con
stm
ix_
lp_
a[][3
]={
/*a
_i_
1a
a_
i_1
ba
_i_
2*/
44{
-80
92
,-8
09
2,
0},
45{
-17
44
4,
-17
44
4,
11
16
6},
46{
-21
90
7,
-21
90
7,
22
40
6},
47};
48 49sh
ort
con
stm
ix_
lp_
b[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
50{
45
23
,4
52
3,
0},
51{
27
25
,5
45
0,
27
25
},52
{8
53
7,
17
07
4,
85
37
},53
};54 55
sho
rtco
nst
mix
_lp
_sc
ale
=1
65
83
;/*
16
58
3to
avo
ido
verf
low
s*/
56 57/*
de
lay
varia
be
ls*/
58sh
ort
mix
_lp
_z_
re[][3
]={
59{
0,0
,0},
60{
0,0
,0},
61{
0,0
,0},
62};
63sh
ort
mix
_lp
_z_
im[][3
]={
64{
0,0
,0},
65{
0,0
,0},
66{
0,0
,0},
67};
68 69/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--70
imp
lem
en
tatio
no
ffu
nct
ion
71--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/72
void
qu
ad
_m
ix(
sho
rtin
_b
uffe
r[]
,sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[])
73{
74in
ti
,k
;75 76
/*_
_si
ne
an
dco
sin
eg
en
era
tion
__
*/77 78
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)79
{80
/*fe
ed
ba
ck*/
81g
en
_z
[0]=
-(((
ge
n_
a1
*g
en
_z
[1])
>>
15
)+
ge
n_
z[2
]);
82 83/*
fore
wa
rd*/
84re
_b
uffe
r[
i]=
ge
n_
z[0
]+
((g
en
_b
1_
cos
*g
en
_z
[1])
>>
15
);85
im_
bu
ffe
r[
i]=
(g
en
_b
1_
sin
*g
en
_z
[1])
>>
15
;86 87
/*sh
iftd
ela
ys*/
88g
en
_z
[2]=
ge
n_
z[1
];89
ge
n_
z[1
]=g
en
_z
[0];
90}
91 92/*
__
mix
ing
an
dsc
alin
g_
_*/
93 94fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
INP
UT;
i+
+)
95{
96/*
mix
ing
*/97
re_
bu
ffe
r[
i]=
(re
_b
uffe
r[
i]*
in_
bu
ffe
r[
i])
>>
15
;98
im_
bu
ffe
r[
i]=
(im
_b
uffe
r[
i]*
in_
bu
ffe
r[
i])
>>
15
;99 100
/*sc
alin
ga
nd
ne
go
fim
_p
ath
*/10
1re
_b
uffe
r[
i]=
(re
_b
uffe
r[
i]*
mix
_lp
_sc
ale
)>>
15
;10
2im
_b
uffe
r[
i]=
-((
im_
bu
ffe
r[
i]*
mix
_lp
_sc
ale
)>>
15
);10
3}
104
105
/*_
_lo
w-p
ass
filte
rin
g_
_*/
106
107
/*--
Ca
sca
de
0(f
irst
Ord
er)
--*/
108
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)10
9{
110
/*fe
ed
ba
ck*/
111
mix
_lp
_z_
re[0
][0
]=
re_
bu
ffe
r[
i]-
((
mix
_lp
_a
[0][0
]*m
ix_
lp_
z_re
[0][1
]+
/*a
_1
a*z
1*/
129
Listings11
2m
ix_
lp_
a[0
][1
]*m
ix_
lp_
z_re
[0][1
]/*
a_
1b
*z1
*/11
3)>
>1
5);
114
115
mix
_lp
_z_
im[0
][0
]=
im_
bu
ffe
r[
i]-
((
mix
_lp
_a
[0][0
]*m
ix_
lp_
z_im
[0][1
]+
/*a
_1
a*z
1*/
116
mix
_lp
_a
[0][1
]*m
ix_
lp_
z_im
[0][1
]/*
a_
1b
*z1
*/11
7)>
>1
5);
118
119
/*fo
rew
ard
*/12
0re
_b
uffe
r[
i]=
(m
ix_
lp_
b[0
][0
]*m
ix_
lp_
z_re
[0][0
]+/*
b_
0*
z0*/
121
mix
_lp
_b
[0][1
]*m
ix_
lp_
z_re
[0][1
]/*
b_
1*
z1*/
122
)>>
15
;12
312
4im
_b
uffe
r[
i]=
(m
ix_
lp_
b[0
][0
]*m
ix_
lp_
z_im
[0][0
]+/*
b_
0*
z0*/
125
mix
_lp
_b
[0][1
]*m
ix_
lp_
z_im
[0][1
]/*
b_
1*
z1*/
126
)>>
15
;12
712
8/*
shift
de
lays
*/12
9m
ix_
lp_
z_re
[0][1
]=m
ix_
lp_
z_re
[0][0
];13
013
1m
ix_
lp_
z_im
[0][1
]=m
ix_
lp_
z_im
[0][0
];13
2}
133
134
/*--
Ca
sca
de
1(S
eco
nd
Ord
er)
--*/
135
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)13
6{
137
/*fe
ed
ba
ck*/
138
mix
_lp
_z_
re[1
][0
]=
re_
bu
ffe
r[
i]-
((
mix
_lp
_a
[1][0
]*m
ix_
lp_
z_re
[1][1
]+
/*a
_1
a*z
1*/
139
mix
_lp
_a
[1][1
]*m
ix_
lp_
z_re
[1][1
]+
/*a
_1
b*z
1*/
140
mix
_lp
_a
[1][2
]*m
ix_
lp_
z_re
[1][2
]/*
a_
2*z
2*/
141
)>>
15
);14
214
3m
ix_
lp_
z_im
[1][0
]=
im_
bu
ffe
r[
i]-
((
mix
_lp
_a
[1][0
]*m
ix_
lp_
z_im
[1][1
]+
/*a
_1
a*z
1*/
144
mix
_lp
_a
[1][1
]*m
ix_
lp_
z_im
[1][1
]+
/*a
_1
b*z
1*/
145
mix
_lp
_a
[1][2
]*m
ix_
lp_
z_im
[1][2
]/*
a_
2*z
2*/
146
)>>
15
);14
714
8/*
fore
wa
rd*/
149
re_
bu
ffe
r[
i]=
(m
ix_
lp_
b[1
][0
]*m
ix_
lp_
z_re
[1][0
]+/*
b_
0*
z0*/
150
mix
_lp
_b
[1][1
]*m
ix_
lp_
z_re
[1][1
]+/*
b_
1*
z1*/
151
mix
_lp
_b
[1][2
]*m
ix_
lp_
z_re
[1][2
]/*
b_
2*
z2*/
152
)>>
15
;15
315
4im
_b
uffe
r[
i]=
(m
ix_
lp_
b[1
][0
]*m
ix_
lp_
z_im
[1][0
]+/*
b_
0*
z0*/
155
mix
_lp
_b
[1][1
]*m
ix_
lp_
z_im
[1][1
]+/*
b_
1*
z1*/
156
mix
_lp
_b
[1][2
]*m
ix_
lp_
z_im
[1][2
]/*
b_
2*
z2*/
157
)>>
15
;15
815
9/*
shift
de
lays
*/16
0m
ix_
lp_
z_re
[1][2
]=m
ix_
lp_
z_re
[1][1
];16
1m
ix_
lp_
z_re
[1][1
]=m
ix_
lp_
z_re
[1][0
];16
216
3m
ix_
lp_
z_im
[1][2
]=m
ix_
lp_
z_im
[1][1
];16
4m
ix_
lp_
z_im
[1][1
]=m
ix_
lp_
z_im
[1][0
];16
5}
166
167
/*--
Ca
sca
de
2(s
eco
nd
Ord
er)
--*/
/*in
clu
din
gd
ow
nsa
mp
ling
*/16
8fo
r(
i=
0,
k=
0;
i<
BU
FF
ER
SIZ
E_
INP
UT;
i+
+)
169
{17
0/*
fee
db
ack
*/17
1m
ix_
lp_
z_re
[2][0
]=
re_
bu
ffe
r[
i]-
((
mix
_lp
_a
[2][0
]*m
ix_
lp_
z_re
[2][1
]+
/*a
_1
a*z
1*/
172
mix
_lp
_a
[2][1
]*m
ix_
lp_
z_re
[2][1
]+
/*a
_1
b*z
1*/
173
mix
_lp
_a
[2][2
]*m
ix_
lp_
z_re
[2][2
]/*
a_
2*z
2*/
174
)>>
15
);17
517
6m
ix_
lp_
z_im
[2][0
]=
im_
bu
ffe
r[
i]-
((
mix
_lp
_a
[2][0
]*m
ix_
lp_
z_im
[2][1
]+
/*a
_1
a*z
1*/
177
mix
_lp
_a
[2][1
]*m
ix_
lp_
z_im
[2][1
]+
/*a
_1
b*z
1*/
178
mix
_lp
_a
[2][2
]*m
ix_
lp_
z_im
[2][2
]/*
a_
2*z
2*/
179
)>>
15
);18
018
1/*
fore
wa
rdin
clu
din
gd
ow
nsa
mp
ling
->ta
kee
very
4th
valu
e*/
182
if(
i%
DO
WN
SA
MP
LE
_O
NE
==
0)
183
{18
4re
_b
uffe
r[
k]=
(m
ix_
lp_
b[2
][0
]*m
ix_
lp_
z_re
[2][0
]+/*
b_
0*
z0*/
185
mix
_lp
_b
[2][1
]*m
ix_
lp_
z_re
[2][1
]+/*
b_
1*
z1*/
186
mix
_lp
_b
[2][2
]*m
ix_
lp_
z_re
[2][2
]/*
b_
2*
z2*/
187
)>>
15
;18
818
9im
_b
uffe
r[
k]=
(m
ix_
lp_
b[2
][0
]*m
ix_
lp_
z_im
[2][0
]+/*
b_
0*
z0*/
190
mix
_lp
_b
[2][1
]*m
ix_
lp_
z_im
[2][1
]+/*
b_
1*
z1*/
191
mix
_lp
_b
[2][2
]*m
ix_
lp_
z_im
[2][2
]/*
b_
2*
z2*/
192
)>>
15
;19
3k
++
;19
4}
195
196
/*sh
iftd
ela
ys*/
197
mix
_lp
_z_
re[2
][2
]=m
ix_
lp_
z_re
[2][1
];19
8m
ix_
lp_
z_re
[2][1
]=m
ix_
lp_
z_re
[2][0
];19
920
0m
ix_
lp_
z_im
[2][2
]=m
ix_
lp_
z_im
[2][1
];20
1m
ix_
lp_
z_im
[2][1
]=m
ix_
lp_
z_im
[2][0
];20
2}
203
}20
420
520
620
7/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
208
EN
DO
FT
HE
FIL
E20
9_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
mix
ed_d
emod
ulat
e
List
ing
F.23
:Fix
ed-P
oint
::m
ixed
_dem
odul
ate.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
MIX
ED
DE
MO
DU
LA
TO
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
mix
ed
_d
em
od
ula
te.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_M
IXE
D_
DE
MO
DU
LA
TE
_12
#d
efin
e_
MIX
ED
_D
EM
OD
UL
AT
E_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18#
incl
ud
e"a
tan
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24F
Md
em
od
ula
tes
the
the
two
ba
seb
an
dsi
gn
al
re_
bu
ffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
em
ixe
da
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
mix
ed
_d
em
od
ula
te(
sho
rtre
_b
uffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
MIX
ED
_D
EM
OD
UL
AT
E_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.24
:Fix
ed-P
oint
::m
ixed
_dem
odul
ate.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
MIX
ED
DE
MO
DU
LA
TO
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
mix
ed
_d
em
od
ula
te.c
5d
ate
:o
ct2
00
1-
jan
20
02
130
F.1. C Listings
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
/*d
ela
yva
rib
ale
so
fth
em
ixe
dd
em
od
ula
tor
*/20
sho
rtd
em
_z_
re=
16
38
4;
/*!=
0to
avo
idd
ivis
ion
with
0*/
21sh
ort
de
m_
z_im
=1
63
84
;/*
!=0
toa
void
div
isio
nw
ith0
*/22 23
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
24im
ple
me
nta
tion
of
fun
ctio
n25
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
26vo
idm
ixe
d_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[])
27{
28in
ti
;29
int
re_
pa
th=
0;
30in
tim
_p
ath
=0
;31
int
de
m_
arg
=0
;32 33 34
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)35
{36
re_
pa
th=
(im
_b
uffe
r[
i]*
de
m_
z_re
-re
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/37
im_
pa
th=
(re
_b
uffe
r[
i]*
de
m_
z_re
+im
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/38 39
/*sh
iftd
ela
ys*/
40d
em
_z_
re=
re_
bu
ffe
r[
i];
41d
em
_z_
im=
im_
bu
ffe
r[
i];
42 43/*
calc
ula
teth
ea
rgu
me
nt
*/44
de
m_
arg
=re
_p
ath
/(im
_p
ath
>>
14
);/*
Q1
7.1
4*/
45 46/*
ata
nlo
oku
p*/
47if
(d
em
_a
rg>
0)
/*p
osi
tiv*/
48{
49d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;50
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;51
ou
t_b
uffe
r[
i]=
ata
n_
bu
ffe
r[
de
m_
arg
];52
}e
lse
/*n
eg
ativ
e*/
53{
54d
em
_a
rg=
-d
em
_a
rg;
55d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;56
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;57
ou
t_b
uffe
r[
i]=
-a
tan
_b
uffe
r[
de
m_
arg
];58
}59
}60
}61 62
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_63
EN
DO
FT
HE
FIL
E64
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.25
:Fix
ed-P
oint
Inte
rpol
ated
::m
ixed
_dem
odul
ate.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
MIX
ED
DE
MO
DU
LA
TO
RW
ITH
INT
ER
PO
LA
TIO
N-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
mix
ed
_d
em
od
ula
te.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_M
IXE
D_
DE
MO
DU
LA
TE
_12
#d
efin
e_
MIX
ED
_D
EM
OD
UL
AT
E_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18#
incl
ud
e"a
tan
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24F
Md
em
od
ula
tes
the
the
two
ba
seb
an
dsi
gn
al
re_
bu
ffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
em
ixe
da
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
mix
ed
_d
em
od
ula
te(
sho
rtre
_b
uffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
MIX
ED
_D
EM
OD
UL
AT
E_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.26
:Fix
ed-P
oint
Inte
rpol
ated
::m
ixed
_dem
odul
ate.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
MIX
ED
DE
MO
DU
LA
TO
RW
ITH
INT
ER
PO
LA
TIO
N-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
mix
ed
_d
em
od
ula
te.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
/*d
ela
yva
rib
ale
so
fth
em
ixe
dd
em
od
ula
tor
*/20
sho
rtd
em
_z_
re=
16
38
4;
/*!=
0to
avo
idd
ivis
ion
with
0*/
21sh
ort
de
m_
z_im
=1
63
84
;/*
!=0
toa
void
div
isio
nw
ith0
*/22 23
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
24im
ple
me
nta
tion
of
fun
ctio
n25
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
26vo
idm
ixe
d_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[])
27{
28in
ti
;29
int
re_
pa
th=
0;
30in
tim
_p
ath
=0
;31
int
de
m_
arg
=0
;32
sho
rtcu
toff
=0
;33 34 35
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)36
{37 38
re_
pa
th=
(im
_b
uffe
r[
i]*
de
m_
z_re
-re
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/39
im_
pa
th=
(re
_b
uffe
r[
i]*
de
m_
z_re
+im
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/40 41
/*sh
iftd
ela
ys*/
42d
em
_z_
re=
re_
bu
ffe
r[
i];
43d
em
_z_
im=
im_
bu
ffe
r[
i];
44 45/*
calc
ula
teth
ea
rgu
me
nt
*/46
de
m_
arg
=re
_p
ath
/(im
_p
ath
>>
14
);/*
Q1
7.1
4*/
47 48/*
ata
nlo
oku
p*/
49if
(d
em
_a
rg>
0)
/*p
osi
tiv*/
50{
51cu
toff
=d
em
_a
rg%
AT
AN
_IN
TE
RP
OL;
52d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;53
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;54
ou
t_b
uffe
r[
i]=
ata
n_
bu
ffe
r[
de
m_
arg
]+((
cuto
ff*
ata
n_
gra
d_
bu
ffe
r[
de
m_
arg
])>
>A
TA
N_
SH
IFT)
;
131
Listings55
}e
lse
/*n
eg
ativ
e*/
56{
57 58d
em
_a
rg=
-d
em
_a
rg;
59cu
toff
=d
em
_a
rg%
AT
AN
_IN
TE
RP
OL;
60d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;61
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;62
ou
t_b
uffe
r[
i]=
-(a
tan
_b
uffe
r[
de
m_
arg
]+((
cuto
ff*
ata
n_
gra
d_
bu
ffe
r[
de
m_
arg
])>
>A
TA
N_
SH
IFT)
);63
}64
}65
}66 67
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_68
EN
DO
FT
HE
FIL
E69
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
pll_
dem
odul
ate Li
stin
gF.
27:F
ixed
-Poi
nt::
pll_
dem
odul
ate.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
PL
LD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T0
.53 4
file
:p
ll_d
em
od
ula
te.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_P
LL
_D
EM
OD
UL
AT
E_
12#
de
fine
_P
LL
_D
EM
OD
UL
AT
E_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18#
incl
ud
e"s
ine
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24F
Md
em
od
ula
tes
the
the
two
ba
seb
an
dsi
gn
al
re_
bu
ffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
ep
lla
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
pll_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
PL
L_
DE
MO
DU
LA
TE
_*/
35 36/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
37E
ND
OF
TH
EF
ILE
38_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.28
:Fix
ed-P
oint
::pl
l_de
mod
ulat
e.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2P
LL
DE
MO
DU
LA
TO
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
pll_
de
mo
du
late
.c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
incl
ud
e"p
ll_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
sho
rta
rg=
0;
/*a
rgu
me
nt
of
sin
ea
nd
cosi
ne
*/20
sho
rti_
pa
th=
10
00
;/*
Ip
ath
*/21
sho
rtq
_p
ath
=0
;/*
Qp
ath
*/22 23
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
24g
lob
al
de
fine
s25
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
26#
de
fine
P_
PL
L6
55
36
/*P
_P
LL
=2
.0,
usi
ng
q1
5*/
27#
de
fine
K_
PL
L1
02
40
/*K
_P
LL
=2
.5,
usi
ng
q3
.12
*/28
#d
efin
eG
AIN
_P
LL
55
72
1/*
GA
IN_
PL
L=
1.7
,u
sin
gq
15
*/29
#d
efin
eT
WO
_P
I2
57
35
/*2
*PI,
usi
ng
q3
.12
*/30 31 32
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
33im
ple
me
nta
tion
of
fun
ctio
n34
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
35vo
idp
ll_d
em
od
ula
te(
sho
rtre
_b
uffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[])
36{
37in
ti
;38
int
flag
=0
;39 40
sho
rtd
em
o;/*
ind
ex
for
sin
e_
bu
ffe
ra
cce
ss*/
41sh
ort
ind
ex
;/*
valu
eo
fd
em
od
ula
tion
*/42 43 44
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)45
{46
/*_
_ca
lcu
latio
no
fd
em
od
ula
ted
valu
e,
usi
ng
Q1
5_
_*/
47 48i_
pa
th=
(re
_b
uffe
r[
i]*
i_p
ath
)>>
15
;49
q_
pa
th=
(im
_b
uffe
r[
i]*
q_
pa
th)>
>1
5;
50 51d
em
o=q
_p
ath
-i_
pa
th;
52d
em
o=(
de
mo*
P_
PL
L)>
>1
5;
53 54o
ut_
bu
ffe
r[
i]=
(d
em
o*G
AIN
_P
LL
)>>
15
;55 56 57
/*_
_su
mm
atio
no
fd
em
od
ula
ted
sig
na
l,u
sin
gQ
3.1
2_
_*/
58 59d
em
o=d
em
o>>
3;
60a
rg=
arg
+((
de
mo*
K_
PL
L)>
>1
2);
61 62 63/*
__
limita
tion
of
arg
um
en
tto
2*P
I,u
sin
gQ
3.1
2_
_*/
64 65if
(a
rg>
TW
O_
PI)
66{
67a
rg=
arg
-T
WO
_P
I;68
}69 70
els
eif
(a
rg<
-T
WO
_P
I)71
{72
arg
=a
rg+
TW
O_
PI;
73}
74 75 76/*
__
calc
ula
tion
of
sin
ea
nd
cosi
ne
valu
eo
fa
rgu
me
nt_
_*/
77 78/*
calc
ula
ting
of
ind
ex
for
sin
e_
bu
ffe
ra
cce
ss,
usi
ng
ne
wQ
form
at*
/79 80
ind
ex
=a
rg>
>R
ED
UC
TIO
N;81 82
if(
ind
ex
<0
)83
{84
ind
ex
=-
ind
ex
;85
flag
=1
;86
}87 88
ind
ex
=(
ind
ex
*S
TE
P_
INV
ER
SE)
>>
(2*
Q_
FO
RM
AT);
89 90if
(fla
g=
=1
)91
{
132
F.1. C Listings
92in
de
x=
-in
de
x;
93fla
g=
0;
94}
95 96/*
acc
ess
on
sin
e_
bu
ffe
rw
ithin
de
x*/
97 98if
(in
de
x>
=0
)99
{10
0if
(in
de
x<
(B
UF
FE
RS
IZE
_S
INE-1
))10
1{
102
/*si
ne
valu
e*/
103
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];10
4/*
cosi
ne
valu
e*/
105
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
106
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];10
7}
108
els
eif
(in
de
x<
2*(
BU
FF
ER
SIZ
E_
SIN
E-1
))10
9{
110
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);11
1/*
sin
eva
lue
*/11
2in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
113
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];11
4/*
cosi
ne
valu
e*/
115
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
116
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];11
7}
118
els
eif
(in
de
x<
3*(
BU
FF
ER
SIZ
E_
SIN
E-1
))11
9{
120
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);12
1/*
sin
eva
lue
*/12
2i_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];12
3/*
cosi
ne
valu
e*/
124
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
125
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];12
6}
127
els
eif
(in
de
x<
4*(
BU
FF
ER
SIZ
E_
SIN
E-1
))12
8{
129
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);13
0/*
sin
eva
lue
*/13
1in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
132
i_p
ath
=-
sin
e_
bu
ffe
r[
ind
ex
];13
3/*
cosi
ne
valu
e*/
134
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
135
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];13
6}
137
els
e13
8{
139
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);14
0/*
sin
eva
lue
*/14
1i_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];14
2/*
cosi
ne
valu
e*/
143
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
144
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];14
5}
146
}14
7e
lse
148
{14
9if
(in
de
x>
-(B
UF
FE
RS
IZE
_S
INE-1
))15
0{
151
ind
ex
=-
ind
ex
;15
2/*
sin
eva
lue
*/15
3i_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];15
4/*
cosi
ne
valu
e*/
155
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
156
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];15
7}
158
els
eif
(in
de
x>
-2*(
BU
FF
ER
SIZ
E_
SIN
E-1
))15
9{
160
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
161
/*si
ne
valu
e*/
162
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
163
i_p
ath
=-
sin
e_
bu
ffe
r[
ind
ex
];16
4/*
cosi
ne
valu
e*/
165
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
166
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];16
7}
168
els
eif
(in
de
x>
-3*(
BU
FF
ER
SIZ
E_
SIN
E-1
))16
9{
170
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
171
/*si
ne
valu
e*/
172
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];17
3/*
cosi
ne
valu
e*/
174
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
175
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];17
6}
177
els
eif
(in
de
x>
-4*(
BU
FF
ER
SIZ
E_
SIN
E-1
))17
8{
179
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
180
/*si
ne
valu
e*/
181
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
182
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];18
3/*
cosi
ne
valu
e*/
184
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
185
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];18
6}
187
els
e18
8{
189
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
190
/*si
ne
valu
e*/
191
i_p
ath
=-
sin
e_
bu
ffe
r[
ind
ex
];19
2/*
cosi
ne
valu
e*/
193
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
194
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];19
5}
196
}19
7}
198
}19
920
0/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
201
EN
DO
FT
HE
FIL
E20
2_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.29
:Fix
ed-P
oint
Inte
rpol
ated
::pl
l_de
mod
ulat
e.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2P
LL
DE
MO
DU
LA
TO
RW
ITH
INT
ER
PO
LA
TIO
N-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
pll_
de
mo
du
late
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
PL
L_
DE
MO
DU
LA
TE
_12
#d
efin
e_
PL
L_
DE
MO
DU
LA
TE
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18#
incl
ud
e"s
ine
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24F
Md
em
od
ula
tes
the
the
two
ba
seb
an
dsi
gn
al
re_
bu
ffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
ep
lla
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
pll_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
PL
L_
DE
MO
DU
LA
TE
_*/
35 36/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
37E
ND
OF
TH
EF
ILE
38_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.30
:Fix
ed-P
oint
Inte
rpol
ated
::pl
l_de
mod
ulat
e.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2P
LL
DE
MO
DU
LA
TO
RW
ITH
INT
ER
PO
LA
TIO
N-
VE
RS
ION
FIX
ED
PO
INT
0.5
3
133
Listings4
file
:p
ll_d
em
od
ula
te.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"pll_
de
mo
du
late
.h"
15 16/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--17
glo
ba
lva
rib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
sho
rta
rg=
0;
/*a
rgu
me
nt
of
sin
ea
nd
cosi
ne
*/20
sho
rti_
pa
th=
0;
/*I
pa
th*/
21sh
ort
q_
pa
th=
0;
/*Q
pa
th*/
22 23/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--24
glo
ba
ld
efin
es
25--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/26
#d
efin
eP
_P
LL
65
53
6/*
P_
PL
L=
2.0
,u
sin
gq
15
*/27
#d
efin
eK
_P
LL
10
24
0/*
K_
PL
L=
2.5
,u
sin
gq
12
*/28
#d
efin
eG
AIN
_P
LL
55
72
1/*
GA
IN_
PL
L=
1.7
,u
sin
gq
15
*/29
#d
efin
eT
WO
_P
I2
57
35
/*2
*PI,
usi
ng
q1
2*/
30 31 32/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--33
imp
lem
en
tatio
no
ffu
nct
ion
34--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/35
void
pll_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[])
36{
37in
ti
;38
int
flag
=0
;/*
flag
toch
eck
sig
no
fin
de
x*/
39 40 41sh
ort
ind
ex
;/*
ind
ex
for
sin
e_
bu
ffe
ra
cce
ss*/
42sh
ort
corr
ect
ion
;/*
corr
ect
ion
use
dfo
rin
terp
ola
tion
*/43
sho
rtre
st;
/*re
stu
sed
for
inte
rpo
latio
n*/
44sh
ort
de
mo;
/*va
lue
of
de
mo
du
latio
n*/
45 46 47fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
48{
49/*
__
calc
ula
tion
of
de
mo
du
late
dva
lue
,u
sin
gQ
15
__
*/50 51
i_p
ath
=(
re_
bu
ffe
r[
i]*
i_p
ath
)>>
15
;52
q_
pa
th=
(im
_b
uffe
r[
i]*
q_
pa
th)>
>1
5;
53 54d
em
o=q
_p
ath
-i_
pa
th;
55d
em
o=(
de
mo*
P_
PL
L)>
>1
5;
56 57o
ut_
bu
ffe
r[
i]=
(d
em
o*G
AIN
_P
LL
)>>
15
;58 59 60
/*_
_su
mm
atio
no
fd
em
od
ula
ted
sig
na
l,u
sin
gQ
3.1
2_
_*/
61 62d
em
o=d
em
o>>
3;
63a
rg=
arg
+((
de
mo*
K_
PL
L)>
>1
2);
64 65 66/*
__
limita
tion
of
arg
um
en
tto
2*P
I,u
sin
gQ
3.1
2_
_*/
67 68if
(a
rg>
TW
O_
PI)
69{
70a
rg=
arg
-T
WO
_P
I;71
}72 73
els
eif
(a
rg<
-T
WO
_P
I)74
{75
arg
=a
rg+
TW
O_
PI;
76}
77 78 79/*
__
calc
ula
tion
of
sin
ea
nd
cosi
ne
valu
eo
fa
rgu
me
nt_
_*/
80 81/*
calc
ula
ting
of
ind
ex
for
sin
e_
bu
ffe
ra
cce
ss,
usi
ng
ne
wQ
form
at*
/82 83
ind
ex
=a
rg>
>R
ED
UC
TIO
N;
84 85if
(in
de
x<
0)
86{
87in
de
x=
-in
de
x;
88fla
g=
1;
89}
90 91in
de
x=
(in
de
x*
ST
EP
_IN
VE
RS
E)>
>Q
_F
OR
MA
T;92
rest
=in
de
x%
FO
RM
AT;
93in
de
x=
ind
ex
>>
Q_
FO
RM
AT;
94 95if
(fla
g=
=1
)96
{97
ind
ex
=-
ind
ex
;98
flag
=0
;99
}10
010
1/*
acc
ess
on
sin
e_
bu
ffe
rw
ithin
de
x*/
102
103
if(
ind
ex
>=
0)
104
{10
5if
(in
de
x<
(B
UF
FE
RS
IZE
_S
INE-1
))10
6{
107
/*si
ne
valu
e*/
108
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/10
9i_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
110
/*co
sin
eva
lue
*/11
1in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
112
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
113
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
114
}11
5e
lse
if(
ind
ex
<2
*(B
UF
FE
RS
IZE
_S
INE-1
))11
6{
117
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);11
8/*
sin
eva
lue
*/11
9in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
120
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
121
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n;
122
/*co
sin
eva
lue
*/12
3in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
124
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/12
5q
_p
ath
=-(
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n);
126
}12
7e
lse
if(
ind
ex
<3
*(B
UF
FE
RS
IZE
_S
INE-1
))12
8{
129
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);13
0/*
sin
eva
lue
*/13
1co
rre
ctio
n=
(si
ne
_g
rad
_b
uffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/13
2i_
pa
th=
-(si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n);
133
/*co
sin
eva
lue
*/13
4in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
135
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
136
q_
pa
th=
-(si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n);
137
}13
8e
lse
if(
ind
ex
<4
*(B
UF
FE
RS
IZE
_S
INE-1
))13
9{
140
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);14
1/*
sin
eva
lue
*/14
2in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
143
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
144
i_p
ath
=-(
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n);
145
/*co
sin
eva
lue
*/14
6in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
147
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/14
8q
_p
ath
=si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n;
149
}15
0e
lse
151
{15
2in
de
x=
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
);15
3/*
sin
eva
lue
*/15
4co
rre
ctio
n=
(si
ne
_g
rad
_b
uffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/15
5i_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
156
/*co
sin
eva
lue
*/15
7in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
158
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
159
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
160
}16
1}
162
els
e16
3{
134
F.1. C Listings
164
if(
ind
ex
>-(
BU
FF
ER
SIZ
E_
SIN
E-1
))16
5{
166
ind
ex
=-
ind
ex
;16
7/*
sin
eva
lue
*/16
8co
rre
ctio
n=
(si
ne
_g
rad
_b
uffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/16
9i_
pa
th=
-(si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n);
170
/*co
sin
eva
lue
*/17
1in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
172
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
173
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
174
}17
5e
lse
if(
ind
ex
>-2
*(B
UF
FE
RS
IZE
_S
INE-1
))17
6{
177
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
178
/*si
ne
valu
e*/
179
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
180
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
181
i_p
ath
=-(
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n);
182
/*co
sin
eva
lue
*/18
3in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
184
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/18
5q
_p
ath
=-(
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n);
186
}18
7e
lse
if(
ind
ex
>-3
*(B
UF
FE
RS
IZE
_S
INE-1
))18
8{
189
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
190
/*si
ne
valu
e*/
191
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/19
2i_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
193
/*co
sin
eva
lue
*/19
4in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
195
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
196
q_
pa
th=
-(si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n);
197
}19
8e
lse
if(
ind
ex
>-4
*(B
UF
FE
RS
IZE
_S
INE-1
))19
9{
200
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
201
/*si
ne
valu
e*/
202
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
203
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
204
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n;
205
/*co
sin
eva
lue
*/20
6in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
207
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/20
8q
_p
ath
=si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n;
209
}21
0e
lse
211
{21
2in
de
x=
-(in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
));
213
/*si
ne
valu
e*/
214
corr
ect
ion
=(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*p
osi
tive
*/21
5i_
pa
th=
-(si
ne
_b
uffe
r[
ind
ex
]+co
rre
ctio
n);
216
/*co
sin
eva
lue
*/21
7in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
218
corr
ect
ion
=-(
sin
e_
gra
d_
bu
ffe
r[
ind
ex
]*re
st)>
>Q
_F
OR
MA
T;/*n
eg
ativ
e*/
219
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
]+co
rre
ctio
n;
220
}22
1}
222
}22
3}
224
225
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_22
6E
ND
OF
TH
EF
ILE
227
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
out_
filte
r
List
ing
F.31
:Fix
ed-P
oint
::ou
t_fil
ter.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2O
UT
PU
TA
ND
NO
ISE
FIL
TE
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
ou
t_fil
ter.
h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
OU
T_
FIL
TE
R_
12#
de
fine
_O
UT
_F
ILT
ER
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23lo
w-p
ass
filte
rsth
eo
ut_
bu
ffe
r_d
ow
n_
on
esi
gn
al
do
wn
sam
ple
sit
24a
nd
the
nfil
ters
itw
itha
nh
igh
-pa
ssa
nd
write
sit
to25
ou
t_b
uffe
r_d
ow
n_
two
26 27P
ara
me
ters
:28
ou
t_b
uffe
r_d
ow
n_
on
ein
pu
tb
uffe
r29
ou
t_b
uffe
r_d
ow
n_
two
ou
tpu
tb
uffe
r30
*/31
void
ou
t_fil
ter
(sh
ort
ou
t_b
uffe
r[]
,sh
ort
ou
t_b
uffe
r_d
ow
n[]);
32 33#
en
dif
/*_
OU
T_
FIL
TE
R_
*/34 35
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_36
EN
DO
FT
HE
FIL
E37
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.32
:Fix
ed-P
oint
::ou
t_fil
ter.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2O
UT
PU
TA
ND
NO
ISE
FIL
TE
R-
VE
RS
ION
FIX
ED
PO
INT
0.5
3 4fil
e:
ou
t_fil
ter.
c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
incl
ud
e"o
ut_
filte
r.h
"15 16 17
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
18g
lob
al
varib
les
19--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/20 21
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
22co
effic
ien
tso
fn
ois
elo
w-p
ass
(no
_lp
)a
fte
rd
em
od
ula
tion
23--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/24
/*O
rde
r:
13
*/25
/*P
ass
-ba
nd
:2
dB
@3
50
0.0
0H
z*/
26/*
Sto
p-b
an
d:
20
dB
@3
99
9.5
7H
z*/
27 28#
de
fine
NO
_L
P_
CA
SC
AD
ES
729
sho
rtn
o_
lp_
a[][2
]={
/*a
_i_
1a
_i_
2*/
30{
-28
88
,0
},31
{-5
86
1,
73
8},
32{
-61
24
,2
24
4},
33{
-66
00
,4
96
2},
34{
-73
52
,9
26
1},
35{
-84
97
,1
58
08
},36
{-1
02
47
,2
58
15
},37
};38 39
sho
rtn
o_
lp_
b[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
40{
13
82
2,
13
82
2,
0},
41{
72
22
,1
44
44
,7
22
2},
42{
77
83
,1
55
65
,7
78
3},
43{
86
69
,1
73
39
,8
66
9},
44{
10
02
0,
20
04
0,
10
02
0},
45{
79
47
,1
58
93
,7
94
7},
135
Listings46
{1
24
57
,2
49
14
,1
24
57
},47
};48 49
sho
rtn
o_
lp_
sca
le=
23
90
4;
/*2
98
80
*0.8
0.9
11
86
2to
avo
ido
verf
low
s*/
50 51/*
de
lay
vari
ab
els
*/52
sho
rtn
o_
lp_
z[][3
]={
53{
0,0
,0},
54{
0,0
,0},
55{
0,0
,0},
56{
0,0
,0},
57{
0,0
,0},
58{
0,0
,0},
59{
0,0
,0},
60};
61/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--62
coe
ffic
ien
tso
fe
nd
hig
h-p
ass
(en
_h
p)
be
fore
da
c63
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
64/*
Ord
er
:4
*/65
/*P
ass
-ba
nd
:0
.1d
B@
30
0.0
0H
z*/
66/*
Sto
p-b
an
d:
40
.0d
B@
50
.00
Hz
*/67 68
#d
efin
eE
N_
HP
_C
AS
CA
DE
S2
69sh
ort
en
_h
p_
a[][3
]={
/*a
a_
i_1
aa
_i_
1b
a_
i_2
*/70
{-2
91
80
,-2
91
80
,2
60
45
},71
{-3
10
46
,-3
10
46
,2
98
05
},72
};73 74
/*75
sho
rte
n_
hp
_b
[][3
]={
b_
i_0
b_
i_1
b_
i_2
76{
1,
-2,
1},
77{
1,
-2,
1},
78};
79*/
80 81sh
ort
en
_h
p_
sca
le=
13
93
1;
/*0
.5*0
.85
02
69
toa
void
ove
rflo
ws
*/82 83
#d
efin
eE
N_
HP
_U
PS
CA
LE
284 85
/*d
ela
yva
ria
be
ls*/
86sh
ort
en
_h
p_
z[][3
]={
87{
0,0
,0},
88{
0,0
,0},
89};
90 91/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--92
imp
lem
en
tatio
no
ffu
nct
ion
93--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/94
void
ou
t_fil
ter
(sh
ort
ou
t_b
uffe
r[]
,sh
ort
ou
t_b
uffe
r_d
ow
n[])
95{
96in
ti
,j
,k
;97 98
k=
0;
99 100
/*_
_th
elo
w-p
ass
__
*/10
110
2/*
sca
ling
*/10
3fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
104
{10
5o
ut_
bu
ffe
r[
i]=
(o
ut_
bu
ffe
r[
i]*
no
_lp
_sc
ale
)>>
15
;10
6}
107
108
/*a
llca
sca
de
se
xce
pt
the
last
on
e*/
109
for
(j
=0
;j
<(
NO
_L
P_
CA
SC
AD
ES-1
);j
++
)11
011
1{
112
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)11
3{
114
/*fe
ed
ba
ck*/
115
no
_lp
_z
[j
][0
]=
ou
t_b
uffe
r[
i]-
((
no
_lp
_a
[j
][0
]*n
o_
lp_
z[
j][1
]+
/*a
_1
*z1
*/11
6n
o_
lp_
a[
j][1
]*n
o_
lp_
z[
j][2
]/*
a_
2*z
2*/
117
)>>
15
);11
811
9/*
fore
wa
rd*/
120
ou
t_b
uffe
r[
i]=
(n
o_
lp_
b[
j][0
]*n
o_
lp_
z[
j][0
]+/*
b_
0*
z0*/
121
no
_lp
_b
[j
][1
]*n
o_
lp_
z[
j][1
]+/*
b_
1*
z1*/
122
no
_lp
_b
[j
][2
]*n
o_
lp_
z[
j][2
]/*
b_
2*
z2*/
123
)>>
15
;12
4
125
126
/*sh
iftd
ela
ys*/
127
no
_lp
_z
[j
][2
]=n
o_
lp_
z[
j][1
];12
8n
o_
lp_
z[
j][1
]=n
o_
lp_
z[
j][0
];12
9}
130
}13
113
2/*
last
casc
ad
ein
clu
din
gd
ow
nsa
mp
ling
*/13
3fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
134
{13
5/*
fee
db
ack
*/13
6n
o_
lp_
z[
j][0
]=
ou
t_b
uffe
r[
i]-
((
no
_lp
_a
[j
][0
]*n
o_
lp_
z[
j][1
]+
/*a
_1
*z1
*/13
7n
o_
lp_
a[
j][1
]*n
o_
lp_
z[
j][2
]/*
a_
2*z
2*/
138
)>>
15
);13
914
0/*
fore
wa
rdn
clu
din
gd
ow
nsa
mp
ling
->ta
kee
very
2n
dva
lue
*/14
1if
(i
%D
OW
NS
AM
PL
E_
TW
O=
=0
)14
2{
143
ou
t_b
uffe
r_d
ow
n[
k]=
(n
o_
lp_
b[
j][0
]*n
o_
lp_
z[
j][0
]+/*
b_
0*
z0*/
144
no
_lp
_b
[j
][1
]*n
o_
lp_
z[
j][1
]+/*
b_
1*
z1*/
145
no
_lp
_b
[j
][2
]*n
o_
lp_
z[
j][2
]/*
b_
2*
z2*/
146
)>>
15
;14
7k
++
;14
8}
149
150
/*sh
iftd
ela
ys*/
151
no
_lp
_z
[j
][2
]=n
o_
lp_
z[
j][1
];15
2n
o_
lp_
z[
j][1
]=n
o_
lp_
z[
j][0
];15
3}
154
155
156
/*_
_th
eh
igh
-pa
ss_
_*/
157
158
/*sc
alin
g*/
159
for
(i
=0
;i
<B
UF
FE
RS
IZE
_O
UT
PU
T;i
++
)16
0{
161
ou
t_b
uffe
r_d
ow
n[
i]=
(o
ut_
bu
ffe
r_d
ow
n[
i]*
en
_h
p_
sca
le)>
>1
5;
162
}16
316
4/*
hig
h-p
ass
intr
an
spo
sed
form
*/16
5fo
r(
j=
0;
j<
(E
N_
HP
_C
AS
CA
DE
S);j
++
)16
6{
167
for
(i
=0
;i
<B
UF
FE
RS
IZE
_O
UT
PU
T;i
++
)16
8{
169
en
_h
p_
z[
j][2
]=e
n_
hp
_z
[j
][1
]+o
ut_
bu
ffe
r_d
ow
n[
i];
170
171
en
_h
p_
z[
j][1
]=-
ou
t_b
uffe
r_d
ow
n[
i]-
ou
t_b
uffe
r_d
ow
n[
i]-
172
((e
n_
hp
_a
[j
][0
]*e
n_
hp
_z
[j
][2
]+17
3e
n_
hp
_a
[j
][1
]*e
n_
hp
_z
[j
][2
])>
>1
5)+
174
en
_h
p_
z[
j][0
];17
517
6e
n_
hp
_z
[j
][0
]=o
ut_
bu
ffe
r_d
ow
n[
i]-
177
((e
n_
hp
_a
[j
][2
]*e
n_
hp
_z
[j
][2
])>
>1
5);
178
ou
t_b
uffe
r_d
ow
n[
i]=
(e
n_
hp
_z
[j
][2
]);
179
}18
0}
181
for
(i
=0
;i
<B
UF
FE
RS
IZE
_O
UT
PU
T;i
++
)18
2{
183
ou
t_b
uffe
r_d
ow
n[
i]=
ou
t_b
uffe
r_d
ow
n[
i]*
EN
_H
P_
UP
SC
AL
E;18
4}
185
186
}18
718
8/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
189
EN
DO
FT
HE
FIL
E19
0_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
F.1.
4.Fi
xed-
Poin
tOpt
imiz
ed
glob
al_s
etti
ngs
List
ing
F.33
:Fix
ed-P
oint
Opt
imiz
ed::
glob
al_s
ettin
gs.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
136
F.1. C Listings
2G
LO
BA
LS
ET
TIN
GS
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
glo
ba
l_se
ttin
gs.
h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#d
efin
eB
UF
FE
RS
IZE
12
812
#d
efin
eD
OW
NS
AM
PL
E_
ON
E413
#d
efin
eD
OW
NS
AM
PL
E_
TW
O214 15
#d
efin
eB
UF
FE
RS
IZE
_IN
PU
T(
BU
FF
ER
SIZ
E)16
#d
efin
eB
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR(
BU
FF
ER
SIZ
E/D
OW
NS
AM
PL
E_
ON
E)
17#
de
fine
BU
FF
ER
SIZ
E_
OU
TP
UT
(B
UF
FE
RS
IZE/
(D
OW
NS
AM
PL
E_
ON
E*
DO
WN
SA
MP
LE
_T
WO
))18 19
#d
efin
eP
I3
.14
15
92
65
35
920 21
#d
efin
eW
OR
D_
AL
IGN
ED(x
)(
_n
ass
ert
(((
int
)(x
)&
0x3
)=
=0
))
fm_d
em_m
ain
List
ing
F.34
:Fix
ed-P
oint
Opt
imiz
ed::
fm_d
em_m
ain.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
FM
DE
MO
DU
LA
TIO
NM
AIN
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
fm_
de
m_
ma
in.c
5d
ate
:n
ov
20
01
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
de
mo
du
lato
rd
efin
e13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
de
fine
FM
_M
IXE
D_
DE
M1
015
#d
efin
eF
M_
PL
L_
DE
M2
016 17
#d
efin
eF
M_
DE
MO
DU
LA
TO
RF
M_
MIX
ED
_D
EM
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
incl
ud
es
21--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/22 23
#in
clu
de
<st
d.
h>
24#
incl
ud
e<
swi
.h
>25
#in
clu
de
<cs
l.
h>
26#
incl
ud
e<
bsl
.h
>27 28
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
29#
incl
ud
e"a
dc_
TH
S1
40
8.h
"30
#in
clu
de
"da
c_co
de
c.h
"31
#in
clu
de
"qu
ad
_m
ix.h
"32
#in
clu
de
"ou
t_fil
ter.
h"
33#
if(
FM
_D
EM
OD
UL
AT
OR
==
FM
_P
LL
_D
EM)
34#
incl
ud
e"p
ll_d
em
od
ula
te.h
"35
#e
lif(
FM
_D
EM
OD
UL
AT
OR
==
FM
_M
IXE
D_
DE
M)36
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"37
#e
lse
38#
err
or
No
de
mo
du
lato
ra
lgo
rith
md
efin
ed
39#
en
dif
40 41 42 43/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--44
de
bu
gd
efin
es
45--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/46
#d
efin
eF
M_
DE
M_
CF
_D
EB
UG
047
/*to
prin
tco
mm
en
tsto
de
bu
g_
log
*/48 49
#d
efin
eF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D0
50/*
Le
dto
gg
les
wh
en
an
inte
rru
pt
occ
urs
*/
51/*
LE
D1
cod
ec
inte
rru
pt
(ou
tpu
t)*/
52/*
LE
D2
ed
ma
inte
rru
pt
(in
pu
t)*/
53/*
LE
D3
timm
ing
err
or
*/54 55
#d
efin
eF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D0
56/*
Le
dO
Nb
yin
terr
up
tst
art
OF
Fa
tth
ee
nd
*/57
/*L
ED
1co
de
cin
terr
up
t(o
utp
ut)
*/58
/*L
ED
2e
dm
ain
terr
up
t(in
pu
t)*/
59/*
LE
D3
soft
wa
rein
terr
up
t*/
60 61#
de
fine
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
062
/*E
na
ble
ST
SO
bje
cts:
*/63
/*-d
ac_
sts
*/64
/*-d
em
od
ula
te_
sts
*/65
/*-e
dm
a_
sts
*/66
/*to
me
asu
reth
ed
ura
tion
time
of
the
inte
rru
pts
*/67 68
#d
efin
eF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S0
69/*
En
ab
leS
TS
Ob
ject
s:*/
70/*
-mix
_st
s*/
71/*
-de
m_
sts
*/72
/*-f
ilte
r_st
s*/
73/*
tom
ea
sure
the
du
ratio
ntim
eo
fth
efu
nct
ion
s*/
74 75#
ifF
M_
DE
M_
CF
_D
EB
UG
76#
incl
ud
e<
log
.h
>77
ext
ern
far
LO
G_
Ob
jd
eb
ug
_lo
g;
78#
en
dif
79 80#
ifF
FM
_D
EM
_C
F_
INT
_O
CC
UR
_L
ED
81#
incl
ud
e<
bsl
_le
d.
h>
82#
en
dif
83 84#
ifF
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
85#
incl
ud
e<
bsl
_le
d.
h>
86#
en
dif
87 88#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S89
#in
clu
de
<cl
k.
h>
90#
incl
ud
e<
sts
.h
>91
ext
ern
far
ST
S_
Ob
jd
ac_
sts
;92
ext
ern
far
ST
S_
Ob
jd
em
od
ula
te_
sts
;93
ext
ern
far
ST
S_
Ob
je
dm
a_
sts
;94
#e
nd
if95 96
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
97#
incl
ud
e<
clk
.h
>98
#in
clu
de
<st
s.
h>
99e
xte
rnfa
rS
TS
_O
bj
mix
_st
s;
100
ext
ern
far
ST
S_
Ob
jd
em
_st
s;
101
ext
ern
far
ST
S_
Ob
jfil
ter_
sts
;10
2#
en
dif
103
104
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
105
DS
P/B
IOS
ext
ern
varib
les
106
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
107
108
ext
ern
far
SW
I_O
bj
de
mo
du
late
_sw
i;
109
ext
ern
HW
I_e
na
ble
();
110
ext
ern
HW
I_d
isa
ble
();
111
112
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
113
glo
ba
lva
rib
les
114
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
115
116
#p
rag
ma
DA
TA
_M
EM
_B
AN
K(in
_b
uffe
r_A
,0
);11
7sh
ort
in_
bu
ffe
r_A
[B
UF
FE
RS
IZE
_IN
PU
T];
118
#p
rag
ma
DA
TA
_M
EM
_B
AN
K(in
_b
uffe
r_B
,0
);11
9sh
ort
in_
bu
ffe
r_B
[B
UF
FE
RS
IZE
_IN
PU
T];
120
121
#p
rag
ma
DA
TA
_M
EM
_B
AN
K(re
_b
uffe
r,
2);
122
sho
rtre
_b
uffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;12
3#
pra
gm
aD
AT
A_
ME
M_
BA
NK(
im_
bu
ffe
r,
4);
124
sho
rtim
_b
uffe
r[
BU
FF
ER
SIZ
E_
INP
UT]
;12
512
6#
pra
gm
aD
AT
A_
ME
M_
BA
NK(
ou
t_b
uffe
r,
0);
127
sho
rto
ut_
bu
ffe
r[
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R];
128
#p
rag
ma
DA
TA
_M
EM
_B
AN
K(o
ut_
bu
ffe
r_A
,6
);12
9sh
ort
ou
t_b
uffe
r_A
[B
UF
FE
RS
IZE
_O
UT
PU
T];13
0#
pra
gm
aD
AT
A_
ME
M_
BA
NK(
ou
t_b
uffe
r_B
,6
);
137
Listings13
1sh
ort
ou
t_b
uffe
r_B
[B
UF
FE
RS
IZE
_O
UT
PU
T];13
213
313
413
5sh
ort
*in
_b
uffe
r_p
tr;
136
sho
rt*
ou
t_b
uffe
r_p
tr;
137
Bo
ol
a_
inE
DM
A=
TR
UE;
138
sho
rto
utc
ou
nte
r=
0;
139
140
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
141
the
ma
infu
nct
ion
142
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
143
void
ma
in()
144
{14
5H
WI_
dis
ab
le()
;14
614
7#
ifF
M_
DE
M_
CF
_D
EB
UG
148
LO
G_
prin
tf(&
de
bu
g_
log
,"In
fo:
Be
gin
Of
ma
in")
;14
9#
en
dif
150
151
CS
L_
init
();
/*o
nch
ipin
it*/
152
BS
L_
init
();
/*o
nb
oa
rdin
it*/
153
154
ths1
40
8_
init
(in
_b
uffe
r_A
,in
_b
uffe
r_B
);15
5co
de
c_in
it()
;15
615
7in
_b
uffe
r_A
[0]=
10
;15
815
9H
WI_
en
ab
le()
;16
016
1th
s14
08
_st
art
();
162
cod
ec_
sta
rt()
;16
316
416
5#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D16
6L
ED
_o
ff(
LE
D_
AL
L);
167
#e
nd
if16
816
9#
ifF
M_
DE
M_
CF
_D
EB
UG
170
LO
G_
prin
tf(&
de
bu
g_
log
,"In
fo:
En
dO
fm
ain
");
171
#e
nd
if17
2}
173
174
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
175
ha
rdw
are
inte
rru
pt
fun
ctio
ns
176
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
177
178
void
ed
ma
Int
(vo
id)
179
{18
0#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D18
1L
ED
_to
gg
le(
LE
D_
2);
182
#e
nd
if18
318
4#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D18
5L
ED
_o
n(
LE
D_
2);
186
#e
nd
if18
718
8#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S18
9S
TS
_se
t(&
ed
ma
_st
s,
CL
K_
ge
thtim
e()
);19
0#
en
dif
191
192
/*re
set
ou
tco
un
ter
*/19
3o
utc
ou
nte
r=
0;
194
195
/*se
lect
ED
MA
cha
nn
el
*/19
6if
(E
DM
A_
intT
est
(T
HS
14
08
_B
UF
FE
R_
A_
TC
C))19
7{
198
#if
FM
_D
EM
_C
F_
DE
BU
G19
9L
OG
_p
rin
tf(&
de
bu
g_
log
,"In
_A
");
200
#e
nd
if20
1/*
Cle
ar
tra
nsf
er
com
ple
tion
inte
rru
pt
flag
*/20
2E
DM
A_
intC
lea
r(
TH
S1
40
8_
BU
FF
ER
_A
_T
CC);
203
204
/*se
tb
uffe
rp
oin
ters
*/20
5a
_in
ED
MA
=F
AL
SE;
206
in_
bu
ffe
r_p
tr=
in_
bu
ffe
r_A
;20
7o
ut_
bu
ffe
r_p
tr=
ou
t_b
uffe
r_A
;20
820
9/*
po
stso
ftw
are
inte
rru
pt
->st
art
de
mo
du
latio
n*/
210
SW
I_p
ost
(&d
em
od
ula
te_
swi
);
211
}21
2if
(E
DM
A_
intT
est
(T
HS
14
08
_B
UF
FE
R_
B_
TC
C))21
3{
214
#if
FM
_D
EM
_C
F_
DE
BU
G21
5L
OG
_p
rin
tf(&
de
bu
g_
log
,"In
_B
");
216
#e
nd
if21
7/*
Cle
ar
tra
nsf
er
com
ple
tion
inte
rru
pt
flag
*/21
8E
DM
A_
intC
lea
r(
TH
S1
40
8_
BU
FF
ER
_B
_T
CC);
219
220
/*se
tb
uffe
rp
oin
ters
*/22
1a
_in
ED
MA
=T
RU
E;22
2in
_b
uffe
r_p
tr=
in_
bu
ffe
r_B
;22
3o
ut_
bu
ffe
r_p
tr=
ou
t_b
uffe
r_B
;22
422
5/*
po
stso
ftw
are
inte
rru
pt
->st
art
de
mo
du
latio
n*/
226
SW
I_p
ost
(&d
em
od
ula
te_
swi
);22
7}
228
229
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
230
ST
S_
de
lta(&
ed
ma
_st
s,
CL
K_
ge
thtim
e()
);23
1#
en
dif
232
233
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
234
LE
D_
off
(L
ED
_2)
;23
5#
en
dif
236
}23
723
8vo
idd
acI
nt
(vo
id)
239
{24
0#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D24
1L
ED
_to
gg
le(
LE
D_
1);
242
#e
nd
if24
324
4#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D24
5L
ED
_o
n(
LE
D_
1);
246
#e
nd
if24
724
8#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S24
9S
TS
_se
t(&
da
c_st
s,
CL
K_
ge
thtim
e()
);25
0#
en
dif
251
252
/*in
terp
ola
tea
mis
sin
gsa
mp
le*/
253
if(
ou
tco
un
ter
>1
5)
254
{25
5#
ifF
M_
DE
M_
CF
_IN
T_
OC
CU
R_
LE
D25
6L
ED
_to
gg
le(
LE
D_
3);
257
#e
nd
if25
8/*
sele
ctth
eb
uffe
r*/
259
if(
a_
inE
DM
A)
260
{26
1A
D5
35
_H
WI_
write
(o
utA
D5
35
h,(
(o
ut_
bu
ffe
r_A
[15
]+o
ut_
bu
ffe
r_B
[0])
/2))
;26
2#
ifF
M_
DE
M_
CF
_D
EB
UG
263
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
Ae
rro
r:%
d",
ou
tco
un
ter
);26
4#
en
dif
265
}e
lse
266
{26
7A
D5
35
_H
WI_
write
(o
utA
D5
35
h,(
(o
ut_
bu
ffe
r_B
[15
]+o
ut_
bu
ffe
r_A
[0])
/2))
;26
8#
ifF
M_
DE
M_
CF
_D
EB
UG
269
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
Be
rro
r:%
d",
ou
tco
un
ter
);27
0#
en
dif
271
}27
2}
els
e/*
ou
tpu
ta
valu
e*/
273
{27
4/*
sele
ctth
eb
uffe
r*/
275
if(
a_
inE
DM
A)
276
{27
7A
D5
35
_H
WI_
write
(o
utA
D5
35
h,
ou
t_b
uffe
r_A
[o
utc
ou
nte
r])
;27
8#
ifF
M_
DE
M_
CF
_D
EB
UG
279
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
A:%
d",
ou
tco
un
ter
);28
0#
en
dif
281
}e
lse
282
{28
3A
D5
35
_H
WI_
write
(o
utA
D5
35
h,
ou
t_b
uffe
r_B
[o
utc
ou
nte
r])
;28
4#
ifF
M_
DE
M_
CF
_D
EB
UG
285
LO
G_
prin
tf(&
de
bu
g_
log
,"O
ut
B:%
d",
ou
tco
un
ter
);28
6#
en
dif
287
}28
8/*
up
da
teo
utc
ou
nte
r*/
289
ou
tco
un
ter
++
;29
0}
138
F.1. C Listings
291
292
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
293
ST
S_
de
lta(&
da
c_st
s,
CL
K_
ge
thtim
e()
);29
4#
en
dif
295
296
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
297
LE
D_
off
(L
ED
_1)
;29
8#
en
dif
299
}30
030
1/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--30
2so
ftw
are
inte
rru
pt
fun
ctio
ns
303
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
304
305
void
de
mo
du
late
Sw
iFu
nc
(vo
id)
306
{30
7in
ti
;30
830
9#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
LE
D31
0L
ED
_o
n(
LE
D_
3);
311
#e
nd
if31
231
3#
ifF
M_
DE
M_
CF
_IN
T_
TIM
E_
ST
S31
4S
TS
_se
t(&
de
mo
du
late
_st
s,
CL
K_
ge
thtim
e()
);31
5#
en
dif
316
317
for
(i
=0
;i
<B
UF
FE
RS
IZE
_IN
PU
T;i
++
)31
8{
319
in_
bu
ffe
r_p
tr[
i]=
in_
bu
ffe
r_p
tr[
i]<
<2
;32
0}
321
322
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
323
ST
S_
set
(&m
ix_
sts
,C
LK
_g
eth
time
());
324
#e
nd
if32
5q
ua
d_
mix
(in
_b
uffe
r_p
tr,
re_
bu
ffe
r,
im_
bu
ffe
r);
326
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
327
ST
S_
de
lta(&
mix
_st
s,
CL
K_
ge
thtim
e()
);32
8#
en
dif
329
330
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
331
ST
S_
set
(&d
em
_st
s,
CL
K_
ge
thtim
e()
);33
2#
en
dif
333
#if
(F
M_
DE
MO
DU
LA
TO
R=
=F
M_
PL
L_
DE
M)33
4p
ll_d
em
od
ula
te(
re_
bu
ffe
r,
im_
bu
ffe
r,
ou
t_b
uffe
r);
335
#e
lif(
FM
_D
EM
OD
UL
AT
OR
==
FM
_M
IXE
D_
DE
M)33
6m
ixe
d_
de
mo
du
late
(re
_b
uffe
r,
im_
bu
ffe
r,
ou
t_b
uffe
r);
337
#e
lse
338
#e
rro
rN
od
em
od
ula
tor
alg
orith
md
efin
ed
339
#e
nd
if34
0#
ifF
M_
DE
M_
CF
_F
UN
C_
TIM
E_
ST
S34
1S
TS
_d
elta
(&d
em
_st
s,
CL
K_
ge
thtim
e()
);34
2#
en
dif
343
344
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
345
ST
S_
set
(&fil
ter_
sts
,C
LK
_g
eth
time
());
346
#e
nd
if34
7o
ut_
filte
r(
ou
t_b
uffe
r,
ou
t_b
uffe
r_p
tr);
348
#if
FM
_D
EM
_C
F_
FU
NC
_T
IME
_S
TS
349
ST
S_
de
lta(&
filte
r_st
s,
CL
K_
ge
thtim
e()
);35
0#
en
dif
351
352
#if
FM
_D
EM
_C
F_
INT
_T
IME
_S
TS
353
ST
S_
de
lta(&
de
mo
du
late
_st
s,
CL
K_
ge
thtim
e()
);35
4#
en
dif
355
356
#if
FM
_D
EM
_C
F_
INT
_T
IME
_L
ED
357
LE
D_
off
(L
ED
_3)
;35
8#
en
dif
359
}
quad
_mix
List
ing
F.35
:Fix
ed-P
oint
Opt
imiz
ed::
quad
_mix
.h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_
2Q
UA
DR
AT
UR
EM
IXE
R-
VE
RS
ION
FIX
ED
PO
INT
13 4
file
:q
ua
d_
mix
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
QU
AD
_M
IX_
12#
de
fine
_Q
UA
D_
MIX
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23th
esi
gn
al
inth
ein
_b
uffe
ris
qu
ad
ratu
rem
ixe
dto
the
two
24b
uffe
rsre
_b
uffe
ra
nd
im_
bu
ffe
ra
nd
isa
lso
do
wn
sam
ple
db
y25
DO
WN
SA
MP
LE
_O
NE
26 27P
ara
me
ters
:28
in_
bu
ffe
rb
uff
er
with
inp
ut
sig
na
l29
re_
bu
ffe
rb
uff
er
of
sig
na
lm
ixe
dw
ithco
sin
e30
ou
t_b
uffe
rb
uff
er
of
sig
na
lm
ixe
dw
ithsi
ne
31*/
32e
xte
rnvo
idq
ua
d_
mix
(sh
ort
in_
bu
ffe
r[]
,sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]);
33 34#
en
dif
/*_
QU
AD
_M
IX_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.36
:Fix
ed-P
oint
Opt
imiz
ed::
quad
_mix
.c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
QU
AD
RA
TU
RE
MIX
ER
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
qu
ad
_m
ix.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"qu
ad
_m
ix.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19 20
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
21co
effic
ien
tso
fsi
ne
an
dco
sin
eo
szila
tor
22--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/23
/*F
req
ue
ncy
:1
31
39
.93
HZ
*/24 25
sho
rtg
en
_b
0_
cos
=1
65
83
;/*
cos*
/26
sho
rtg
en
_b
1_
cos
=-4
59
3;
/*co
s*/
27sh
ort
ge
n_
b1
_si
n=
-15
93
4;
/*si
n*/
28sh
ort
ge
n_
a1
=-1
81
52
;/*
sin
/co
s*/
29 30/*
de
lay
vari
ab
els
*/31
sho
rtg
en
_z
[3]
={0
,0,2
62
13
};/*
0.8
for
first
valu
eo
fd
elta
fun
ctio
n*/
32 33/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--34
coe
ffic
ien
tso
fm
ixe
rlo
w-p
ass
(mix
_lp
)35
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
36/*
Ord
er
:5
*/37
/*P
ass
-ba
nd
:2
dB
@6
30
0.0
0H
z*/
38/*
Sto
p-b
an
d:
60
dB
@1
90
00
.00
Hz
*/39
139
Listings40
#d
efin
eM
IX_
LP
_C
AS
CA
DE
S3
41sh
ort
mix
_lp
_a
[][3
]={
/*a
_i_
1a
a_
i_1
ba
_i_
2*/
42{
-80
92
,-8
09
2,
0},
43{
-17
44
4,
-17
44
4,
11
16
6},
44{
-21
90
7,
-21
90
7,
22
40
6},
45};
46 47sh
ort
mix
_lp
_b
[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
48{
45
23
,4
52
3,
0},
49{
27
25
,5
45
0,
27
25
},50
{8
53
7,
17
07
4,
85
37
},51
};52 53
/*S
calin
gin
clu
de
din
ou
tpu
to
fo
szis
*/54 55
/*d
ela
yva
ria
be
ls*/
56sh
ort
mix
_lp
_z_
re[][3
]={
57{
0,0
,0},
58{
0,0
,0},
59{
0,0
,0},
60};
61sh
ort
mix
_lp
_z_
im[][3
]={
62{
0,0
,0},
63{
0,0
,0},
64{
0,0
,0},
65};
66 67/*
de
lay
varia
be
ls*/
68sh
ort
as_
mix
_lp
_z_
re[][3
]={
69{
0,0
,0},
70{
0,0
,0},
71{
0,0
,0},
72};
73sh
ort
as_
mix
_lp
_z_
im[][3
]={
74{
0,0
,0},
75{
0,0
,0},
76{
0,0
,0},
77};
78 79/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--80
imp
lem
en
tatio
no
ffu
nct
ion
81--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/82 83
/*im
ple
me
nta
tion
inlin
ea
ra
sse
mb
lyin
84fil
eq
ua
d_
mix
_lin
_a
ss!!!
*/85 86
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_87
EN
DO
FT
HE
FIL
E88
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
mix
ed_d
emod
ulat
e
List
ing
F.37
:Fix
ed-P
oint
Opt
imiz
ed::
mix
ed_d
emod
ulat
e.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2M
IXE
DD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
mix
ed
_d
em
od
ula
te.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_M
IXE
D_
DE
MO
DU
LA
TE
_12
#d
efin
e_
MIX
ED
_D
EM
OD
UL
AT
E_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18#
incl
ud
e"a
tan
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s
22--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/23
/*24
FM
de
mo
du
late
sth
eth
etw
ob
ase
ba
nd
sig
na
lre
_b
uffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
em
ixe
da
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
mix
ed
_d
em
od
ula
te(
sho
rtre
_b
uffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
MIX
ED
_D
EM
OD
UL
AT
E_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.38
:Fix
ed-P
oint
Opt
imiz
ed::
mix
ed_d
emod
ulat
e.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2M
IXE
DD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
mix
ed
_d
em
od
ula
te.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
/*d
ela
yva
rib
ale
so
fth
em
ixe
dd
em
od
ula
tor
*/20
sho
rtd
em
_z_
re=
16
38
4;
/*!=
0to
avo
idd
ivis
ion
with
0*/
21sh
ort
de
m_
z_im
=1
63
84
;/*
!=0
toa
void
div
isio
nw
ith0
*/22 23
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
24im
ple
me
nta
tion
of
fun
ctio
n25
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
26vo
idm
ixe
d_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[
rest
rict
],
sho
rtim
_b
uffe
r[
rest
rict
],
sho
rto
ut_
bu
ffe
r[
rest
rict
])27
{28
int
i;
29in
tre
_p
ath
=0
;30
int
im_
pa
th=
0;
31in
td
em
_a
rg=
0;
32 33W
OR
D_
AL
IGN
ED(re
_b
uffe
r);
34W
OR
D_
AL
IGN
ED(im
_b
uffe
r);
35W
OR
D_
AL
IGN
ED(o
ut_
bu
ffe
r);
36 37fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
38{
39re
_p
ath
=(
im_
bu
ffe
r[
i]*
de
m_
z_re
-re
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/40
im_
pa
th=
(re
_b
uffe
r[
i]*
de
m_
z_re
+im
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/41 42
/*sh
iftd
ela
ys*/
43d
em
_z_
re=
re_
bu
ffe
r[
i];
44d
em
_z_
im=
im_
bu
ffe
r[
i];
45 46/*
calc
ula
teth
ea
rgu
me
nt
*/47
de
m_
arg
=re
_p
ath
/(im
_p
ath
>>
14
);/*
Q1
7.1
4*/
48 49/*
ata
nlo
oku
p*/
50if
(d
em
_a
rg>
0)
/*p
osi
tiv*/
51{
52d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;53
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;54
ou
t_b
uffe
r[
i]=
ata
n_
bu
ffe
r[
de
m_
arg
];55
}e
lse
/*n
eg
ativ
e*/
56{
57d
em
_a
rg=
-d
em
_a
rg;
58d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;
140
F.1. C Listings
59if
(d
em
_a
rg>
=B
UF
FE
RS
IZE
_A
TA
N)d
em
_a
rg=
BU
FF
ER
SIZ
E_
AT
AN-
1;
60o
ut_
bu
ffe
r[
i]=
-a
tan
_b
uffe
r[
de
m_
arg
];61
}62 63
}64
}65 66
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_67
EN
DO
FT
HE
FIL
E68
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.39
:Fix
ed-P
oint
Opt
imiz
edIn
terp
olat
ed::
mix
ed_d
emod
ulat
e.h
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2M
IXE
DD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
mix
ed
_d
em
od
ula
te.h
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11#
ifnd
ef
_M
IXE
D_
DE
MO
DU
LA
TE
_12
#d
efin
e_
MIX
ED
_D
EM
OD
UL
AT
E_
13 14/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18#
incl
ud
e"a
tan
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24F
Md
em
od
ula
tes
the
the
two
ba
seb
an
dsi
gn
al
re_
bu
ffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
em
ixe
da
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
mix
ed
_d
em
od
ula
te(
sho
rtre
_b
uffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
MIX
ED
_D
EM
OD
UL
AT
E_
*/35 36
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_37
EN
DO
FT
HE
FIL
E38
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.40
:Fix
ed-P
oint
Opt
imiz
edIn
terp
olat
ed::
mix
ed_d
emod
ulat
e.c
1/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2M
IXE
DD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
mix
ed
_d
em
od
ula
te.c
5d
ate
:o
ct2
00
1-
jan
20
02
6b
y:
c.h
alle
r7
f.sc
hn
yde
r8
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9*/
10 11/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--12
incl
ud
es
13--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/14
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
/*d
ela
yva
rib
ale
so
fth
em
ixe
dd
em
od
ula
tor
*/
20sh
ort
de
m_
z_re
=1
63
84
;/*
!=0
toa
void
div
isio
nw
ith0
*/21
sho
rtd
em
_z_
im=
16
38
4;
/*!=
0to
avo
idd
ivis
ion
with
0*/
22 23/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--24
imp
lem
en
tatio
no
ffu
nct
ion
25--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/26
void
mix
ed
_d
em
od
ula
te(
sho
rtre
_b
uffe
r[
rest
rict
],
sho
rtim
_b
uffe
r[
rest
rict
],
sho
rto
ut_
bu
ffe
r[
rest
rict
])27
{28
int
i;
29in
tre
_p
ath
=0
;30
int
im_
pa
th=
0;
31in
td
em
_a
rg=
0;
32sh
ort
cuto
ff=
0;
33 34W
OR
D_
AL
IGN
ED(re
_b
uffe
r);
35W
OR
D_
AL
IGN
ED(im
_b
uffe
r);
36W
OR
D_
AL
IGN
ED(o
ut_
bu
ffe
r);
37 38 39fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
40{
41 42re
_p
ath
=(
im_
bu
ffe
r[
i]*
de
m_
z_re
-re
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/43
im_
pa
th=
(re
_b
uffe
r[
i]*
de
m_
z_re
+im
_b
uffe
r[
i]*
de
m_
z_im
)<<
1;
/*Q
.31
*/44 45
/*sh
iftd
ela
ys*/
46d
em
_z_
re=
re_
bu
ffe
r[
i];
47d
em
_z_
im=
im_
bu
ffe
r[
i];
48 49/*
calc
ula
teth
ea
rgu
me
nt
*/50
de
m_
arg
=re
_p
ath
/(im
_p
ath
>>
14
);/*
Q1
7.1
4*/
51 52/*
ata
nlo
oku
p*/
53if
(d
em
_a
rg>
0)
/*p
osi
tiv*/
54{
55cu
toff
=d
em
_a
rg%
AT
AN
_IN
TE
RP
OL;
56d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;57
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;58
ou
t_b
uffe
r[
i]=
ata
n_
bu
ffe
r[
de
m_
arg
]+((
cuto
ff*
ata
n_
gra
d_
bu
ffe
r[
de
m_
arg
])>
>A
TA
N_
SH
IFT)
;59
}e
lse
/*n
eg
ativ
e*/
60{
61 62d
em
_a
rg=
-d
em
_a
rg;
63cu
toff
=d
em
_a
rg%
AT
AN
_IN
TE
RP
OL;
64d
em
_a
rg=
de
m_
arg
>>
(A
TA
N_
SH
IFT)
;65
if(
de
m_
arg
>=
BU
FF
ER
SIZ
E_
AT
AN)
de
m_
arg
=B
UF
FE
RS
IZE
_A
TA
N-1
;66
ou
t_b
uffe
r[
i]=
-(a
tan
_b
uffe
r[
de
m_
arg
]+((
cuto
ff*
ata
n_
gra
d_
bu
ffe
r[
de
m_
arg
])>
>A
TA
N_
SH
IFT)
);67
}68
}69
}70 71
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_72
EN
DO
FT
HE
FIL
E73
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
pll_
dem
odul
ate
List
ing
F.41
:Fix
ed-P
oint
Opt
imiz
ed::
pll_
dem
odul
ate.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
PL
LD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
pll_
de
mo
du
late
.h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
PL
L_
DE
MO
DU
LA
TE
_12
#d
efin
e_
PL
L_
DE
MO
DU
LA
TE
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
141
Listings15
incl
ud
es
16--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/17
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
18#
incl
ud
e"s
ine
.h"
19 20/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--21
glo
ba
lfu
nct
ion
s22
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
23/*
24F
Md
em
od
ula
tes
the
the
two
ba
seb
an
dsi
gn
al
re_
bu
ffe
ra
nd
im_
bu
ffe
r25
into
the
ou
t_b
uffe
rw
ithth
ep
lla
lgo
rith
m26 27
Pa
ram
ete
rs:
28re
_b
uffe
rre
el
FM
pa
thin
ba
seb
an
d29
im_
bu
ffe
rim
ag
FM
pa
thin
ba
seb
an
d30
ou
t_b
uffe
rd
em
od
ula
ted
sig
na
l31
*/32
void
pll_
de
mo
du
late
(sh
ort
re_
bu
ffe
r[]
,sh
ort
im_
bu
ffe
r[]
,sh
ort
ou
t_b
uffe
r[]);
33 34#
en
dif
/*_
PL
L_
DE
MO
DU
LA
TE
_*/
35 36/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
37E
ND
OF
TH
EF
ILE
38_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
List
ing
F.42
:Fix
ed-P
oint
Opt
imiz
ed::
pll_
dem
odul
ate.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
PL
LD
EM
OD
UL
AT
OR
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
pll_
de
mo
du
late
.c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
incl
ud
e"p
ll_d
em
od
ula
te.h
"15 16
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
17g
lob
al
varib
les
18--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/19
sho
rta
rg=
0;
/*a
rgu
me
nt
of
sin
ea
nd
cosi
ne
*/20
sho
rti_
pa
th=
10
00
;/*
Ip
ath
*/21
sho
rtq
_p
ath
=0
;/*
Qp
ath
*/22 23
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
24g
lob
al
de
fine
s25
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
26#
de
fine
P_
PL
L6
55
36
/*P
_P
LL
=2
.0,
usi
ng
q1
5*/
27#
de
fine
K_
PL
L1
02
40
/*K
_P
LL
=2
.5,
usi
ng
q3
.12
*/28
#d
efin
eG
AIN
_P
LL
55
70
5/*
GA
IN_
PL
L=
1.7
,u
sin
gq
15
*/29
#d
efin
eT
WO
_P
I2
57
35
/*2
*PI,
usi
ng
q3
.12
*/30 31 32
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
33im
ple
me
nta
tion
of
fun
ctio
n34
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
35vo
idp
ll_d
em
od
ula
te(
sho
rtre
_b
uffe
r[
rest
rict
],
sho
rtim
_b
uffe
r[
rest
rict
],
sho
rto
ut_
bu
ffe
r[
rest
rict
])36
{37
int
i;
38in
tfla
g=
0;
39 40sh
ort
de
mo;
/*in
de
xfo
rsi
ne
_b
uffe
ra
cce
ss*/
41sh
ort
ind
ex
;/*
valu
eo
fd
em
od
ula
tion
*/42 43
WO
RD
_A
LIG
NE
D(re
_b
uffe
r);
44W
OR
D_
AL
IGN
ED(im
_b
uffe
r);
45W
OR
D_
AL
IGN
ED(o
ut_
bu
ffe
r);
46 47 48fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
49{
50/*
__
calc
ula
tion
of
de
mo
du
late
dva
lue
,u
sin
gQ
15
__
*/51
52i_
pa
th=
(re
_b
uffe
r[
i]*
i_p
ath
)>>
15
;53
q_
pa
th=
(im
_b
uffe
r[
i]*
q_
pa
th)>
>1
5;
54 55d
em
o=q
_p
ath
-i_
pa
th;
56d
em
o=(
de
mo*
P_
PL
L)>
>1
5;
57 58o
ut_
bu
ffe
r[
i]=
(d
em
o*G
AIN
_P
LL
)>>
15
;59 60 61
/*_
_su
mm
atio
no
fd
em
od
ula
ted
sig
na
l,u
sin
gQ
3.1
2_
_*/
62 63d
em
o=d
em
o>>
3;
64a
rg=
arg
+((
de
mo*
K_
PL
L)>
>1
2);
65 66 67/*
__
limita
tion
of
arg
um
en
tto
2*P
I,u
sin
gQ
3.1
2_
_*/
68 69if
(a
rg>
TW
O_
PI)
70{
71a
rg=
arg
-T
WO
_P
I;72
}73 74
els
eif
(a
rg<
-T
WO
_P
I)75
{76
arg
=a
rg+
TW
O_
PI;
77}
78 79 80/*
__
calc
ula
tion
of
sin
ea
nd
cosi
ne
valu
eo
fa
rgu
me
nt_
_*/
81 82/*
calc
ula
ting
of
ind
ex
for
sin
e_
bu
ffe
ra
cce
ss,
usi
ng
ne
wQ
form
at*
/83 84
ind
ex
=a
rg>
>R
ED
UC
TIO
N;85 86
if(
ind
ex
<0
)87
{88
ind
ex
=-
ind
ex
;89
flag
=1
;90
}91 92
ind
ex
=(
ind
ex
*S
TE
P_
INV
ER
SE)
>>
(2*
Q_
FO
RM
AT);
93 94if
(fla
g=
=1
)95
{96
ind
ex
=-
ind
ex
;97
flag
=0
;98
}99 100
/*a
cce
sso
nsi
ne
_b
uffe
rw
ithin
de
x*/
101
102
if(
ind
ex
>=
0)
103
{10
4if
(in
de
x<
(B
UF
FE
RS
IZE
_S
INE-1
))10
5{
106
/*si
ne
valu
e*/
107
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];10
8/*
cosi
ne
valu
e*/
109
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
110
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];11
1}
112
els
eif
(in
de
x<
2*(
BU
FF
ER
SIZ
E_
SIN
E-1
))11
3{
114
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);11
5/*
sin
eva
lue
*/11
6in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
117
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];11
8/*
cosi
ne
valu
e*/
119
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
120
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];12
1}
122
els
eif
(in
de
x<
3*(
BU
FF
ER
SIZ
E_
SIN
E-1
))12
3{
124
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);12
5/*
sin
eva
lue
*/12
6i_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];12
7/*
cosi
ne
valu
e*/
128
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
129
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];13
0}
131
els
eif
(in
de
x<
4*(
BU
FF
ER
SIZ
E_
SIN
E-1
))
142
F.1. C Listings
132
{13
3in
de
x=
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
);13
4/*
sin
eva
lue
*/13
5in
de
x=
(B
UF
FE
RS
IZE
_S
INE-1
)-in
de
x;
136
i_p
ath
=-
sin
e_
bu
ffe
r[
ind
ex
];13
7/*
cosi
ne
valu
e*/
138
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
139
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];14
0}
141
els
e14
2{
143
ind
ex
=in
de
x%
(BU
FF
ER
SIZ
E_
SIN
E-1
);14
4/*
sin
eva
lue
*/14
5i_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];14
6/*
cosi
ne
valu
e*/
147
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
148
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];14
9}
150
}15
1e
lse
152
{15
3if
(in
de
x>
-(B
UF
FE
RS
IZE
_S
INE-1
))15
4{
155
ind
ex
=-
ind
ex
;15
6/*
sin
eva
lue
*/15
7i_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];15
8/*
cosi
ne
valu
e*/
159
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
160
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];16
1}
162
els
eif
(in
de
x>
-2*(
BU
FF
ER
SIZ
E_
SIN
E-1
))16
3{
164
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
165
/*si
ne
valu
e*/
166
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
167
i_p
ath
=-
sin
e_
bu
ffe
r[
ind
ex
];16
8/*
cosi
ne
valu
e*/
169
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
170
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];17
1}
172
els
eif
(in
de
x>
-3*(
BU
FF
ER
SIZ
E_
SIN
E-1
))17
3{
174
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
175
/*si
ne
valu
e*/
176
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];17
7/*
cosi
ne
valu
e*/
178
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
179
q_
pa
th=
-si
ne
_b
uffe
r[
ind
ex
];18
0}
181
els
eif
(in
de
x>
-4*(
BU
FF
ER
SIZ
E_
SIN
E-1
))18
2{
183
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
184
/*si
ne
valu
e*/
185
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
186
i_p
ath
=si
ne
_b
uffe
r[
ind
ex
];18
7/*
cosi
ne
valu
e*/
188
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
189
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];19
0}
191
els
e19
2{
193
ind
ex
=-(
ind
ex
%(B
UF
FE
RS
IZE
_S
INE-1
));
194
/*si
ne
valu
e*/
195
i_p
ath
=-
sin
e_
bu
ffe
r[
ind
ex
];19
6/*
cosi
ne
valu
e*/
197
ind
ex
=(
BU
FF
ER
SIZ
E_
SIN
E-1
)-in
de
x;
198
q_
pa
th=
sin
e_
bu
ffe
r[
ind
ex
];19
9}
200
}20
1}
202
}20
320
4/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
205
EN
DO
FT
HE
FIL
E20
6_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
out_
filte
r
List
ing
F.43
:Fix
ed-P
oint
Opt
imiz
ed::
out_
filte
r.h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
OU
TP
UT
AN
DN
OIS
EF
ILT
ER
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
ou
t_fil
ter.
h5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
#ifn
de
f_
OU
T_
FIL
TE
R_
12#
de
fine
_O
UT
_F
ILT
ER
_13 14
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
15in
clu
de
s16
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
17#
incl
ud
e"g
lob
al_
settin
gs.
h"
18 19/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--20
glo
ba
lfu
nct
ion
s21
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
22/*
23lo
w-p
ass
filte
rsth
eo
ut_
bu
ffe
r_d
ow
n_
on
esi
gn
al
do
wn
sam
ple
sit
24a
nd
the
nfil
ters
itw
itha
nh
igh
-pa
ssa
nd
write
sit
to25
ou
t_b
uffe
r_d
ow
n_
two
26 27P
ara
me
ters
:28
ou
t_b
uffe
r_d
ow
n_
on
ein
pu
tb
uffe
r29
ou
t_b
uffe
r_d
ow
n_
two
ou
tpu
tb
uffe
r30
*/31
void
ou
t_fil
ter
(sh
ort
ou
t_b
uffe
r[]
,sh
ort
ou
t_b
uffe
r_d
ow
n[]);
32 33#
en
dif
/*_
OU
T_
FIL
TE
R_
*/34 35
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_36
EN
DO
FT
HE
FIL
E37
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.44
:Fix
ed-P
oint
Opt
imiz
ed::
out_
filte
r.c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
OU
TP
UT
AN
DN
OIS
EF
ILT
ER
-V
ER
SIO
NF
IXE
DP
OIN
T1
3 4fil
e:
ou
t_fil
ter.
c5
da
te:
oct
20
01
-ja
n2
00
26
by
:c.
ha
ller
7f.
sch
nyd
er
8_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9
*/10 11
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
12in
clu
de
s13
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
14#
incl
ud
e"o
ut_
filte
r.h
"15 16 17
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
18g
lob
al
varib
les
19--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/20 21
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
22co
effic
ien
tso
fn
ois
elo
w-p
ass
(no
_lp
)a
fte
rd
em
od
ula
tion
23--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/24
/*O
rde
r:
13
*/25
/*P
ass
-ba
nd
:2
dB
@3
50
0.0
0H
z*/
26/*
Sto
p-b
an
d:
20
dB
@3
99
9.5
7H
z*/
27 28#
de
fine
NO
_L
P_
CA
SC
AD
ES
729
sho
rtn
o_
lp_
a[][2
]={
/*a
_i_
1a
_i_
2*/
30{
-28
88
,0
},31
{-5
86
1,
73
8},
32{
-61
24
,2
24
4},
33{
-66
00
,4
96
2},
34{
-73
52
,9
26
1},
143
Listings35
{-8
49
7,
15
80
8},
36{
-10
24
7,
25
81
5},
37};
38 39sh
ort
no
_lp
_b
[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
40{
13
82
2,
13
82
2,
0},
41{
72
22
,1
44
44
,7
22
2},
42{
77
83
,1
55
65
,7
78
3},
43{
86
69
,1
73
39
,8
66
9},
44{
10
02
0,
20
04
0,
10
02
0},
45{
79
47
,1
58
93
,7
94
7},
46{
52
96
,1
05
92
,5
29
6},
47};
48 49/*
sho
rtn
o_
lp_
sca
le=
23
90
4;*
//*
0.9
11
86
2*0
.8to
avo
ido
verf
low
s*/
50 51/*
de
lay
vari
ab
els
*/52
sho
rtn
o_
lp_
z[][3
]={
53{
0,0
,0},
54{
0,0
,0},
55{
0,0
,0},
56{
0,0
,0},
57{
0,0
,0},
58{
0,0
,0},
59{
0,0
,0},
60};
61 62/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--63
coe
ffic
ien
tso
fe
nd
hig
h-p
ass
(en
_h
p)
be
fore
da
c64
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
65/*
Ord
er
:4
*/66
/*P
ass
-ba
nd
:0
.1d
B@
30
0.0
0H
z*/
67/*
Sto
p-b
an
d:
40
.0d
B@
50
.00
Hz
*/68 69
#d
efin
eE
N_
HP
_C
AS
CA
DE
S2
70sh
ort
en
_h
p_
a[][3
]={
/*a
a_
i_1
aa
_i_
1b
a_
i_2
*/71
{-2
91
80
,-2
91
80
,2
60
45
},72
{-3
10
46
,-3
10
46
,2
98
05
},73
};74 75
/*76
sho
rte
n_
hp
_b
[][3
]={
b_
i_0
b_
i_1
b_
i_2
77{
1,
-2,
1},
78{
1,
-2,
1},
79};
80*/
81 82sh
ort
en
_h
p_
sca
le=
13
93
1;
/*0
.5*0
.85
02
69
toa
void
ove
rflo
ws
*/83 84
#d
efin
eE
N_
HP
_U
PS
CA
LE
285 86
/*d
ela
yva
ria
be
ls*/
87sh
ort
en
_h
p_
z[][3
]={
88{
0,0
,0},
89{
0,0
,0},
90};
91 92/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--93
imp
lem
en
tatio
no
ffu
nct
ion
94--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/95
void
ou
t_fil
ter
(sh
ort
ou
t_b
uffe
r[
rest
rict
],
sho
rto
ut_
bu
ffe
r_d
ow
n[
rest
rict
])96
{97
int
i,
j,
k;
98 99W
OR
D_
AL
IGN
ED(o
ut_
bu
ffe
r);
100
WO
RD
_A
LIG
NE
D(o
ut_
bu
ffe
r_d
ow
n);
101
102
k=
0;
103
104
/*_
_th
elo
w-p
ass
__
*/10
510
6/*
all
casc
ad
es
exc
ep
tfis
rtth
ela
sto
ne
*/10
7fo
r(
j=
0;
j<
(N
O_
LP
_C
AS
CA
DE
S-1);
j+
+)
108
109
{11
0fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
111
{11
2/*
fee
db
ack
*/11
3n
o_
lp_
z[
j][0
]=
ou
t_b
uffe
r[
i]-
((
no
_lp
_a
[j
][0
]*n
o_
lp_
z[
j][1
]+
/*a
_1
*z1
*/
114
no
_lp
_a
[j
][1
]*n
o_
lp_
z[
j][2
]/*
a_
2*z
2*/
115
)>>
15
);11
611
7/*
fore
wa
rd*/
118
ou
t_b
uffe
r[
i]=
(n
o_
lp_
b[
j][0
]*n
o_
lp_
z[
j][0
]+/*
b_
0*
z0*/
119
no
_lp
_b
[j
][1
]*n
o_
lp_
z[
j][1
]+/*
b_
1*
z1*/
120
no
_lp
_b
[j
][2
]*n
o_
lp_
z[
j][2
]/*
b_
2*
z2*/
121
)>>
15
;12
212
312
4/*
shift
de
lays
*/12
5n
o_
lp_
z[
j][2
]=n
o_
lp_
z[
j][1
];12
6n
o_
lp_
z[
j][1
]=n
o_
lp_
z[
j][0
];12
7}
128
}12
913
0/*
last
casc
ad
ein
clu
din
gd
ow
nsa
mp
ling
*/13
1fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R;
i+
+)
132
{13
3/*
fee
db
ack
*/13
4n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES-1
][0
]=
ou
t_b
uffe
r[
i]-
((
no
_lp
_a
[N
O_
LP
_C
AS
CA
DE
S-1
][0
]*n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES-1
][1
]+
/*a
_1
*z1
*/13
5n
o_
lp_
a[
NO
_L
P_
CA
SC
AD
ES-1
][1
]*n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES-1
][2
]/*
a_
2*z
2*/
136
)>>
15
);13
713
8/*
fore
wa
rdn
clu
din
gd
ow
nsa
mp
ling
->ta
kee
very
2n
dva
lue
*/13
9if
(i
%D
OW
NS
AM
PL
E_
TW
O=
=0
)14
0{
141
ou
t_b
uffe
r_d
ow
n[
k]=
(n
o_
lp_
b[
NO
_L
P_
CA
SC
AD
ES-1
][0
]*n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES
-1][0
]+/*
b_
0*
z0*/
142
no
_lp
_b
[N
O_
LP
_C
AS
CA
DE
S-1][1
]*n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES
-1][1
]+/*
b_
1*
z1*/
143
no
_lp
_b
[N
O_
LP
_C
AS
CA
DE
S-1][2
]*n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES
-1][2
]/*
b_
2*
z2*/
144
)>>
15
;14
5k
++
;14
6}
147
148
/*sh
iftd
ela
ys*/
149
no
_lp
_z
[N
O_
LP
_C
AS
CA
DE
S-1][2
]=n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES-1
][1
];15
0n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES-1
][1
]=n
o_
lp_
z[
NO
_L
P_
CA
SC
AD
ES-1
][0
];15
1}
152
153
154
/*_
_th
eh
igh
-pa
ss_
_*/
155
156
/*h
igh
-pa
ssin
tra
nsp
ose
dfo
rm*/
157
for
(j
=0
;j
<(
EN
_H
P_
CA
SC
AD
ES);
j+
+)
158
{15
9fo
r(
i=
0;
i<
BU
FF
ER
SIZ
E_
OU
TP
UT;i
++
)16
0{
161
en
_h
p_
z[
j][2
]=e
n_
hp
_z
[j
][1
]+o
ut_
bu
ffe
r_d
ow
n[
i];
162
163
en
_h
p_
z[
j][1
]=-
ou
t_b
uffe
r_d
ow
n[
i]-
ou
t_b
uffe
r_d
ow
n[
i]-
164
((e
n_
hp
_a
[j
][0
]*e
n_
hp
_z
[j
][2
]+16
5e
n_
hp
_a
[j
][1
]*e
n_
hp
_z
[j
][2
])>
>1
5)+
166
en
_h
p_
z[
j][0
];16
716
8e
n_
hp
_z
[j
][0
]=o
ut_
bu
ffe
r_d
ow
n[
i]-
169
((e
n_
hp
_a
[j
][2
]*e
n_
hp
_z
[j
][2
])>
>1
5);
170
ou
t_b
uffe
r_d
ow
n[
i]=
(e
n_
hp
_z
[j
][2
]);
171
}17
2}
173
for
(i
=0
;i
<B
UF
FE
RS
IZE
_O
UT
PU
T;i
++
)17
4{
175
ou
t_b
uffe
r_d
ow
n[
i]=
ou
t_b
uffe
r_d
ow
n[
i]*
EN
_H
P_
UP
SC
AL
E;17
6}
177
178
}17
918
0/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
181
EN
DO
FT
HE
FIL
E18
2_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
144
F.1. C Listings
F.1.
5.Fl
oati
ng-P
oint
Ada
ptiv
e
mix
ed_d
emod
ulat
e
List
ing
F.45
: Flo
atin
g-Po
int
Opt
imiz
edA
dapt
ive
::m
ixed
_dem
odul
ate.
h1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
MIX
ED
DE
MO
DU
LA
TO
RW
ITH
CA
RR
IER
CO
RR
EC
TIO
N3
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.1
4 5fil
e:
mix
ed
_d
em
od
ula
te.h
6d
ate
:o
ct2
00
1-
jan
20
02
7b
y:
c.h
alle
r8
f.sc
hn
yde
r9
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
10*/
11 12#
ifnd
ef
_M
IXE
D_
DE
MO
DU
LA
TE
_13
#d
efin
e_
MIX
ED
_D
EM
OD
UL
AT
E_
14 15/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--16
incl
ud
es
17--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/18
#in
clu
de
"glo
ba
l_se
ttin
gs.
h"
19#
incl
ud
e<
ma
th.
h>
20 21/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--22
glo
ba
lfu
nct
ion
s23
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
24/*
25T
he
re_
bu
ffe
r_d
ow
n_
on
ea
nd
im_
bu
ffe
r_d
ow
n_
on
ea
red
em
od
ula
ted
26w
ithth
em
ixe
dd
em
od
ula
tor
alg
orith
mto
ou
t_b
uffe
r_d
ow
n_
on
e.
27 28P
ara
me
ters
:29 30
re_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Isi
gn
al
31im
_b
uffe
r_d
ow
n_
on
eb
uffe
ro
fd
ow
nsa
mp
led
Qsi
gn
al
32o
ut_
bu
ffe
r_d
ow
n_
on
eb
uffe
ro
fd
em
od
ula
ted
sig
na
l33
*/34
void
mix
ed
_d
em
od
ula
te(
floa
tre
_b
uffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[]);
35 36#
en
dif
/*_
MIX
ED
_D
EM
OD
UL
AT
E_
*/37 38
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_39
EN
DO
FT
HE
FIL
E40
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
*/
List
ing
F.46
:Flo
atin
g-Po
int
Opt
imiz
edA
dapt
ive
::m
ixed
_dem
odul
ate.
c1
/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_2
MIX
ED
DE
MO
DU
LA
TO
RW
ITH
CA
RR
IER
CO
RR
EC
TIO
N3
-V
ER
SIO
NF
LO
AT
ING
PO
INT
1.1
4 5fil
e:
mix
ed
_d
em
od
ula
te.c
6d
ate
:o
ct2
00
1-
jan
20
02
7b
y:
c.h
alle
r8
f.sc
hn
yde
r9
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
10*/
11 12/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--13
incl
ud
es
14--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/15
#in
clu
de
"mix
ed
_d
em
od
ula
te.h
"16 17
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
18g
lob
al
varib
les
19--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
*/20
/*va
ria
be
lso
fd
em
od
ula
ting
(atte
nsi
on
div
isio
nb
yze
ro!)
*/21 22
floa
tco
old
=0
.0;/*o
ldva
lue
of
I-p
ath
*/
23flo
at
con
ew
=1
.0;/*n
ew
valu
eo
fI-
pa
th*/
24flo
at
sio
ld=
0.0
;/*o
ldva
lue
of
Q-p
ath
*/25
floa
tsi
ne
w=
1.0
;/*n
ew
valu
eo
fQ
-pa
th*/
26flo
at
de
mo=
0.0
;/*v
alu
ed
em
od
ula
ting
*/27 28
/*co
nst
an
to
fd
em
od
ula
ting
*/29 30
floa
td
eco
n=
0.7
;31 32
/*va
ria
be
lso
fa
da
ptiv
efil
terin
g*/
33 34in
tco
un
ter
=0
;35 36
floa
tsu
m=
0;
37flo
at
wM
e=8
25
61
;/*e
xsta
nt
mix
er
an
gu
lar
fre
qu
en
cy*/
38flo
at
wM
s=0
;/*s
up
po
sed
mix
er
an
gu
lar
fre
qu
en
cy*/
39 40e
xte
rnflo
at
bc2
;41
ext
ern
floa
tb
s2;
42e
xte
rnflo
at
asc
2;
43 44/*
con
sta
nts
of
ad
ap
tive
filte
rin
g*/
45 46#
de
fine
N3
20
00
/*x*
BU
FF
ER
SIZ
E_
DE
MO
DU
LA
TO
R*/
47#
de
fine
de
riva
tion
30
00
48 49flo
at
T=
0.0
00
01
56
25
;/*s
am
ple
time
*/50
floa
ta
dco
n=
2*
PI*
de
riva
tion
/N
;51 52 53 54
/*--
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
55im
ple
me
nta
tion
of
fun
ctio
n56
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
57vo
idm
ixe
d_
de
mo
du
late
(flo
at
re_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
im_
bu
ffe
r_d
ow
n_
on
e[]
,flo
at
ou
t_b
uffe
r_d
ow
n_
on
e[])
58{
59in
ti
;60 61
for
(i
=0
;i
<B
UF
FE
RS
IZE
_D
EM
OD
UL
AT
OR
;i
++
)62
{63
/*_
_sh
iftin
gva
lue
s__
*/64
coo
ld=
con
ew
;65
sio
ld=
sin
ew
;66
con
ew
=re
_b
uffe
r_d
ow
n_
on
e[
i];
67si
ne
w=
im_
bu
ffe
r_d
ow
n_
on
e[
i];
68 69/*
__
calc
ula
ting
de
mo
du
late
dva
lue
__
*/70
de
mo=
(co
old
*si
ne
w-
sio
ld*
con
ew
)/(
coo
ld*
con
ew
+si
old
*si
ne
w);
/*a
tan
arg
um
en
t*/
71d
em
o=a
tan
f(
de
mo)
;/*a
tan
valu
e*/
72d
em
o=d
em
o*d
eco
n;/*d
em
od
ula
ted
valu
e*/
73o
ut_
bu
ffe
r_d
ow
n_
on
e[
i]=
de
mo;
74 75su
m=
sum
+d
em
o;76
cou
nte
r+
+;
77}
78 79 80if
(co
un
ter
==
N)
81{
82w
Ms=
wM
e;83
wM
e=w
Ms+
sum
*a
dco
n;
84 85b
c2=
-co
sf(
wM
e*T
);86
bs2
=si
nf
(w
Me*
T);
87a
sc2
=-2
*co
sf(
wM
e*T
);88 89
sum
=0
;90
cou
nte
r=
0;
91}
92 93}
94 95 96/*
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
97E
ND
OF
TH
EF
ILE
98_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_*/
145
ListingsF.
2.Li
near
Ass
embl
yLi
stin
gs
F.2.
1.Fi
xed-
Poin
tOpt
imiz
ed
quad
_mix Li
stin
gF.
47:F
ixed
-Poi
ntO
ptim
ized
::qu
ad_m
ix_l
in_a
ss.s
a1
;__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
2;
QU
AD
RA
TU
RE
MIX
ER
-V
ER
SIO
NF
IXE
DP
OIN
T1
3;
4;
5;
file
:q
ua
d_
mix
.c6
;d
ate
:o
ct2
00
1-
jan
20
02
7;
by
:c.
ha
ller
8;
f.sc
hn
yde
r9
;__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
10 11 12.g
lob
al
_q
ua
d_
mix
13.g
lob
al
_m
ix_
lp_
a14
.glo
ba
l_
mix
_lp
_b
15.g
lob
al
_m
ix_
lp_
z_re
16.g
lob
al
_m
ix_
lp_
z_im
17.g
lob
al
_g
en
_b
0_
cos
18.g
lob
al
_g
en
_b
1_
cos
19.g
lob
al
_g
en
_b
1_
sin
20.g
lob
al
_g
en
_a
121
.glo
ba
l_
ge
n_
z22 23
.se
ct"
.te
xt"
24 25_
qu
ad
_m
ix:
.cp
roc
in_
s,
re_
b_
s,
im_
b_
s26 27
.re
gre
_b
,im
_b
28.r
eg
cnt
29.r
eg
ptr
_re
,p
tr_
im30 31
.re
gre
_in
,re
_p
rod
1,
re_
pro
d2
32.r
eg
im_
in,
im_
pro
d1
,im
_p
rod
233 34
.re
gre
_a
_1
_a
,re
_a
_1
_b
,re
_a
_2
,re
_b
_0
,re
_b
_1
,re
_b
_2
35.r
eg
im_
a_
1_
a,
im_
a_
1_
b,
im_
a_
2,
im_
b_
0,
im_
b_
1,
im_
b_
236 37
.re
gre
_z_
0,
re_
z_1
,re
_z_
238
.re
gim
_z_
0,
im_
z_1
,im
_z_
239 40
.no
_m
de
p41 42 43
;==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
44;
BE
GIN
mix
ing
45;=
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
=46
;co
py
ad
dre
sso
fin
pu
tb
uffe
rs47
MV
re_
b_
s,
re_
b48
MV
im_
b_
s,
im_
b49 50
;lo
ad
filte
rco
effic
ien
ts51
MV
KL
_g
en
_a
1,
ptr
_re
52M
VK
L_
ge
n_
b1
_si
n,
ptr
_im
53M
VK
H_
ge
n_
a1
,p
tr_
re54
MV
KH
_g
en
_b
1_
sin
,p
tr_
im55 56
LD
H*
ptr
_re
,re
_a
_1
_a
57L
DH
*p
tr_
im,
im_
b_
158 59
MV
KL
_g
en
_b
0_
cos
,p
tr_
re60
MV
KL
_g
en
_b
1_
cos
,p
tr_
im61
MV
KH
_g
en
_b
0_
cos
,p
tr_
re62
MV
KH
_g
en
_b
1_
cos
,p
tr_
im63 64
LD
H*
ptr
_re
,re
_b
_0
65L
DH
*p
tr_
im,
re_
b_
166 67
;lo
ad
de
lay
sta
tes
68M
VK
L_
ge
n_
z,
ptr
_re
69M
VK
H_
ge
n_
z,
ptr
_re
70 71L
DH
*++
ptr
_re
,re
_z_
172
LD
H*+
+p
tr_
re,
re_
z_2
73 74;
setu
plo
op
75M
VK
12
8,
cnt
76 77M
IX_
LO
OP
_G
EN:
.trip
12
8,
12
8;
loo
pw
ithm
in1
28
iter
an
dm
ax
12
8ite
r78 79
;lo
ad
inp
ut
valu
es
80L
DH
*in
_s
++
,re
_in
81 82;
fee
db
ack
of
osz
i83
MP
Yre
_a
_1
_a
,re
_z_
1,
re_
z_0
;z1
*a1
84S
HR
re_
z_0
,1
5,
re_
z_0
;b
ack
toQ
15
85A
DD
re_
z_0
,re
_z_
2,
re_
z_0
;(z
1*a
1)+
z286
NE
Gre
_z_
0,
re_
z_0
;-(
z1*a
1)+
z287 88
;fo
rew
ard
of
osz
i89
MP
Yre
_z_
0,
re_
b_
0,
re_
pro
d1
90 91M
PY
re_
z_1
,re
_b
_1
,re
_p
rod
292
MP
Yre
_z_
1,
im_
b_
1,
im_
pro
d2
93 94A
DD
re_
pro
d1
,re
_p
rod
2,
re_
pro
d2
95 96S
HR
re_
pro
d2
,1
5,
re_
pro
d2
97S
HR
im_
pro
d2
,1
5,
im_
pro
d2
98 99;
shift
de
lays
100
MV
re_
z_1
,re
_z_
210
1M
Vre
_z_
0,
re_
z_1
102
103
;m
ixin
g10
4M
PY
im_
pro
d2
,re
_in
,im
_in
105
MP
Yre
_p
rod
2,
re_
in,
re_
in10
6S
HR
im_
in,
15
,im
_in
107
SH
Rre
_in
,1
5,
re_
in10
810
9;
sto
reo
utp
ut
valu
es
am
dse
tP
oin
ter
ton
ext
valu
e11
0S
TH
re_
in,
*re
_b
++
111
ST
Him
_in
,*
im_
b+
+11
211
3;
incr
em
en
tco
un
ter
an
db
ran
chtil
llo
op
cnt=
011
4[
cnt
]S
UB
cnt
,1
,cn
t11
5[
cnt
]B
MIX
_L
OO
P_
GE
N11
611
7;
sto
red
ela
yst
ate
s11
8M
VK
L_
ge
n_
z,
ptr
_re
119
MV
KH
_g
en
_z
,p
tr_
re12
012
1S
TH
re_
z_1
,*+
+p
tr_
re12
2S
TH
re_
z_2
,*+
+p
tr_
re12
312
4;=
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
=12
5;
EN
Dm
ixin
g12
6;=
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
=12
712
8;=
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
=12
9;
BE
GIN
low
-pa
ssfil
ter
130
;==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
131
132
;---
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
-13
3;
casc
ad
e0
(first
ord
er)
134
;---
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
-13
513
613
7;
cop
ya
dd
ress
of
inp
ut
bu
ffe
rs13
8M
Vre
_b
_s
,re
_b
139
MV
im_
b_
s,
im_
b14
014
1;
loa
dfil
ter
coe
ffic
ien
ts14
2M
VK
L_
mix
_lp
_a
,p
tr_
re14
3M
VK
L_
mix
_lp
_b
,p
tr_
im14
4M
VK
H_
mix
_lp
_a
,p
tr_
re14
5M
VK
H_
mix
_lp
_b
,p
tr_
im14
614
7L
DH
*p
tr_
re+
+,
re_
a_
1_
a
146
F.2. Linear Assembly Listings
148
LD
H*
ptr
_im
++
,re
_b
_0
149
LD
H*
ptr
_re
++
,re
_a
_1
_b
150
LD
H*
ptr
_im
++
,re
_b
_1
151
152
;co
py
toh
ave
the
mfo
rb
oth
pa
ths
153
MV
re_
a_
1_
a,
im_
a_
1_
a15
4M
Vre
_b
_0
,im
_b
_0
155
MV
re_
a_
1_
b,
im_
a_
1_
b15
6M
Vre
_b
_1
,im
_b
_1
157
158
;lo
ad
de
lay
sta
tes
159
MV
KL
_m
ix_
lp_
z_re
,p
tr_
re16
0M
VK
L_
mix
_lp
_z_
im,
ptr
_im
161
MV
KH
_m
ix_
lp_
z_re
,p
tr_
re16
2M
VK
H_
mix
_lp
_z_
im,
ptr
_im
163
164
LD
H*+
+p
tr_
re,
re_
z_1
165
LD
H*+
+p
tr_
im,
im_
z_1
166
167
;se
tup
the
loo
p16
8M
VK
12
8,
cnt
169
170
MIX
_L
OO
P_
C0:
.trip
12
8,
12
8;
loo
pw
ithm
in1
28
iter
an
dm
ax
12
8ite
r17
117
2;
loa
din
pu
tva
lue
s17
3L
DH
*re
_b
,re
_in
174
LD
H*
im_
b,
im_
in17
517
6;
fee
db
ack
of
filte
r17
7M
PY
re_
z_1
,re
_a
_1
_a
,re
_p
rod
1;
z1*
a1
a17
8M
PY
im_
z_1
,im
_a
_1
_a
,im
_p
rod
117
918
0M
PY
re_
z_1
,re
_a
_1
_b
,re
_z_
0;
z1*
a1
b18
1M
PY
im_
z_1
,im
_a
_1
_b
,im
_z_
018
218
3A
DD
re_
z_0
,re
_p
rod
1,
re_
z_0
;z1
*a1
a+
z1*a
1b
184
AD
Dim
_z_
0,
im_
pro
d1
,im
_z_
018
518
6S
HR
re_
z_0
,1
5,
re_
z_0
;b
ack
toQ
15
187
SH
Rim
_z_
0,
15
,im
_z_
018
818
9S
UB
re_
in,
re_
z_0
,re
_z_
0;
in-(
z1*a
1a
+z1
*a1
b)
190
SU
Bim
_in
,im
_z_
0,
im_
z_0
191
192
;fo
rew
ard
of
filte
r19
3M
PY
re_
z_0
,re
_b
_0
,re
_p
rod
1;
z0*b
019
4M
PY
im_
z_0
,im
_b
_0
,im
_p
rod
119
519
6M
PY
re_
z_1
,re
_b
_1
,re
_in
;z1
*b1
197
MP
Yim
_z_
1,
im_
b_
1,
im_
in19
819
9A
DD
re_
in,
re_
pro
d1
,re
_in
;z0
*b0
+z1
*b1
200
AD
Dim
_in
,im
_p
rod
1,
im_
in20
120
2S
HR
re_
in,
15
,re
_in
;b
ack
toQ
15
203
SH
Rim
_in
,1
5,
im_
in20
420
5;
shift
de
lays
206
MV
re_
z_0
,re
_z_
120
7M
Vim
_z_
0,
im_
z_1
208
209
;st
ore
ou
tpu
tva
lue
sa
md
set
Po
inte
rto
ne
xtva
lue
210
ST
Hre
_in
,*
re_
b+
+21
1S
TH
im_
in,
*im
_b
++
212
213
;in
cre
me
nt
cou
nte
ra
nd
bra
nch
till
loo
pcn
t=0
214
[cn
t]
SU
Bcn
t,
1,
cnt
215
[cn
t]
BM
IX_
LO
OP
_C
021
621
7;
sto
red
ela
yst
ate
s21
8M
VK
L_
mix
_lp
_z_
re,
ptr
_re
219
MV
KL
_m
ix_
lp_
z_im
,p
tr_
im22
0M
VK
H_
mix
_lp
_z_
re,
ptr
_re
221
MV
KH
_m
ix_
lp_
z_im
,p
tr_
im22
222
3S
TH
re_
z_1
,*+
+p
tr_
re22
4S
TH
im_
z_1
,*+
+p
tr_
im22
522
6;-
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
---
227
;ca
sca
de
1(s
eco
nd
ord
er)
228
;---
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
-22
923
0;
cop
ya
dd
ress
of
inp
ut
bu
ffe
rs23
1M
Vre
_b
_s
,re
_b
232
MV
im_
b_
s,
im_
b23
323
4;
loa
dco
effic
ien
ts23
5M
VK
L_
mix
_lp
_a
,p
tr_
re23
6M
VK
L_
mix
_lp
_b
,p
tr_
im23
7M
VK
H_
mix
_lp
_a
,p
tr_
re23
8M
VK
H_
mix
_lp
_b
,p
tr_
im23
924
0A
DD
6,
ptr
_re
,p
tr_
re24
1A
DD
6,
ptr
_im
,p
tr_
im24
224
3L
DH
*p
tr_
re+
+,
re_
a_
1_
a24
4L
DH
*p
tr_
im+
+,
re_
b_
024
5L
DH
*p
tr_
re+
+,
re_
a_
1_
b24
6L
DH
*p
tr_
im+
+,
re_
b_
124
7L
DH
*p
tr_
re+
+,
re_
a_
224
8L
DH
*p
tr_
im+
+,
re_
b_
224
925
0M
Vre
_a
_1
_a
,im
_a
_1
_a
251
MV
re_
b_
0,
im_
b_
025
2M
Vre
_a
_1
_b
,im
_a
_1
_b
253
MV
re_
b_
1,
im_
b_
125
4M
Vre
_a
_2
,im
_a
_2
255
MV
re_
b_
2,
im_
b_
225
625
7;
loa
dd
ela
yst
ate
s25
8M
VK
L_
mix
_lp
_z_
re,
ptr
_re
259
MV
KL
_m
ix_
lp_
z_im
,p
tr_
im26
0M
VK
H_
mix
_lp
_z_
re,
ptr
_re
261
MV
KH
_m
ix_
lp_
z_im
,p
tr_
im26
226
3A
DD
6,
ptr
_re
,p
tr_
re;r
ed
ire
ctp
oin
ter
toco
eff
264
AD
D6
,p
tr_
im,
ptr
_im
265
266
LD
H*+
+p
tr_
re,
re_
z_1
267
LD
H*+
+p
tr_
im,
im_
z_1
268
269
LD
H*+
+p
tr_
re,
re_
z_2
270
LD
H*+
+p
tr_
im,
im_
z_2
271
272
;se
tup
loo
p27
3M
VK
12
8,
cnt
274
275
276
277
MIX
_L
OO
P_
C1:
.trip
12
8,
12
8;
loo
pw
ithm
in1
28
iter
an
dm
ax
12
8ite
r27
827
9;
loa
din
pu
tva
lue
s28
0L
DH
*re
_b
,re
_in
281
LD
H*
im_
b,
im_
in28
228
3;
fee
db
ack
of
filte
r28
4M
PY
re_
z_1
,re
_a
_1
_a
,re
_p
rod
1;
z1*
a1
a28
5M
PY
im_
z_1
,im
_a
_1
_a
,im
_p
rod
128
628
7M
PY
re_
z_1
,re
_a
_1
_b
,re
_p
rod
2;
z1*
a1
b28
8M
PY
im_
z_1
,im
_a
_1
_b
,im
_p
rod
228
929
0M
PY
re_
z_2
,re
_a
_2
,re
_z_
0;
z2*
a2
291
MP
Yim
_z_
2,
im_
a_
2,
im_
z_0
292
293
AD
Dre
_z_
0,
re_
pro
d1
,re
_z_
0;
z1*a
1a
+z2
*a2
294
AD
Dim
_z_
0,
im_
pro
d1
,im
_z_
029
529
6A
DD
re_
z_0
,re
_p
rod
2,
re_
z_0
;z1
*a1
a+
z1*a
1b
+z2
*a2
297
AD
Dim
_z_
0,
im_
pro
d2
,im
_z_
029
829
9S
HR
re_
z_0
,1
5,
re_
z_0
;b
ack
toQ
15
300
SH
Rim
_z_
0,
15
,im
_z_
030
130
2S
UB
re_
in,
re_
z_0
,re
_z_
0;
in-(
z1*a
1a
+z1
*a1
b+
z2*a
2)
303
SU
Bim
_in
,im
_z_
0,
im_
z_0
304
305
;fo
rew
ard
of
filte
r30
6M
PY
re_
z_0
,re
_b
_0
,re
_p
rod
1;
z0*b
030
7M
PY
im_
z_0
,im
_b
_0
,im
_p
rod
1
147
Listings30
830
9M
PY
re_
z_1
,re
_b
_1
,re
_p
rod
2;
z1*b
131
0M
PY
im_
z_1
,im
_b
_1
,im
_p
rod
231
131
2M
PY
re_
z_2
,re
_b
_2
,re
_in
;z2
*b2
313
MP
Yim
_z_
2,
im_
b_
2,
im_
in31
431
5A
DD
re_
in,
re_
pro
d1
,re
_in
;z0
*b0
+z2
*b2
316
AD
Dim
_in
,im
_p
rod
1,
im_
in31
731
8A
DD
re_
in,
re_
pro
d2
,re
_in
;z0
*b0
+z1
*b1
+z2
*b2
319
AD
Dim
_in
,im
_p
rod
2,
im_
in32
032
1S
HR
re_
in,
15
,re
_in
;b
ack
toQ
15
322
SH
Rim
_in
,1
5,
im_
in32
332
4;
shift
de
lays
325
MV
re_
z_1
,re
_z_
232
6M
Vim
_z_
1,
im_
z_2
327
328
MV
re_
z_0
,re
_z_
132
9M
Vim
_z_
0,
im_
z_1
330
331
;st
ore
ou
tpu
tva
lue
sa
md
set
Po
inte
rto
ne
xtva
lue
332
ST
Hre
_in
,*
re_
b+
+33
3S
TH
im_
in,
*im
_b
++
334
335
;in
cre
me
nt
cou
nte
ra
nd
bra
nch
till
loo
pcn
t=0
336
[cn
t]
SU
Bcn
t,
1,
cnt
337
[cn
t]
BM
IX_
LO
OP
_C
133
833
9;
sto
red
ela
yst
ate
s34
0M
VK
L_
mix
_lp
_z_
re,
ptr
_re
341
MV
KL
_m
ix_
lp_
z_im
,p
tr_
im34
2M
VK
H_
mix
_lp
_z_
re,
ptr
_re
343
MV
KH
_m
ix_
lp_
z_im
,p
tr_
im34
434
5A
DD
6,
ptr
_re
,p
tr_
re34
6A
DD
6,
ptr
_im
,p
tr_
im34
734
8S
TH
re_
z_1
,*+
+p
tr_
re34
9S
TH
re_
z_2
,*+
+p
tr_
re35
035
1S
TH
im_
z_1
,*+
+p
tr_
im35
2S
TH
im_
z_2
,*+
+p
tr_
im35
335
4;-
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
---
355
;ca
sca
de
2(s
eco
nd
ord
er)
356
;---
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
-35
7;
cop
ya
dd
ress
of
inp
ut
bu
ffe
rs35
8M
Vre
_b
_s
,re
_b
359
MV
im_
b_
s,
im_
b36
036
1;lo
ad
coe
ffic
ien
ts36
2M
VK
L_
mix
_lp
_a
,p
tr_
re36
3M
VK
L_
mix
_lp
_b
,p
tr_
im36
436
5M
VK
H_
mix
_lp
_a
,p
tr_
re36
6M
VK
H_
mix
_lp
_b
,p
tr_
im36
736
8A
DD
6,
ptr
_re
,p
tr_
re36
9A
DD
6,
ptr
_im
,p
tr_
im37
037
1A
DD
6,
ptr
_re
,p
tr_
re37
2A
DD
6,
ptr
_im
,p
tr_
im37
337
4L
DH
*p
tr_
re+
+,
re_
a_
1_
a37
5L
DH
*p
tr_
im+
+,
re_
b_
037
6L
DH
*p
tr_
re+
+,
re_
a_
1_
b37
7L
DH
*p
tr_
im+
+,
re_
b_
137
8L
DH
*p
tr_
re+
+,
re_
a_
237
9L
DH
*p
tr_
im+
+,
re_
b_
238
038
1M
Vre
_a
_1
_a
,im
_a
_1
_a
382
MV
re_
b_
0,
im_
b_
038
3M
Vre
_a
_1
_b
,im
_a
_1
_b
384
MV
re_
b_
1,
im_
b_
138
5M
Vre
_a
_2
,im
_a
_2
386
MV
re_
b_
2,
im_
b_
238
7
388
;lo
ad
de
lay
sta
tes
389
MV
KL
_m
ix_
lp_
z_re
,p
tr_
re39
0M
VK
L_
mix
_lp
_z_
im,
ptr
_im
391
MV
KH
_m
ix_
lp_
z_re
,p
tr_
re39
2M
VK
H_
mix
_lp
_z_
im,
ptr
_im
393
394
AD
D6
,p
tr_
re,
ptr
_re
395
AD
D6
,p
tr_
im,
ptr
_im
;a
dd
12
396
397
AD
D6
,p
tr_
re,
ptr
_re
398
AD
D6
,p
tr_
im,
ptr
_im
;a
dd
12
399
400
LD
H*+
+p
tr_
re,
re_
z_1
401
LD
H*+
+p
tr_
im,
im_
z_1
402
403
LD
H*+
+p
tr_
re,
re_
z_2
404
LD
H*+
+p
tr_
im,
im_
z_2
405
406
;se
tup
loo
p40
7M
VK
12
8,
cnt
408
409
MIX
_L
OO
P_
C2:
.trip
12
8,
12
8;
loo
pw
ithm
in1
28
iter
an
dm
ax
12
8ite
r41
041
1;
loa
din
pu
tva
lue
s41
2L
DH
*re
_b
,re
_in
413
LD
H*
im_
b+
+,
im_
in41
441
5;
fee
db
ack
of
filte
r41
6M
PY
re_
z_1
,re
_a
_1
_a
,re
_p
rod
1;
z1*
a1
a41
7M
PY
im_
z_1
,im
_a
_1
_a
,im
_p
rod
141
841
9M
PY
re_
z_1
,re
_a
_1
_b
,re
_p
rod
2;
z1*
a1
b42
0M
PY
im_
z_1
,im
_a
_1
_b
,im
_p
rod
242
142
2M
PY
re_
z_2
,re
_a
_2
,re
_z_
0;
z2*
a2
423
MP
Yim
_z_
2,
im_
a_
2,
im_
z_0
424
425
AD
Dre
_z_
0,
re_
pro
d1
,re
_z_
0;
z1*a
1a
+z2
*a2
426
AD
Dim
_z_
0,
im_
pro
d1
,im
_z_
042
742
8A
DD
re_
z_0
,re
_p
rod
2,
re_
z_0
;z1
*a1
a+
z1*a
1b
+z2
*a2
429
AD
Dim
_z_
0,
im_
pro
d2
,im
_z_
043
043
1S
HR
re_
z_0
,1
5,
re_
z_0
;b
ack
toQ
15
432
SH
Rim
_z_
0,
15
,im
_z_
043
343
4S
UB
re_
in,
re_
z_0
,re
_z_
0;
in-(
z1*a
1a
+z1
*a1
b+
z2*a
2)
435
SU
Bim
_in
,im
_z_
0,
im_
z_0
436
437
;fo
rew
ard
of
filte
r43
8A
ND
0x7
,re
_b
,p
tr_
re;
do
forw
ard
on
lye
very
4th
time
439
AD
D0
x2,
re_
b,
re_
b;
red
ire
ctp
oin
ter
440
441
442
[!p
tr_
re]
MP
Yre
_z_
0,
re_
b_
0,
re_
pro
d1
;z0
*b0
443
[!p
tr_
re]
MP
Yim
_z_
0,
im_
b_
0,
im_
pro
d1
444
445
[!p
tr_
re]
MP
Yre
_z_
1,
re_
b_
1,
re_
pro
d2
;z1
*b1
446
[!p
tr_
re]
MP
Yim
_z_
1,
im_
b_
1,
im_
pro
d2
447
448
[!p
tr_
re]
MP
Yre
_z_
2,
re_
b_
2,
re_
in;
z2*b
244
9[!
ptr
_re
]M
PY
im_
z_2
,im
_b
_2
,im
_in
450
451
[!p
tr_
re]
AD
Dre
_in
,re
_p
rod
1,
re_
in;
z0*b
0+
z2*b
245
2[!
ptr
_re
]A
DD
im_
in,
im_
pro
d1
,im
_in
453
454
[!p
tr_
re]
AD
Dre
_in
,re
_p
rod
2,
re_
in;
z0*b
0+
z1*b
1+
z2*b
245
5[!
ptr
_re
]A
DD
im_
in,
im_
pro
d2
,im
_in
456
457
[!p
tr_
re]
SH
Rre
_in
,1
5,
re_
in;
ba
ckto
Q1
545
8[!
ptr
_re
]S
HR
im_
in,
15
,im
_in
459
460
;st
ore
ou
tpu
t46
1[!
ptr
_re
]S
TH
re_
in,
*re
_b
_s
++
462
[!p
tr_
re]
ST
Him
_in
,*
im_
b_
s+
+46
346
4;
shift
de
lays
465
MV
re_
z_1
,re
_z_
246
6M
Vim
_z_
1,
im_
z_2
467
148
F.3. MATLAB Listings
468
MV
re_
z_0
,re
_z_
146
9M
Vim
_z_
0,
im_
z_1
470
471
;in
cre
me
nt
cou
nte
ra
nd
bra
nch
till
loo
pcn
t=0
472
[cn
t]
SU
Bcn
t,
1,
cnt
473
[cn
t]
BM
IX_
LO
OP
_C
247
447
5;
sto
red
ela
yst
ate
s47
6M
VK
L_
mix
_lp
_z_
re,
ptr
_re
477
MV
KL
_m
ix_
lp_
z_im
,p
tr_
im47
8M
VK
H_
mix
_lp
_z_
re,
ptr
_re
479
MV
KH
_m
ix_
lp_
z_im
,p
tr_
im48
048
1A
DD
6,
ptr
_re
,p
tr_
re48
2A
DD
6,
ptr
_im
,p
tr_
im48
348
4A
DD
6,
ptr
_re
,p
tr_
re48
5A
DD
6,
ptr
_im
,p
tr_
im48
648
7S
TH
re_
z_1
,*+
+p
tr_
re48
8S
TH
re_
z_2
,*+
+p
tr_
re48
949
0S
TH
im_
z_1
,*+
+p
tr_
im49
1S
TH
im_
z_2
,*+
+p
tr_
im49
249
3;=
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
=49
4;
EN
Dlo
w-p
ass
filte
r49
5;=
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
==
=49
649
7.e
nd
pro
c;q
ua
d_
mix
F.3.
MA
TLA
BLi
stin
gs
Tabl
eG
ener
ator
s
List
ing
F.48
:tan
TabG
en.m
1%
Arc
Ta
ng
en
tT
ab
leG
en
era
tor
-V
ers
ion
0.5
2%
3%
file
:ta
nT
ab
Ge
n.m
4%
da
te:
oct
20
01
-ja
n2
00
25
%b
y:
c.h
alle
r6
%f.
sch
nyd
er
7%
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
8 9%
inp
ut
pa
ram
ete
rs10
na
me=
’ata
n’;
%n
am
eo
fth
eo
utp
ut
file
s11
Nb
it=
7;
%le
ng
ht
of
tab
le=
2^N
bit
12sc
ale
=0
.8;
%sc
ale
fact
or
incl
ud
ed
inta
ble
(0.8
)13
Mb
it=
2;
%b
itso
fm
ax
inp
ut
->ta
ble
fro
m0
to2
^bit
14in
bits
=1
4;
%Q
form
at
of
inp
ut
15 16%
calc
ula
tere
sto
fp
ara
me
ters
17N
=2
^N
bit
;18
ma
x=2
^M
bit
;19
shift
=in
bits
-(N
bit
-M
bit
);20
shift
val
=2
^sh
ift;
21 22%
calc
ula
tion
of
tab
leva
lue
s23
v=
linsp
ace
(0,
ma
x,N
+1
);24
valu
es
=a
tan
(v
)*sc
ale
;25 26
%sc
ale
ing
toQ
15
27va
lue
s=
rou
nd
(va
lue
s*(
2^1
5))
;28
valu
es
=va
lue
s(1
:N
);29 30
%a
void
ove
rflo
ws
(sa
tura
tion
)31
for
i=
1:
N32
ifva
lue
s(
i)>
(2^1
5-1
)33
valu
es
(i
)=2
^15
-1;
34e
nd
35e
nd
36 37%
ge
ne
rate
.ca
nd
.hfil
e38 39
%.c
file
40o
utfile
=fo
pe
n(
strc
at
(n
am
e,’.c
’),’w
’);
41fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
42fp
rin
tf(
ou
tfile
,’A
RC
TA
NG
EN
TF
UN
CT
ION
TA
BL
E-
VE
RS
ION
FIX
ED
PO
INT
0.5
\n’);
43fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
tan
Ta
bG
en
.m\n
’);
44fp
rin
tf(
ou
tfile
,’N
=%
i\n’,
N);
45fp
rin
tf(
ou
tfile
,’R
an
ge
=%
i\n’,
ma
x);
46fp
rin
tf(
ou
tfile
,’S
cale
=%
f\n
’,sc
ale
);47
fprin
tf(
ou
tfile
,’\n
’);
48fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.c
’));
49fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
50fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
51fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
52fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
53fp
rin
tf(
ou
tfile
,’*/\n
’);
54fp
rin
tf(
ou
tfile
,’\n
’);
55fp
rin
tf(
ou
tfile
,’#
incl
ud
e"%
s"\n
’,st
rca
t(
na
me,
’.h’));
56fp
rin
tf(
ou
tfile
,’\n
’);
57fp
rin
tf(
ou
tfile
,’sh
ort
ata
n_
bu
ffe
r[]=
{\n
’);
58fp
rin
tf(
ou
tfile
,’%
i,\n
’,va
lue
s);
59fp
rin
tf(
ou
tfile
,’};
\n’);
60fp
rin
tf(
ou
tfile
,’\n
’);
61fc
lose
(o
utfile
);62 63
%.h
file
64o
utfile
=fo
pe
n(
strc
at
(n
am
e,’.h
’),’w
’);
65fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
66fp
rin
tf(
ou
tfile
,’A
RC
TA
NG
EN
TF
UN
CT
ION
TA
BL
E-
VE
RS
ION
FIX
ED
PO
INT
0.5
\n’);
67fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
tan
Ta
bG
en
.m\n
’);
68fp
rin
tf(
ou
tfile
,’N
=%
i\n’,
N);
69fp
rin
tf(
ou
tfile
,’R
an
ge
=%
i\n’,
ma
x);
70fp
rin
tf(
ou
tfile
,’S
cale
=%
f\n
’,sc
ale
);71
fprin
tf(
ou
tfile
,’\n
’);
72fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.h
’));
73fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
74fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
75fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
76fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
77fp
rin
tf(
ou
tfile
,’*/\n
’);
78fp
rin
tf(
ou
tfile
,’\n
’);
79fp
rin
tf(
ou
tfile
,’#ifn
de
f_
%s_
\n’,
up
pe
r(
na
me)
);80
fprin
tf(
ou
tfile
,’#d
efin
e_
%s_
\n’,
up
pe
r(
na
me)
);81
fprin
tf(
ou
tfile
,’\n
’);
82fp
rin
tf(
ou
tfile
,’#
de
fine
BU
FF
ER
SIZ
E_
AT
AN
%i\n
’,N
);83
fprin
tf(
ou
tfile
,’#
de
fine
AT
AN
_S
HIF
T%
i\n’,
shift
);84
fprin
tf(
ou
tfile
,’#
de
fine
AT
AN
_IN
TE
RP
OL
%i\n
’,sh
iftva
l);
85fp
rin
tf(
ou
tfile
,’\n
’);
86fp
rin
tf(
ou
tfile
,’e
xte
rnsh
ort
ata
n_
bu
ffe
r[];\n
’);
87fp
rin
tf(
ou
tfile
,’\n
’);
88fp
rin
tf(
ou
tfile
,’#e
nd
if/*
_%
s_*/
\n’,
up
pe
r(
na
me)
);89
fprin
tf(
ou
tfile
,’\n
’);
90 91fc
lose
(o
utfile
);92 93
%co
mp
aire
po
lt94
test
v=
0:(
2^(
inb
its+
Mb
it))
;95
test
v=
test
v(1
:le
ng
th(
test
v)-
1);
96in
de
xv=
floo
r(
test
v./(
2^
shift
));
97cu
tv=
test
v-(
(2^
shift
)*in
de
xv);
%m
od
ula
98d
ire
ct=
test
v;
99fo
ri
=1
:le
ng
th(
test
v)
100
dire
ct(
i)=
valu
es
(in
de
xv(
i)+
1);
101
en
d10
2in
terp
ol
=te
stv
;10
3fo
ri
=1
:le
ng
th(
test
v)
104
ifin
de
xv(
i)<
2^
Nb
it-1
105
inte
rpo
l(
i)=
(va
lue
s(
ind
exv
(i
)+2
)*cu
tv(
i)+
valu
es
(in
de
xv(
i)+
1)*
((2
^sh
ift)-
cutv
(i
)))
/2^
shift
;10
6e
lse
107
inte
rpo
l(
i)=
valu
es
(in
de
xv(
i)+
1);
108
en
d10
9e
nd
110
test
v=
(te
stv.
/(2
^in
bits
));
149
Listings11
1p
lot
(te
stv
,d
ire
ct.
/2^1
5,
test
v,
inte
rpo
l./2
^15
,te
stv
,a
tan
(te
stv
)*sc
ale
);11
2le
ge
nd
(’D
ire
ctL
oo
kup
’,’In
terp
ola
tion
Lo
oku
p’,’
Ata
n’)
List
ing
F.49
:tan
TabG
enIn
terp
.m1
%A
rcT
an
ge
nt
Ta
ble
With
Inte
rpo
latio
nG
en
era
tor
-V
ers
ion
0.5
2%
3%
file
:ta
nT
ab
Ge
nIn
terp
.m4
%d
ate
:o
ct2
00
1-
jan
20
02
5%
by
:c.
ha
ller
6%
f.sc
hn
yde
r7
%_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_8 9
%in
pu
tp
ara
me
ters
10n
am
e=’a
tan
’;%
na
me
of
the
ou
tpu
tfil
es
11N
bit
=4
;%
len
gh
to
fta
ble
=2
^Nb
it12
sca
le=
0.8
;%
sca
lefa
cto
rin
clu
de
din
tab
le13
Mb
it=
2;
%b
itso
fm
ax
inp
ut
->ta
ble
fro
m0
to2
^bit
14in
bits
=1
4;
%Q
form
at
of
inp
ut
15 16%
calc
ula
tere
sto
fp
ara
me
ters
17N
=2
^N
bit
;18
ma
x=2
^M
bit
;19
shift
=in
bits
-(N
bit
-M
bit
);20
shift
val
=2
^sh
ift;
21 22%
calc
ula
tion
of
valu
es
23v
=lin
spa
ce(0
,m
ax,
N+
1);
24va
lue
s=
ata
n(
v)*
sca
le;
25 26%
sca
lein
gto
Q1
527
valu
es
=ro
un
d(
valu
es
*(2
^15
));
28va
lue
s=
valu
es
(1:
N);
29 30%
avo
ido
verf
low
s(s
atu
ratio
n)
31fo
ri
=1
:N
32if
valu
es
(i
)>(2
^15
-1)
33va
lue
s(
i)=
2^1
5-1
;34
en
d35
en
d36
gra
die
nt
=va
lue
s(2
:N
)-va
lue
s(1
:N
-1);
37g
rad
ien
t(
N)=
0;
38 39%
ge
ne
rate
.ca
nd
.hfil
e40 41
%.c
file
42o
utfile
=fo
pe
n(
strc
at
(n
am
e,’.c
’),’w
’);
43fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
44fp
rin
tf(
ou
tfile
,’A
RC
TA
NG
EN
TF
UN
CT
ION
TA
BL
EW
ITH
INT
ER
PO
LA
TIO
N\n
’);
45fp
rin
tf(
ou
tfile
,’-
VE
RS
ION
FIX
ED
PO
INT
0.5
\n’);
46fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
tan
Ta
bG
en
.m\n
’);
47fp
rin
tf(
ou
tfile
,’N
=%
i\n’,
N);
48fp
rin
tf(
ou
tfile
,’R
an
ge
=%
i\n’,
ma
x);
49fp
rin
tf(
ou
tfile
,’S
cale
=%
f\n
’,sc
ale
);50
fprin
tf(
ou
tfile
,’\n
’);
51fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.c
’));
52fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
53fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
54fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
55fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
56fp
rin
tf(
ou
tfile
,’*/\n
’);
57fp
rin
tf(
ou
tfile
,’\n
’);
58fp
rin
tf(
ou
tfile
,’#
incl
ud
e"%
s"\n
’,st
rca
t(
na
me,
’.h’));
59fp
rin
tf(
ou
tfile
,’\n
’);
60fp
rin
tf(
ou
tfile
,’sh
ort
ata
n_
bu
ffe
r[]=
{\n
’);
61fp
rin
tf(
ou
tfile
,’%
i,\n
’,va
lue
s);
62fp
rin
tf(
ou
tfile
,’};
\n’);
63fp
rin
tf(
ou
tfile
,’\n
’);
64fp
rin
tf(
ou
tfile
,’sh
ort
ata
n_
gra
d_
bu
ffe
r[]=
{\n
’);
65fp
rin
tf(
ou
tfile
,’%
i,\n
’,g
rad
ien
t);
66fp
rin
tf(
ou
tfile
,’};
\n’);
67fp
rin
tf(
ou
tfile
,’\n
’);
68fc
lose
(o
utfile
);69 70
%.h
file
71o
utfile
=fo
pe
n(
strc
at
(n
am
e,’.h
’),’w
’);
72fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
73fp
rin
tf(
ou
tfile
,’A
RC
TA
NG
EN
TF
UN
CT
ION
TA
BL
EW
ITH
INT
ER
PO
LA
TIO
N\n
’);
74fp
rin
tf(
ou
tfile
,’-
VE
RS
ION
FIX
ED
PO
INT
0.5
\n’);
75fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
tan
Ta
bG
en
.m\n
’);
76fp
rin
tf(
ou
tfile
,’N
=%
i\n’,
N);
77fp
rin
tf(
ou
tfile
,’R
an
ge
=%
i\n’,
ma
x);
78fp
rin
tf(
ou
tfile
,’S
cale
=%
f\n
’,sc
ale
);79
fprin
tf(
ou
tfile
,’\n
’);
80fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.h
’));
81fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
82fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
83fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
84fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
85fp
rin
tf(
ou
tfile
,’*/\n
’);
86fp
rin
tf(
ou
tfile
,’\n
’);
87fp
rin
tf(
ou
tfile
,’#ifn
de
f_
%s_
\n’,
up
pe
r(
na
me)
);88
fprin
tf(
ou
tfile
,’#d
efin
e_
%s_
\n’,
up
pe
r(
na
me)
);89
fprin
tf(
ou
tfile
,’\n
’);
90fp
rin
tf(
ou
tfile
,’#
de
fine
BU
FF
ER
SIZ
E_
AT
AN
%i\n
’,N
);91
fprin
tf(
ou
tfile
,’#
de
fine
AT
AN
_S
HIF
T%
i\n’,
shift
);92
fprin
tf(
ou
tfile
,’#
de
fine
AT
AN
_IN
TE
RP
OL
%i\n
’,sh
iftva
l);
93fp
rin
tf(
ou
tfile
,’\n
’);
94fp
rin
tf(
ou
tfile
,’e
xte
rnsh
ort
ata
n_
bu
ffe
r[];\n
’);
95fp
rin
tf(
ou
tfile
,’\n
’);
96fp
rin
tf(
ou
tfile
,’e
xte
rnsh
ort
ata
n_
gra
d_
bu
ffe
r[];\n
’);
97fp
rin
tf(
ou
tfile
,’\n
’);
98fp
rin
tf(
ou
tfile
,’#e
nd
if/*
_%
s_*/
\n’,
up
pe
r(
na
me)
);99
fprin
tf(
ou
tfile
,’\n
’);
100
fclo
se(
ou
tfile
);10
110
2%
com
pa
ire
po
lt10
3te
stv
=0
:(2
^(in
bits
+M
bit
));
104
test
v=
test
v(1
:le
ng
th(
test
v)-
1);
105
ind
exv
=flo
or
(te
stv.
/(2
^sh
ift))
;10
6cu
tv=
test
v-(
(2^
shift
)*in
de
xv);
%m
od
ula
107
dire
ct=
test
v;
108
for
i=
1:
len
gth
(te
stv
)10
9d
ire
ct(
i)=
valu
es
(in
de
xv(
i)+
1);
110
en
d11
1in
terp
ol
=te
stv
;11
2fo
ri
=1
:le
ng
th(
test
v)
113
ifin
de
xv(
i)<
2^
Nb
it-1
114
inte
rpo
l(
i)=
valu
es
(in
de
xv(
i)+
1)+
(g
rad
ien
t(
ind
exv
(i
)+1
)*cu
tv(
i))
/2^
shift
;11
5e
lse
116
inte
rpo
l(
i)=
valu
es
(in
de
xv(
i)+
1);
117
en
d11
8e
nd
119
test
v=
(te
stv.
/(2
^in
bits
));
120
plo
t(
test
v,
dire
ct.
/2^1
5,
test
v,
inte
rpo
l./2
^15
,te
stv
,a
tan
(te
stv
)*sc
ale
);12
1le
ge
nd
(’D
ire
ctL
oo
kup
’,’In
terp
ola
tion
Lo
oku
p’,’
Ata
n’)
List
ing
F.50
:Sin
eTab
Gen
.m1
%S
ine
Ta
ble
Ge
ne
rato
r-
Ve
rsio
n1
2%
3%
file
:S
ine
Ta
bG
en
.m4
%d
ate
:o
ct2
00
1-
jan
20
02
5%
by
:c.
ha
ller
6%
f.sc
hn
yde
r7
%_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_8 9
%n
am
eo
fth
eo
utp
ut
file
s10
na
me=
’sin
e’;
11 12%
file
inp
ut:
bitn
um
be
ro
fb
uffe
rle
ng
ht
(4,
5,
6,
7)
13n
=7
;14 15
%ca
lcu
latio
no
fco
nst
an
ts16
len
=2
^n
;%
tab
lele
ng
th17
q_
form
at
=1
5-
log
2(4
*le
n);
%si
zeo
fn
ee
de
dQ
form
at
18fo
rma
t=
2^
q_
form
at
;%
form
at
toca
lcu
late
ste
p_
inve
rse
19re
du
ctio
n=
12
-q
_fo
rma
t;
%ch
an
ge
fro
mQ
3.1
2to
ne
wQ
form
at
20st
ep
=(
pi
/2)/
(le
n-1
);%
ste
pb
etw
ee
nth
ea
rgu
me
nts
21st
ep
_in
vers
e=
rou
nd
((1
/st
ep
)*fo
rma
t);
%st
ep
_in
vers
e22 23
%ca
lcu
latio
no
fva
lue
s24
arg
=lin
spa
ce(0
,(p
i/2
),le
n);
150
F.3. MATLAB Listings
25va
lue
s=
sin
(a
rg);
26 27%
sca
ling
toQ
15
28va
lue
s=
rou
nd
(va
lue
s*(
(2^1
5)-
1))
;%
con
vers
ion
fro
mflo
at
toq
15
29 30 31%
ge
ne
rate
.ca
nd
.hfil
e32
ou
tfile
=fo
pe
n(
strc
at
(n
am
e,’.c
’),’w
’);
33 34fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
35fp
rin
tf(
ou
tfile
,’S
INE
FU
NC
TIO
NT
AB
LE
\n’);
36fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
Sin
eT
ab
Ge
n.m
\n’);
37fp
rin
tf(
ou
tfile
,’\n
’);
38fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.c
’));
39fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
40fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
41fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
42fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
43fp
rin
tf(
ou
tfile
,’*/\n
’);
44fp
rin
tf(
ou
tfile
,’\n
’);
45fp
rin
tf(
ou
tfile
,’#
incl
ud
e"%
s"\n
’,st
rca
t(
na
me,
’.h’));
46fp
rin
tf(
ou
tfile
,’\n
’);
47fp
rin
tf(
ou
tfile
,’sh
ort
sin
e_
bu
ffe
r[]=
{\n
’);
48fp
rin
tf(
ou
tfile
,’%
i,\n
’,va
lue
s);
49fp
rin
tf(
ou
tfile
,’};
\n’);
50fp
rin
tf(
ou
tfile
,’\n
’);
51 52 53fc
lose
(o
utfile
);54 55
ou
tfile
=fo
pe
n(
strc
at
(n
am
e,’.h
’),’w
’);
56 57fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
58fp
rin
tf(
ou
tfile
,’S
INE
FU
NC
TIO
NT
AB
LE
\n’);
59fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
Sin
eT
ab
Ge
n.m
\n’);
60fp
rin
tf(
ou
tfile
,’\n
’);
61fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.h
’));
62fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
63fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
64fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
65fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
66fp
rin
tf(
ou
tfile
,’*/\n
’);
67fp
rin
tf(
ou
tfile
,’\n
’);
68fp
rin
tf(
ou
tfile
,’#ifn
de
f_
%s_
\n’,
up
pe
r(
na
me)
);69
fprin
tf(
ou
tfile
,’#d
efin
e_
%s_
\n’,
up
pe
r(
na
me)
);70
fprin
tf(
ou
tfile
,’\n
’);
71fp
rin
tf(
ou
tfile
,’#
de
fine
BU
FF
ER
SIZ
E_
SIN
E%
i\n’,
len
);72
fprin
tf(
ou
tfile
,’#
de
fine
ST
EP
_IN
VE
RS
E%
i\n’,
ste
p_
inve
rse
);73
fprin
tf(
ou
tfile
,’#
de
fine
Q_
FO
RM
AT
%i\n
’,q
_fo
rma
t);
74fp
rin
tf(
ou
tfile
,’#
de
fine
FO
RM
AT
%i\n
’,fo
rma
t);
75fp
rin
tf(
ou
tfile
,’#
de
fine
RE
DU
CT
ION
%i\n
’,re
du
ctio
n);
76fp
rin
tf(
ou
tfile
,’\n
’);
77fp
rin
tf(
ou
tfile
,’e
xte
rnsh
ort
sin
e_
bu
ffe
r[];\n
’);
78fp
rin
tf(
ou
tfile
,’\n
’);
79fp
rin
tf(
ou
tfile
,’#e
nd
if/*
_%
s_*/
\n’,
up
pe
r(
na
me)
);80
fprin
tf(
ou
tfile
,’\n
’);
81 82fc
lose
(o
utfile
);83 84
plo
t(
valu
es.
/2^1
5)
List
ing
F.51
:Sin
eTab
Gen
Int.m
1%
Sin
eT
ab
leW
ithIn
terp
ola
tion
Ge
ne
rato
r-
Ve
rsio
n1
2%
3%
file
:S
ine
Ta
bG
en
Int.m
4%
da
te:
oct
20
01
-ja
n2
00
25
%b
y:
c.h
alle
r6
%f.
sch
nyd
er
7%
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
8 9%
na
me
of
the
ou
tpu
tfil
es
10n
am
e=’s
ine
’;11 12
%fil
ein
pu
t:b
itnu
mb
er
of
bu
ffe
rle
ng
ht
(4,
5,
6,
7)
13n
=4
;14 15
%ca
lcu
latio
no
fco
nst
an
ts16
len
=2
^n
;%
tab
lele
ng
th17
q_
form
at
=1
5-
log
2(4
*le
n);
%si
zeo
fn
ee
de
dQ
form
at
18fo
rma
t=
2^
q_
form
at
;%
form
at
toca
lcu
late
ste
p_
inve
rse
19re
du
ctio
n=
12
-q
_fo
rma
t;
%ch
an
ge
fro
mQ
3.1
2to
ne
wQ
form
at
20st
ep
=(
pi
/2)/
(le
n-1
);%
ste
pb
etw
ee
nth
ea
rgu
me
nts
21st
ep
_in
vers
e=
rou
nd
((1
/st
ep
)*fo
rma
t);
%st
ep
_in
vers
e22 23
%ca
lcu
latio
no
fsi
ne
tab
le24
arg
=lin
spa
ce(0
,(p
i/2
),le
n);
25va
lue
s=
sin
(a
rg);
26 27%
sca
ling
toQ
15
28va
lue
s=
rou
nd
(va
lue
s*(
(2^1
5)-
1))
;%
con
vers
ion
fro
mflo
at
toq
15
29 30%
calc
ula
tion
of
sin
eg
rad
ien
tta
ble
31g
rad
ien
t=
valu
es
(2:
len
)-va
lue
s(1
:le
n-1
);32
gra
die
nt
(le
n)=
0;
33 34%
ge
ne
rate
.ca
nd
.hfil
e35
ou
tfile
=fo
pe
n(
strc
at
(n
am
e,’.c
’),’w
’);
36 37fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
38fp
rin
tf(
ou
tfile
,’S
INE
FU
NC
TIO
NT
AB
LE
\n’);
39fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
Sin
eT
ab
Ge
nIn
t.m
\n’);
40fp
rin
tf(
ou
tfile
,’\n
’);
41fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.c
’));
42fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
43fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
44fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
45fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
46fp
rin
tf(
ou
tfile
,’*/\n
’);
47fp
rin
tf(
ou
tfile
,’\n
’);
48fp
rin
tf(
ou
tfile
,’#
incl
ud
e"%
s"\n
’,st
rca
t(
na
me,
’.h’));
49fp
rin
tf(
ou
tfile
,’\n
’);
50fp
rin
tf(
ou
tfile
,’sh
ort
sin
e_
bu
ffe
r[]=
{\n
’);
51fp
rin
tf(
ou
tfile
,’%
i,\n
’,va
lue
s);
52fp
rin
tf(
ou
tfile
,’};
\n’);
53fp
rin
tf(
ou
tfile
,’\n
’);
54fp
rin
tf(
ou
tfile
,’sh
ort
sin
e_
gra
d_
bu
ffe
r[]=
{\n
’);
55fp
rin
tf(
ou
tfile
,’%
i,\n
’,g
rad
ien
t);
56fp
rin
tf(
ou
tfile
,’};
\n’);
57fp
rin
tf(
ou
tfile
,’\n
’);
58 59 60fc
lose
(o
utfile
);61 62
ou
tfile
=fo
pe
n(
strc
at
(n
am
e,’.h
’),’w
’);
63 64fp
rin
tf(
ou
tfile
,’/*_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\n
’);
65fp
rin
tf(
ou
tfile
,’S
INE
FU
NC
TIO
NT
AB
LE
\n’);
66fp
rin
tf(
ou
tfile
,’g
en
era
ted
with
Sin
eT
ab
Ge
nIn
t.m
\n’);
67fp
rin
tf(
ou
tfile
,’\n
’);
68fp
rin
tf(
ou
tfile
,’fil
e:
%s\
n’,
strc
at
(n
am
e,’.h
’));
69fp
rin
tf(
ou
tfile
,’d
ate
:o
ct2
00
1-
jan
20
02
\n’);
70fp
rin
tf(
ou
tfile
,’b
y:
c.h
alle
r\n
’);
71fp
rin
tf(
ou
tfile
,’f.
sch
nyd
er\
n’);
72fp
rin
tf(
ou
tfile
,’_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_\
n’);
73fp
rin
tf(
ou
tfile
,’*/\n
’);
74fp
rin
tf(
ou
tfile
,’\n
’);
75fp
rin
tf(
ou
tfile
,’#ifn
de
f_
%s_
\n’,
up
pe
r(
na
me)
);76
fprin
tf(
ou
tfile
,’#d
efin
e_
%s_
\n’,
up
pe
r(
na
me)
);77
fprin
tf(
ou
tfile
,’\n
’);
78fp
rin
tf(
ou
tfile
,’#
de
fine
BU
FF
ER
SIZ
E_
SIN
E%
i\n’,
len
);79
fprin
tf(
ou
tfile
,’#
de
fine
ST
EP
_IN
VE
RS
E%
i\n’,
ste
p_
inve
rse
);80
fprin
tf(
ou
tfile
,’#
de
fine
Q_
FO
RM
AT
%i\n
’,q
_fo
rma
t);
81fp
rin
tf(
ou
tfile
,’#
de
fine
FO
RM
AT
%i\n
’,fo
rma
t);
82fp
rin
tf(
ou
tfile
,’#
de
fine
RE
DU
CT
ION
%i\n
’,re
du
ctio
n);
83fp
rin
tf(
ou
tfile
,’\n
’);
84fp
rin
tf(
ou
tfile
,’e
xte
rnsh
ort
sin
e_
bu
ffe
r[];\n
’);
85fp
rin
tf(
ou
tfile
,’\n
’);
86fp
rin
tf(
ou
tfile
,’e
xte
rnsh
ort
sin
e_
gra
d_
bu
ffe
r[];\n
’);
87fp
rin
tf(
ou
tfile
,’\n
’);
88fp
rin
tf(
ou
tfile
,’#e
nd
if/*
_%
s_*/
\n’,
up
pe
r(
na
me)
);
151
Listings89
fprin
tf(
ou
tfile
,’\n
’);
90 91fc
lose
(o
utfile
);92 93
plo
t(
valu
es.
/2^1
5)
Filt
erC
oeffi
cien
ts
List
ing
F.52
:mix
er_d
esig
n.m
1%
Mix
er
De
sig
n-
Ve
rsio
n0
.52
%3
%fil
e:
mix
er_
de
sig
n.m
4%
da
te:
oct
20
01
-ja
n2
00
25
%b
y:
c.h
alle
r6
%f.
sch
nyd
er
7%
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
8 9fo
rma
tlo
ng
10 11fa
=1
50
e6
/(8
*29
3);
%sa
mp
ling
rate
12fp
=6
30
0;
%p
ass
-ba
nd
ed
ge
fre
qu
en
cy13
fs=
19
00
0;
%st
op
-ba
nd
ed
ge
fre
qu
en
cy14
dp
=2
;%
pa
ss-b
an
drip
ple
15d
s=
60
;%
sto
p-b
an
drip
ple
16fc
=1
0.7
e6
;%
cari
er
fre
qu
en
cy17 18 19
%th
esi
ne
an
dco
sin
eo
szila
tor
20su
b=
floo
r(
fc/
fa);
21fo
szi
=fc
-su
b*
fa;
22 23o
szi_
a1
=-2
*co
s(2
*p
i*
fosz
i*(
1/
fa))
;24
osz
i_b
1_
cos
=-
cos
(2*
pi
*fo
szi
*(1
/fa
));
25o
szi_
b1
_si
n=
sin
(2*
pi
*fo
szi
*(1
/fa
));
26%
toQ
15
27io
szi_
a1
=ro
un
d(
osz
i_a
1*2
^15
);28
iosz
i_b
1_
cos
=ro
un
d(
osz
i_b
1_
cos
*2^1
5);
29io
szi_
b1
_si
n=
rou
nd
(o
szi_
b1
_si
n*2
^15
);30 31
%th
efil
ter
32[
n,
Wn]=
bu
tto
rd(
fp*2
/fa
,fs
*2/
fa,
dp
,d
s);
%d
ete
rmin
eth
eo
rde
r33 34
[b
,a
]=b
utte
r(
n,
Wn)
;%
de
term
ine
dire
ctco
effic
ien
ts35
fre
qz
(b
,a
,25
6,
fa)
%a
nd
plo
tth
efil
ter
36 37[
z,
p,
k]=
bu
tte
r(
n,
Wn)
;%
de
rerm
ine
seco
nd
ord
er
coe
ffic
ien
ts38
[co
eff
,g
]=zp
2so
s(
z,
p,
k,’u
p’,’
inf’)
;39 40
%to
Q1
541
ico
eff
=co
eff
;42
Ns=
size
(co
eff
,1);
43fo
ri
=1
:N
s44
ico
eff
(i
,4)=
coe
ff(
i,5
)/2
;45
ico
eff
(i
,5)=
coe
ff(
i,5
)/2
;46
ico
eff
(i
,:)=
rou
nd
(ic
oe
ff(
i,:)*
2^1
5);
47e
nd
48 49%
write
da
tao
utp
ut
50 51fp
rin
tf(’/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--\n
’);
52fp
rin
tf(’
coe
ffic
ien
tso
fsi
ne
an
dco
sin
eo
szila
tor
\n’);
53fp
rin
tf(’
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
\n’);
54fp
rin
tf(’
/*F
req
ue
ncy
:%
10
.2f
HZ
*/\n
’,fo
szi
);55
fprin
tf(’\n
’);
56fp
rin
tf(’
sho
rtg
en
_b
1_
cos
=%
i;/*
cos*
/\n
’,io
szi_
b1
_co
s);
57fp
rin
tf(’
sho
rtg
en
_b
1_
sin
=%
i;/*
sin
*/\n
’,io
szi_
b1
_si
n);
58fp
rin
tf(’
sho
rtg
en
_a
1=
%i;
/*si
n/c
os*
/\n
’,io
szi_
a1
);59
fprin
tf(’\n
’);
60fp
rin
tf(’
/*d
ela
yva
ria
be
ls*/
\n’);
61fp
rin
tf(’
sho
rtg
en
_z
[3]
={0
,0,2
62
13
};/*
0.8
for
first
valu
eo
fd
elta
fun
ctio
n*/
\n
’);
62fp
rin
tf(’\n
’);
63 64
65fp
rin
tf(’/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--\n
’);
66fp
rin
tf(’
coe
ffic
ien
tso
fm
ixe
rlo
w-p
ass
(mix
_lp
)\n
’);
67fp
rin
tf(’
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
\n’);
68fp
rin
tf(’
/*O
rde
r:
%2
i*/
\n’,
n);
69fp
rin
tf(’
/*P
ass
-ba
nd
:%
2i
dB
@%
6.2
fH
z*/
\n’,
dp
,fp
);70
fprin
tf(’
/*S
top
-ba
nd
:%
2i
dB
@%
6.2
fH
z*/
\n’,
ds
,fs
);71
fprin
tf(’\n
’);
72fp
rin
tf(’
#d
efin
eM
IX_
LP
_C
AS
CA
DE
S%
i’,N
s);
73fp
rin
tf(’\n
’);
74fp
rin
tf(’
sho
rtm
ix_
lp_
a[][3
]={
/*a
_i_
1a
a_
i_1
ba
_i_
2*/
\n’);
75fp
rin
tf(’
{%
6i
,%
6i
,%
6i
},\n
’,ic
oe
ff(:
,4:6
)’);
76fp
rin
tf(’
};\n
’);
77fp
rin
tf(’\n
’);
78fp
rin
tf(’
sho
rtm
ix_
lp_
b[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
\n’);
79fp
rin
tf(’
{%
6i
,%
6i
,%
6i
},\n
’,ic
oe
ff(:
,1:3
)’);
80fp
rin
tf(’
};\n
’);
81fp
rin
tf(’\n
’);
82fp
rin
tf(’
sho
rtm
ix_
lp_
sca
le=
%i;
\t/*
%f
toa
void
ove
rflo
ws
*/\n
’,(ro
un
d(
g*2
^15
)),
g)
;83
fprin
tf(’\n
’);
84fp
rin
tf(’
/*d
ela
yva
ria
be
ls*/
\n’);
85fp
rin
tf(’
sho
rtm
ix_
lp_
z_re
[][3
]={
\n’);
86fo
ri
=1
:N
s87
fprin
tf(’
{0
,0,0
},\n
’,ic
oe
ff(:
,5:6
)’);
88e
nd
89fp
rin
tf(’
};\n
’);
90fp
rin
tf(’
sho
rtm
ix_
lp_
z_im
[][3
]={
\n’);
91fo
ri
=1
:N
s92
fprin
tf(’
{0
,0,0
},\n
’,ic
oe
ff(:
,5:6
)’);
93e
nd
94fp
rin
tf(’
};\n
’);
95fp
rin
tf(’\n
’);
96 97%
Filt
er
Te
stfo
ro
verf
low
s98
Nx=
20
0;
99y
=ze
ros
(N
s,N
x+2
);10
010
110
2%
cre
ate
inp
ut
sig
na
l10
3t
=lin
spa
ce(0
,(1
/fa
*(N
x+1
)),
Nx+
2);
104
%x=
sin
(2*p
i*3
00
0*t
);10
5%
x=ch
irp
(t,1
00
,t(N
x+2
),1
00
00
);10
6%
x=[0
0(r
an
d(1
,Nx)
-0.5
)*2
];10
7x
=[0
1o
ne
s(1
,N
x/2
)(
on
es
(1,
Nx/
2)*
-1)
];10
810
9xs
ave
=x
;11
011
1%
sca
ling
fro
mth
em
ixe
r11
2x
=x
*g
;%*0
.8;
113
d=
zero
s(
Ns,
Nx+
2);
114
115
%d
oth
efil
teri
ng
116
for
n=
3:
Nx+
211
7fo
ri
=1
:N
s11
8d
(i
,n
)=(
x(
n)-
coe
ff(
i,5
)*d
(i
,n
-1)-
coe
ff(
i,6
)*d
(i
,n
-2))
;11
9y
(i
,n
)=(
coe
ff(
i,1
)*d
(i
,n
)+co
eff
(i
,2)*
d(
i,
n-1
)+co
eff
(i
,3)*
d(
i,
n-2
));
120
x(
n)
=y
(i
,n
);12
1e
nd
122
en
d12
312
4%
Plo
td
ela
yst
ate
sa
nd
ou
tpu
tva
lue
s12
512
6fig
ure
127
for
i=
1:
Ns
128
sub
plo
t(2
,N
s,i
);12
9p
lot
(d
(i
,:),
’k’);
130
axi
s([
-10
Nx
-1.4
1.4
])13
1le
ge
nd
([’D
ela
yC
asc
ad
e_
’,in
t2st
r(
i-1
)],4
);13
213
3su
bp
lot
(2,
Ns,
i+
Ns)
;13
4p
lot
(y
(i
,:),
’k’);
135
axi
s([
-10
Nx
-1.4
1.4
])13
6le
ge
nd
([’O
utp
ut
Ca
sca
de
_’,
int2
str
(i
-1)]
,4);
137
en
d13
813
9%
plo
t(y(
Ns,
:));
140
ho
ldo
n14
1p
lot
(xs
ave
,’k:’)
;14
2le
ge
nd
(’O
utp
ut
Sig
na
l’,
’Inp
ut
Sig
na
l’,4
);14
3h
old
off
152
F.3. MATLAB Listings
List
ing
F.53
:low
pass
_des
ign_
nois
efilte
r.m1
%L
ow
-Pa
ssF
ilte
rD
esi
gn
-V
ers
ion
0.5
2%
3%
filte
r:
low
-pa
ssb
efo
red
ac
4%
file
:lo
wp
ass
_d
esi
gn
_n
ois
efil
ter.
m5
%d
ate
:o
ct2
00
1-
jan
20
02
6%
by
:c.
ha
ller
7%
f.sc
hn
yde
r8
%_
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
_9 10
fa=
15
00
00
00
0/(
8*2
93
*4);
%sa
mp
lera
te11
fp=
35
00
;%
pa
ss-b
an
de
dg
efr
eq
ue
ncy
12fs
=fa
/4;
%st
op
-ba
nd
ed
ge
fre
qu
en
cy13
dp
=2
;%
pa
ss-b
an
drip
ple
14d
s=
20
;%
sto
p-b
an
drip
ple
15 16[
n,
Wn]=
bu
tto
rd(
fp*2
/fa
,fs
*2/
fa,
dp
,d
s);
%d
ete
rmin
eth
eo
rde
r17 18
[b
,a
]=b
utte
r(
n,
Wn)
;%
de
term
ine
dire
ctco
effic
ien
ts19
fre
qz
(b
,a
,25
6,
fa)
20 21[
z,
p,
k]=
bu
tte
r(
n,
Wn)
;%
de
rerm
ine
seco
nd
ord
er
coe
ffic
ien
ts22
[co
eff
,g
]=zp
2so
s(
z,
p,
k,’u
p’,’
inf’)
;23 24
coe
ffsa
ve=
coe
ff;
25ic
oe
ff=
coe
ff;
26 27N
s=si
ze(
coe
ff,1
);28 29
for
i=
1:
Ns
30ic
oe
ff(
i,:)=
rou
nd
(ic
oe
ff(
i,:)*
2^1
5);
31e
nd
32 33fp
rin
tf(’/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--\n
’);
34fp
rin
tf(’
coe
ffic
ien
tso
fn
ois
elo
w-p
ass
(no
_lp
)a
fte
rd
em
od
ula
tion
\n’);
35fp
rin
tf(’
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
\n’);
36fp
rin
tf(’
/*O
rde
r:
%2
i*/
\n’,
n);
37fp
rin
tf(’
/*P
ass
-ba
nd
:%
2i
dB
@%
6.2
fH
z*/
\n’,
dp
,fp
);38
fprin
tf(’
/*S
top
-ba
nd
:%
2i
dB
@%
6.2
fH
z*/
\n’,
ds
,fs
);39
fprin
tf(’\n
’);
40fp
rin
tf(’
#d
efin
eN
O_
LP
_C
AS
CA
DE
S%
i’,N
s);
41fp
rin
tf(’\n
’);
42fp
rin
tf(’
sho
rtn
o_
lp_
a[][2
]={
/*a
_i_
1a
_i_
2*/
\n’);
43fp
rin
tf(’
{%
6i
,%
6i
},\n
’,ic
oe
ff(:
,5:6
)’);
44fp
rin
tf(’
};\n
’);
45fp
rin
tf(’\n
’);
46fp
rin
tf(’
sho
rtn
o_
lp_
b[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
\n’);
47fp
rin
tf(’
{%
6i
,%
6i
,%
6i
},\n
’,ic
oe
ff(:
,1:3
)’);
48fp
rin
tf(’
};\n
’);
49fp
rin
tf(’\n
’);
50fp
rin
tf(’
sho
rtn
o_
lp_
sca
le=
%i;
\t/*
%f*
0.8
toa
void
ove
rflo
ws
*/\n
’,(ro
un
d((
g*0
.8)
*2^1
5))
,g
);51
fprin
tf(’\n
’);
52fp
rin
tf(’
/*d
ela
yva
ria
be
ls*/
\n’);
53fp
rin
tf(’
sho
rtn
o_
lp_
z[][3
]={
\n’);
54fo
ri
=1
:N
s55
fprin
tf(’
{0
,0,0
},\n
’,ic
oe
ff(:
,5:6
)’);
56e
nd
57fp
rin
tf(’
};\n
’);
58 59%
Filt
er
Te
st60
Nx=
30
0;
61y
=ze
ros
(N
s,N
x+2
);62 63
%x=
[00
(ra
nd
(1,N
x)-0
.5)*
2];
64 65t
=lin
spa
ce(0
,(1
/fa
*(N
x+1
)),
Nx+
2);
66%
x=si
n(2
*pi*
30
00
*t);
67%
x=ch
irp
(t,1
00
,t(N
x+2
),1
00
00
);68 69
x=
[01
on
es
(1,
Nx)
];70 71
xsa
ve=
x;
72 73x
=x
*g
*0.8
;74 75
d=
zero
s(
Ns,
Nx+
2);
76 77fo
rn
=3
:N
x+2
78fo
ri
=1
:N
s
79d
(i
,n
)=(
x(
n)-
coe
ff(
i,5
)*d
(i
,n
-1)-
coe
ff(
i,6
)*d
(i
,n
-2))
;80
y(
i,
n)=
(co
eff
(i
,1)*
d(
i,
n)+
coe
ff(
i,2
)*d
(i
,n
-1)+
coe
ff(
i,3
)*d
(i
,n
-2))
;81
x(
n)
=y
(i
,n
);82
en
d83
en
d84 85
figu
re86
for
i=
1:
Ns
87su
bp
lot
(2,
Ns,
i);
88p
lot
(d
(i
,:))
;89
leg
en
d([
’D’,
int2
str
(i
)]);
90 91su
bp
lot
(2,
Ns,
i+
Ns)
;92
plo
t(
y(
i,:))
;93
leg
en
d(’Y
’);
94e
nd
95 96fig
ure
97p
lot
(y
(N
s,:)
);98
ho
ldo
n99
plo
t(
xsa
ve,’r
’);
100
ho
ldo
ff
List
ing
F.54
:hig
hpas
s_de
sign
_noi
sefil
ter.m
1%
Hig
h-P
ass
Filt
er
De
sig
n-
Ve
rsio
n0
.52
%3
%fil
ter
:h
igh
-pa
ssb
efo
red
ac
4%
file
:h
igh
pa
ss_
de
sig
n_
no
ise
filte
r.m
5%
da
te:
oct
20
01
-ja
n2
00
26
%b
y:
c.h
alle
r7
%f.
sch
nyd
er
8%
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
__
9 10fa
=1
50
00
00
00
/(8
*29
3*4
*2);
;%
sam
ple
rate
11fp
=3
00
;%
pa
ss-b
an
de
dg
efr
eq
ue
ncy
12fs
=5
0;
%st
op
-ba
nd
ed
ge
fre
qu
en
cy13
dp
=0
.1;
%p
ass
-ba
nd
rip
ple
14d
s=
40
;%
sto
p-b
an
drip
ple
15 16[
n,
Wn]=
bu
tto
rd(
fp*2
/fa
,fs
*2/
fa,
dp
,d
s);
%d
ete
rmin
eth
eo
rde
r17 18
[b
,a
]=b
utte
r(
n,
Wn,’h
igh
’);
%d
ete
rmin
ed
ire
ctco
effic
ien
ts19 20
fre
qz
(b
,a
,25
6,
fa)
21 22[
z,
p,
k]=
bu
tte
r(
n,
Wn,’h
igh
’);
%d
ere
rmin
ese
con
do
rde
rco
effic
ien
ts23
[so
s,
g]=
zp2
sos
(z
,p
,k
);24
nc
=si
ze(
sos
,1);
25A
=so
s(:
,4:6
);26
B=
sos
(:,1
:3);
27iA
=A
;28
iB=
B;
29 30fo
ri
=1
:n
c31
iA(
i,1
)=iA
(i
,2)/
2;
32iA
(i
,2)=
iA(
i,2
)/2
;33
iA(
i,:)=
rou
nd
(iA
(i
,:)*
2^1
5);
34iB
(i
,:)=
rou
nd
(iB
(i
,:)*
2^1
5);
35e
nd
36 37fp
rin
tf(’/*
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--\n
’);
38fp
rin
tf(’
coe
ffic
ien
tso
fe
nd
hig
h-p
ass
(en
_h
p)
be
fore
da
c\n
’);
39fp
rin
tf(’
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
----
--*/
\n’);
40fp
rin
tf(’
/*O
rde
r:
%2
i*/
\n’,
n);
41fp
rin
tf(’
/*P
ass
-ba
nd
:%
2.1
fd
B@
%6
.2f
Hz
*/\n
’,d
p,
fp);
42fp
rin
tf(’
/*S
top
-ba
nd
:%
2.1
fd
B@
%6
.2f
Hz
*/\n
’,d
s,
fs);
43fp
rin
tf(’\n
’);
44fp
rin
tf(’
#d
efin
eE
N_
HP
_C
AS
CA
DE
S%
i’,n
c);
45fp
rin
tf(’\n
’);
46fp
rin
tf(’
sho
rte
n_
hp
_a
[][2
]={
/*a
a_
i_1
aa
_i_
1b
a_
i_2
*/\n
’);
47fp
rin
tf(’
{%
6i
,%
6i
,%
6i
},\n
’,iA
’);
48fp
rin
tf(’
};\n
’);
49fp
rin
tf(’\n
’);
50fp
rin
tf(’
/*\n
’);
51fp
rin
tf(’
sho
rte
n_
hp
_b
[][3
]={
/*b
_i_
0b
_i_
1b
_i_
2*/
\n’);
52fp
rin
tf(’
{%
6i
,%
6i
,%
6i
},\n
’,B
’);
53fp
rin
tf(’
};\n
’);
54fp
rin
tf(’
*/\n
’);
153
Listings55
fprin
tf(’\n
’);
56fp
rin
tf(’
sho
rte
n_
hp
_sc
ale
=%
i;\t/*
0.5
*%f
toa
void
ove
rflo
ws
*/\n
’,(ro
un
d(
g*2
^15
/2))
,g
);57
fprin
tf(’\n
’);
58fp
rin
tf(’
#d
efin
eE
N_
HP
_U
PS
CA
LE
2\n
’);
59fp
rin
tf(’\n
’);
60fp
rin
tf(’
/*d
ela
yva
ria
be
ls*/
\n’);
61fp
rin
tf(’
sho
rte
n_
hp
_z[
][3
]={
\n’);
62fo
ri
=1
:n
c63
fprin
tf(’
{0
,0,0
},\n
’);
64e
nd
65fp
rin
tf(’
};\n
’);
66 67 68 69 70n
x=
10
071
t=
linsp
ace
(0,(
1/
fa*(
nx
-1))
,n
x);
72x
=si
n(2
*p
i*3
00
*t
(1,1
:50
));
73x
=[
x,
cos
(2*
pi
*30
0*
t(1
,51
:n
x))
];74
%x=
[01
on
es(
1,n
x-2
)];
75 76 77xs
ave
=x
;78
x=
x*
g;
79 80ze
ta=
zero
s(
nc
,n
x);
81ka
pp
a=
zero
s(
nc
,n
x);
82y
=ze
ros
(n
c,
nx
);83 84
for
i=
1:
len
gth
(t
)85
for
c=
1:
nc
86y
(c
,i
)=ze
ta(
c,
i)+
(B
(c
,1)*
x(
i))
;87
zeta
(c
,i
+1
)=B
(c
,2)*
x(
i)-
A(
c,2
)*y
(c
,i
)+ka
pp
a(
c,
i);
88ka
pp
a(
c,
i+
1)=
B(
c,3
)*x
(i
)-A
(c
,3)*
y(
c,
i);
89x
(i
)=y
(c
,i
);90
en
d91
en
d92 93
alp
ha
=ze
ros
(n
c,
nx
);94
be
ta=
zero
s(
nc
,n
x);
95g
am
ma=
zero
s(
nc
,n
x);
96y2
=ze
ros
(n
c,
nx
);97 98
x=
xsa
ve;
99 100
for
i=
1:
len
gth
(t
)10
1fo
rc
=1
:n
c10
2a
lph
a(
c,
i)=
(-A
(c
,3)*
ga
mm
a(c
,i
))+
(-A
(c
,2)*
be
ta(
c,
i))
+x
(i
);10
3y2
(c
,i
)=(
B(
c,1
)*a
lph
a(
c,
i))
+(
B(
c,2
)*b
eta
(c
,i
))+
(B
(c
,3)*
ga
mm
a(c
,i
));
104
ga
mm
a(c
,i
+1
)=b
eta
(c
,i
);10
5b
eta
(c
,i
+1
)=a
lph
a(
c,
i);
106
x(
i)=
y(
c,
i);
107
en
d10
8e
nd
109
110
lab
els
=in
t2st
r([
1:
nc
]);
111
112
plo
t(
t,
xsa
ve,
t,
y);
113
leg
en
d(’in
’,’o
ut1
’,’o
ut2
’);
114
figu
re;
115
sub
plo
t(2
,1,1
)11
6p
lot
(t
,ze
ta(:
,1:
nx
))11
7le
ge
nd
(’ze
ta1
’,’ze
ta2
’);
118
sub
plo
t(2
,1,2
)11
9p
lot
(t
,ka
pp
a(:
,1:
nx
))12
0le
ge
nd
(’ka
pp
a1
’,’ka
pp
a2
’);
121
122
figu
re12
3p
lot
(t
,xs
ave
,t
,y
);12
4le
ge
nd
(’in
n’,’
ou
t1’,’
ou
t2’);
125
figu
re;
126
sub
plo
t(3
,1,1
)12
7p
lot
(t
,a
lph
a(:
,1:
nx
))12
8le
ge
nd
(’a
lph
a1
’,’a
lph
a2
’);
129
sub
plo
t(3
,1,2
)13
0p
lot
(t
,b
eta
(:,1
:n
x))
131
leg
en
d(’b
eta
1’,’
be
ta2
’);
132
sub
plo
t(3
,1,3
)13
3p
lot
(t
,g
am
ma(:,1
:n
x))
134
leg
en
d(’g
am
ma
1’,’
ga
mm
a2
’);
154