PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio...

134
PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund Boye Carsten Steffensen Gustav Høgh Jes Toft Kristensen Niels Christian Holm Per Kingo Jensen

Transcript of PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio...

Page 1: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

PC FM-radio receiver

5th semester project, AAU,Elektronik og elektroteknik

Group 506Andreas Trøllund Boye

Carsten SteffensenGustav Høgh

Jes Toft KristensenNiels Christian Holm

Per Kingo Jensen

Page 2: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund
Page 3: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Elektronik og Elektroteknik

Fredrik Bajers Vej 7B

Telefon 96 35 98 36

Fax 98 15 36 62

http://www.esn.aau.dk

Title:

FM radio receiver

Theme:

Realtime systems

Projectperiod:P5, fall semester 2005

Project group:506

Members:Andreas Trøllund BoyeCarsten SteffensenGustav HøghJes Toft KristensenNiels Christian HolmPer Kingo Jensen

Supervisor:Persafoni Kyritsi

Copies: 9 FiXme Note: ret titelblad

Pages: 29

Appendices: 19

Finished December 13, 2005

Synopsis:

The objective of this project is to design andimplement a PC based FM radio receiver, ca-pable of receiving an amateur radio signal,which has a bandwidth of 16 kHz and a carrierfrequency in the vicinity of 145 MHz.The signal is downconverted to a low interme-diate frequency of 9 kHz. The low bandwidthallows for the FM signal to be sampled usingthe input of a standard sound card. The sam-pled signal is demodulated using an algorithmof the groups choice. The demodulated sam-pled signal is continously replayed using theoutput of a standard sound card.Six demodulation algorithms has been imple-mented and evaluated using MATLABTM. Ofthe evaluated algorithms the arcus tangent de-modulator has been chosen for further imple-mentation in C on the basis of listening tests,SINAD, visual inspection of DFT and resis-tance against induced noise.An input/output system to handle the conti-nous data transmission to and from the soundcard, and the chosen demodulation algorithmis implemented in C.The final system consisting of downconversionhardware and processing software running ona PC has been tested and the sound outputwas clearly understabable. The system has ameassured SINAD ratio of 28 dB and a delayof 400 ms, thereby conforming only with therequirement to SINAD.

Page 4: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Preface

This project is made by group EE-506 during the 5th semester of the electronicsand electrical engineering education program at Aalborg University (AAU). Theproject is carried out in the period from the 2nd of September to the 20th of De-cember 2005 under the theme ’Analog systems in interaction with data processingunits’.

The reader of this report is presumed a similar technical background as the projectgroup, including knowledge of the courses given during the 5th semester, which areon the subjects of analog filters, analysis and design of embedded real-time sys-tems, signal processing and modulation theory. This particular project has beenmade with basis in the project proposal ”PC FM-radio receiver” and discusses thedesign and implementation of an FM radio receiver and demodulator using a PCas the processing unit. The project exploits the subjects: radio communications,modulation and demodulation, analog and digital signal processing, analog anddigital filtering, matlab simulation, linux programming, use of ALSA sound APIand multithreading.

The report is divided in two parts; the main report (you are holding that one now),and an appendix report. The main report contains an overview of the project anddraws on the main conclusions of the appendices. The main report holds plentifulreferences to appropriate appendices and the interested reader should consult theappendices for an in-depth description, which is ommitted in the main report.

Citations are made in square brackets and contains the author of the work andthe year of publication. Some cited works and papers are to be found on the en-closed CD. Whether this is the case for a particular work or paper is stated in thebibliography list. The enclosed CD contains the complete source code of the soft-ware and the software documentation in HTML format. Furthermore it contains aPDF and postscript version of this report.

The project group would like to thank technician Kim Olesen from the AAU mi-crowave laboratory for practical assistance during the implementation of the re-ceiver.

Niels Christian Holm

Carsten Steffensen

Gustav Høgh

Jes Toft Kristensen

Per Kingo Jensen

Andreas Trøllund Boye

Page 5: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Contents

I Main report 1

1 Introduction 2

2 Requirement specification 32.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32.2 Interface definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.3 User interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.4 Quality factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Analysis 73.1 Radio signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73.2 Data acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83.3 Software demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . 93.4 System design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9

4 System description 104.1 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

5 Chronological signal processing 125.1 Downconverter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125.2 Input filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135.3 Automatic Gain Control . . . . . . . . . . . . . . . . . . . . . . . . . 145.4 Capture sound card . . . . . . . . . . . . . . . . . . . . . . . . . . . 145.5 Demodulation algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 14

6 Demodulation 156.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.2 Test results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.3 Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21

7 Acceptance test 227.1 Demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.2 Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 227.3 SINAD ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23

ii

Page 6: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

8 Conclusion 24

9 Perspectivation 26

II Appendix report 29

A Sound card 30

B Modulation 31B.1 Amplitude modulation . . . . . . . . . . . . . . . . . . . . . . . . . . 31B.2 Frequency modulation . . . . . . . . . . . . . . . . . . . . . . . . . . 34

C Downconverter 40C.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40C.2 Building blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41C.3 Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42C.4 Mathematical analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 43C.5 Dimensioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44C.6 Measurements of downconverter . . . . . . . . . . . . . . . . . . . . . 44C.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

D Input-filter 47D.1 Filter-specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47D.2 Filter-design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48D.3 Filter-simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52

E Multithreading 53E.1 General multithreading . . . . . . . . . . . . . . . . . . . . . . . . . 53E.2 Selection of threading API . . . . . . . . . . . . . . . . . . . . . . . . 54E.3 GNU Pth general usage . . . . . . . . . . . . . . . . . . . . . . . . . 55

F Advanced Linux Sound Architecture 57F.1 Data flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57F.2 Data structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58F.3 Alsa API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59F.4 Control interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59F.5 PCM interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

G IO system 61G.1 Analysis and design . . . . . . . . . . . . . . . . . . . . . . . . . . . 62G.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

H Sallen and Key filter 69H.1 Low pass Sallen and Key filter realization . . . . . . . . . . . . . . . 69H.2 High pass Sallen and Key filter realization . . . . . . . . . . . . . . . 71

I Automatic Gain Control 73I.1 Theory of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . 73I.2 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Page 7: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

J Measurements of signal strength 75J.1 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75J.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76J.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76

K Test of algorithm 77K.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77K.2 Verification of test algorithms . . . . . . . . . . . . . . . . . . . . . . 81K.3 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82K.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

L Zero cross Detection 87L.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87L.2 Basic zero cross detection . . . . . . . . . . . . . . . . . . . . . . . . 87L.3 Improved zero crossing detection . . . . . . . . . . . . . . . . . . . . 89L.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

M FIR bandpass filter 93M.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93M.2 Mathematical description . . . . . . . . . . . . . . . . . . . . . . . . 93M.3 Digitization considerations . . . . . . . . . . . . . . . . . . . . . . . . 95M.4 MATLABTM implementation . . . . . . . . . . . . . . . . . . . . . . 95M.5 C implementation considerations . . . . . . . . . . . . . . . . . . . . 96M.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96

N Quadrature detection 97N.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97N.2 IQ generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101N.3 Arctan demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 103N.4 Baseband delay demodulator . . . . . . . . . . . . . . . . . . . . . . 105N.5 Baseband differentiator demodulator . . . . . . . . . . . . . . . . . . 108N.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111

O Slope detector 112O.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112O.2 Mathematical description . . . . . . . . . . . . . . . . . . . . . . . . 112O.3 Digitization considerations . . . . . . . . . . . . . . . . . . . . . . . . 116O.4 MATLABTM implementation . . . . . . . . . . . . . . . . . . . . . . 116O.5 C implementation considerations . . . . . . . . . . . . . . . . . . . . 116O.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116

P Acceptance test 117P.1 Demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117P.2 Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118P.3 SINAD ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119P.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121

Page 8: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

List of Tables

2.1 Definitions used in system requirements . . . . . . . . . . . . . . . . 52.2 Input interface specification . . . . . . . . . . . . . . . . . . . . . . . 52.3 Output interface specification. . . . . . . . . . . . . . . . . . . . . . . 6

5.1 Specification of input to downconverter. . . . . . . . . . . . . . . . . 125.2 Downconverter output specifications. . . . . . . . . . . . . . . . . . . 135.3 Specifications for the antialiasering filter in the soundcard. [Intel

Corporation, 2002] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6.1 Result of the listening test . . . . . . . . . . . . . . . . . . . . . . . . 206.2 Result of the complexity test . . . . . . . . . . . . . . . . . . . . . . 21

A.1 Frequency response of an AC’97 compliant sound card. . . . . . . . . 30A.2 Input parameters of an AC’97 compliant sound card. . . . . . . . . . 30

C.1 Specifications of input and output of the downconverter. . . . . . . . 41C.2 Specifications of mixers. . . . . . . . . . . . . . . . . . . . . . . . . . 44C.3 Specifications of bandpass filter. . . . . . . . . . . . . . . . . . . . . . 44C.4 Specifications of lowpass filter. . . . . . . . . . . . . . . . . . . . . . 44C.5 Equipment used in test. . . . . . . . . . . . . . . . . . . . . . . . . . 45C.6 Result of test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

D.1 Specifications for the signal from the downconverder. . . . . . . . . . 47D.2 Specifications for the antialiasering filter in the soundcard. [Intel

Corporation, 2002] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

F.1 Hardware settings passed to the sound card. . . . . . . . . . . . . . . 60

G.1 Summary of input- output-system functions. . . . . . . . . . . . . . . 65G.2 Grouping of functions for the input- output-system. . . . . . . . . . 66

I.1 Components used in the AGC circuit . . . . . . . . . . . . . . . . . . 74

J.1 Equipment used in test. . . . . . . . . . . . . . . . . . . . . . . . . . 76

K.1 Result of the listening test. . . . . . . . . . . . . . . . . . . . . . . . 85

v

Page 9: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

K.2 Result of the complexity test. (*) Uses functions with unknowncomplexity. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

P.1 Equipment used in demodulation evaluation. . . . . . . . . . . . . . 118P.2 Equipment used in delay evaluation. . . . . . . . . . . . . . . . . . . 119P.3 Equipment used in SINAD test. . . . . . . . . . . . . . . . . . . . . . 120

Page 10: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

List of Figures

2.1 System overview. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4

3.1 Function diagram of radio transmitter . . . . . . . . . . . . . . . . . 73.2 Frequency overview of two neighboring FM-modulated signals. . . . 83.3 Function diagram of radio receiver. . . . . . . . . . . . . . . . . . . . 8

4.1 Block diagram of the system. . . . . . . . . . . . . . . . . . . . . . . 10

5.1 Block diagram of downconverter. . . . . . . . . . . . . . . . . . . . . 13

6.1 SINAD ratios . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186.2 SINAD ratio with induced noise . . . . . . . . . . . . . . . . . . . . . 196.3 Frequency spectrum of each demodulation algorithm . . . . . . . . . 20

7.1 Results of the delay test . . . . . . . . . . . . . . . . . . . . . . . . . 23

B.1 Illustration of the carrier wave, baseband signal, amplitude modu-lated signal and frequency modulated signal. . . . . . . . . . . . . . 32

B.2 Amplitude modulation of a signal using three different values of ka.Values above 1 result in over modulation and phase reversal. . . . . 32

B.3 Amplitude modulation using two different carrier frequencies. . . . . 33B.4 (a) Spectrum of the AM signal (b) Detailed spectrum of the positive

frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35B.5 Besselfunktions of 0 to 3 orders as a function of β. . . . . . . . . . . 38B.6 First 25 orders of the besselfunction with 3 fixed β values . . . . . . 38B.7 Numbers of significant side frequencies (|Jn(β)| > 0.01) . . . . . . . 39

C.1 Displacement of frequency spectrum. . . . . . . . . . . . . . . . . . . 40C.2 Mirrors as a result of product modulation. . . . . . . . . . . . . . . . 41C.3 Symbol of a 3-terminal mixer. . . . . . . . . . . . . . . . . . . . . . . 42C.4 Block diagram of a possible downconverter solution. . . . . . . . . . 42C.5 Test setup for downconverter. . . . . . . . . . . . . . . . . . . . . . . 45

D.1 4th order band pass Sallen and Key filter . . . . . . . . . . . . . . . 52D.2 Simulation of the bandpass filter. . . . . . . . . . . . . . . . . . . . . 52

vii

Page 11: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

E.1 GNU Pth scheduler mechanism . . . . . . . . . . . . . . . . . . . . . 55

F.1 Structure of the interleaved and non-interleaved buffer structure usedin ALSA. The uppermost part is of a non interleaved buffer structure,where the channels are kept separated. The lover most part is of ainterleaved buffer structure, where the channels are mixed togetherin one buffer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

G.1 Deployment diagram for input and output system . . . . . . . . . . . 62G.2 Use-cases for input and output system. . . . . . . . . . . . . . . . . . 63G.3 Activity diagram for buffer filled use-case. . . . . . . . . . . . . . . . 64G.4 Activity diagram for data ready use-case. . . . . . . . . . . . . . . . 65G.5 Component diagram for the input- output-system. . . . . . . . . . . 67G.6 Flowchart of the 3 threads of the input- output-system. . . . . . . . 68

H.1 Low pass Sallen and Key filter. . . . . . . . . . . . . . . . . . . . . . 69H.2 High pass Sallen and Key filter . . . . . . . . . . . . . . . . . . . . . 71

I.1 Schematic of AGC . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74

J.1 Test setup for signal strength measurement . . . . . . . . . . . . . . 75

K.1 Implemention of the SINAD test in MATLABTM . . . . . . . . . . . 78K.2 Signal to distortion block diagram. . . . . . . . . . . . . . . . . . . . 78K.3 Frequency responce of a 1000 order hamming window FIR filter. . . 79K.4 Implemention of the SINAD test, where noise has been added to the

modulated signal before demodulating. . . . . . . . . . . . . . . . . . 80K.5 Implemention of the DFT analysis test. . . . . . . . . . . . . . . . . 80K.6 FFT analysis of 1 kHz sine tone . . . . . . . . . . . . . . . . . . . . . 82K.7 Comparison of SINAD ratio . . . . . . . . . . . . . . . . . . . . . . . 83K.8 SINAD ration with induced noise . . . . . . . . . . . . . . . . . . . . 84K.9 DFT plot of a 1 kHz demodulated test signal, normalized . . . . . . 85

L.1 Block diagram Zero-crossing Detection Demodulation Algorithm. . . 88L.2 The zero-cross demodulation process. . . . . . . . . . . . . . . . . . . 89L.3 Output at different points of the Modified Zero-Cross Detection De-

modulation Algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . 90L.4 Closeup of zero-crossing, used to increase the accuracy of f∆. . . . . 91L.5 Output at different points of the demodulation process using the

zero-crossing estimation. . . . . . . . . . . . . . . . . . . . . . . . . . 91

M.1 20 order FIR bandpass filter. . . . . . . . . . . . . . . . . . . . . . . 94M.2 Ideal bandpass filter. . . . . . . . . . . . . . . . . . . . . . . . . . . . 94

N.1 Illustrating spectrums of a) a received bandpass signal, (b), the pre-envelope of the bandpass signal and (c) the complex envelope of thebandpass signal. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99

N.2 A block diagram for extracting the I- and Q-signals . . . . . . . . . . 101N.3 Block diagram of the arcus tangent demodulation method. . . . . . . 104N.4 Illustration of wrapping and difference of angles . . . . . . . . . . . . 106N.5 The principle for the Baseband delay demodulator. . . . . . . . . . . 107

Page 12: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.6 The principle for the Baseband differentiator demodulator. . . . . . 109

O.1 Conversion from FM to AM. . . . . . . . . . . . . . . . . . . . . . . 113O.2 Conversion from input to FM to AM . . . . . . . . . . . . . . . . . . 114O.3 Block diagram of a balanced slope detector. . . . . . . . . . . . . . . 115O.4 Amplitude responses of a balanced frequency discriminator. . . . . . 115

P.1 Illustration of the test set-up used to test the demodulation. . . . . . 117P.2 Illustration of the test set-up used to meassure the delay in the system.119P.3 Output af the delay test . . . . . . . . . . . . . . . . . . . . . . . . . 120P.4 Illustration of the test set-up used to test the demodulation. . . . . . 120

Page 13: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Part I

Main report

1

Page 14: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Chapter 1Introduction

FM modulation is widely used in comminucation radio, broadcast radio, televisionand many other applications. Usually receiving and demodulation of FM signalsare carried out in hardware, but PCs of today have enough processing power tohandle the demodulation. This opens up for a wide range of new applications inwhich signals are both demodulated and furtherly handled by the PC, i.e. by re-transmission of the signal through another network as the Internet.

This project aims on designing and implementing a PC based FM radio receiver.The received signal will be a amateur radio signals, which has the advantage oflow bandwidth and that a transmitter is available to the group for testing puposes.The frequency band used for testing is 144.0 - 146.0 MHz which is allocated foramateur radio. The bandwidth of amateur radio signals in the range 50 to 146 Mhzmust not exceed 16 kHz [IT- og Telestyrelsen, 2004, page 14]. The problem canbe divided into receiving the FM signal, sampling of the signal, processing of thesamples and audio output. These tasks must be handled continously.

The initial problem for this project is therefore as follows: How is a PC basedFM radio receiver for amateur radio designed and implemented?

In order to realize how a PC based radio receiver can be designed and implementedthe following questions will be covered:

• How is FM signals received?

• How can an FM signal be sampled by a PC?

• How does FM modulation and demodulation work?

• How can PC data processing be carried out in real time?

• Which algorithm is the best suited for digital FM demodulation?

2

Page 15: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 2. REQUIREMENT SPECIFICATION

Chapter 2Requirement specification

This chapter contains the requirement specification for the project. This will beused in the development of the system and in the acceptance test of the system.The acceptance test specification can be found in appendix P on page 117. Theresults of the acceptance test can be found in chapter 7 on page 22.

Requirements for the system will be specified looking at the system as a blackbox. A general description will be given in section 2.1 with interface descriptions insection 2.2 on the following page. The quality factors are described in section 2.4 onpage 5.

The utilized specification method is “struktureret programudvikling” (struc-tured program development) with reference to [Biering-Sørensen et al., 1988, page85, danish book].

2.1 General description

The following sections describe the system. This is included to give a generaloverview of the system.

2.1.1 System description

The system can be described as a black box containing a radio receiver and demod-ulator, which has two external interfaces; input and output, connecting the systemwith a receiving antenna and a loudspeaker. This is shown in figure 2.1.

The purpose of the system is to receive a frequency modulated signal via theinput channel, demodulate it and deliver it for output via the output channel.

The source block consists of a transmitter and a receiving antenna. A signal isthus transferred in air to the receiving antenna, which delivers the received signalto the system, via the input channel.

The demodulated signal is sent via the output for playback in the loudspeaker.

3

Page 16: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

2.2. INTERFACE DEFINITIONS

Figure 2.1: System overview. The source consists of a transmitter and a receiv-ing antenna. It delivers a frequency modulated signal to the sys-tem. The system demodulates the receivede signal and plays it onthe loudpseaker. The specified input and output are interfaces to the“black box” system.

2.1.2 Limitations of the system

The system is only designed to function in the laboratory with a fixed distance of5 metres between the transmitter and the antenna in the source block.

As the output signal consists of speech, the system is not required to correctlydemodulate the frequencies below 300 Hz and above 3 kHz [Christensen, 1999, page392]. Furthermore, only mono (1 channel) audio is considered.

The communication is one-way. Meaning that signals always travel from thesource to the loudspeaker, not the other way.

2.1.3 Further plans for the system

The system is not to be used or developed any further after the project is evaluated.

2.1.4 User profile

The users are the developers of the system, ease of use is therefore not a priorityin the system development.

2.1.5 Definitions

The definitions used in the requirement specifications can be found in table 2.1 onthe facing page. The SINAD ratio is a quality measure, showing the relationshipbetween signal strength and noise/distortion. A higher value means a bigger ratiobetween the original signal and induced noise/distortion. Thus, a high SINAD levelis desirable.

The definition dBm is defined by the logarithm of the input signal relative to 1mW.

2.2 Interface definitions

This sections contains specifications of the input- and output-channels. This willbe used later in system development.

4

Page 17: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 2. REQUIREMENT SPECIFICATION

Name DescriptionSINAD ratio (Signal + Noise + Distortion)/(Noise + Distortion)

describing the quality of the sound transfer

dBm 10 · log10

(Pin

10[−3]

)

Description of dBm

Table 2.1: Definitons used in system requirements. SINAD is a quality factorregarding signal to distortion/noise. A higher SINAD ratio is better.dBm definition here.

2.2.1 Input interface

The input channel amplitude and carrier frequency is dependant of the internalworkings of the source block. The mechanisms internal to the source block arebeyond the scope of this report, and have thus been measured to the values found intable 2.2 (marked with X). The measurements are further discussed in appendix J onpage 75.

The requirement regarding frequency range are found in the system limitations.The signal bandwidth is defined in the cite [IT- og Telestyrelsen, 2004].

The physical connection of the input channel is a BNC plug.

Parameter Value MeasuredMax bandwidth 16 kHzCarrier Frequency 145MHzSignal magnitude -33 dBm X

Table 2.2: Input interface specification. This channel connects the source blockwith the system, as shown in figure 2.1. Requirements found by mea-surement on the source block are marked with X. The signal bandwidthis specified by the project group.

2.2.2 Output interface

The output is specified in table 2.2.2 on the next page. That the system only usesone channel and the bit resolution is 16 bit is chosen by the project group. Thefrequency range is defined in [Christensen, 1999].

The frequency range are decided by the project group . The physical connectionis a minijack plug.

2.3 User interface

The user interface will be used solely for debugging purpose.

2.4 Quality factors

These are the requirements to the quality of the output signal.

5

Page 18: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

2.4. QUALITY FACTORS

Parameter ValueFrequency range 300 - 3000 HzChannels 1Bit resolution 16 bit

Table 2.3: Output interface specification. This interface connects the system withthe loudspeaker, as shown in figure 2.1. The requirements are specifiedby the project group.

1. The total delay through the system has been chosen to be smaller than 100ms

2. SINAD ratio has to be over 20 dB. This requirement is a adaption of theETSI standard[ETSI, 1991, page 35]..

6

Page 19: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 3. ANALYSIS

Chapter 3Analysis

The requirement for functionality, quality and external interfaces is specified in theprevious chapter. This chapter aims to discuss the possibility of a solution to theproblem. In the end of this chapter a solution is chosen and the overall systemdesign is presented.

The functionality of the system is to receive and demodulate an FM radio sig-nal using a PC. Therefore the initial design considerations is divided into gettingthe signal into the PC and demodulating the signal. Before this an introduction toradio signals in generel is presented.

3.1 Radio signals

The purpose of a radio transmitter (fig. 3.1) is to transform a signal to radiowaves,thus enabling a wireless signal transfer. This is done by utilizing the fact that analternating current through an antenna, creates an electromagnetic field around it.This field emanates from the antenna, and can be received by another antenna.

Figure 3.1: Function diagram of radio transmitter

To enable the transmission of multiple signals, the signals are modulated to acarrier frequency by either Amplitude Modulation (AM), Phase Modulation (PM)or Frequency Modulation (PM). Modulation tecniques are discussed in appendixB. This enables transmission of more than one signal at a time, as each signal has adifferent carrier frequency, see figure 3.2. Between two neighbouring channels thereis a bufferzone, to avoid overlap and ease filtering.

Due to the requirements of sound quality for commercial radiostations, eachchannel is allowed to have a bandwidth of 150 kHz. On the contrary amateur

7

Page 20: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

3.2. DATA ACQUISITION

radio channels are only allowed to have a bandwidth of 16 kHz, as only speech istransmitted. [IT- og Telestyrelsen, 2004, page 14]

Figure 3.2: Frequency overview of two neighboring FM-modulated signals.

The purpose of a radio receiver, see figure 3.3 is to receive the transmitted signal,and extract the modulating signal.

Figure 3.3: Function diagram of radio receiver.

3.2 Data acquisition

In its transmitted form, radio signals are analog. To perform a PC based demodu-lation the radio signal must be sampled. The concerns about sampling sums up toa) the sample frequency and b) the frequency range of the AD converter. Samplinghigh frequencies requires a high sampling frequency. However it is possible to lowerthe frequency of a band limited radio signal by analog downconversion, before thesignal is sampled. Knowing that the computer to be used is a PC this yields twooptions, which are described in the following.

3.2.1 High frequency sampling

Some of the fastest I/O extension cards for PCs samples with a frequency of 200MHz [www.ni.com, 2004], which is sufficient for correct sampling of some broadcastradio signals. The solution is expensive compared to analog receiving.

3.2.2 Analog downconversion and low frequency sampling

Downconversion is the process of ’moving’ a band limited signal to lower partof the frequency spectrum. Since radio signals are always band limited analogdownconversion is possible without loosing information. The low frequency signalallows the use of much cheaper I/O cards for sampling, even sound cards.

The sound card is designed for both input and output of audio signal whichranges from 20 Hz to 20 kHz. The sound card can be used to sample other signalsthan audio, in this case an amateur radio signal as the one described in the pre-vious section. The bandwith of the radio signal (16 kHz) is lower than the input

8

Page 21: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 3. ANALYSIS

bandwidth of the sampling sound card, so if the radio signal can be downconvertedto fit into the range of frequencies, sampling should be possible.

One problem with using a sound card could be that it is not designed for phaselinearity, because the human ear is generally not sensitive to phase in audio.

The sound card solution is considered the best method to use in the project,and furthermore it utilizes hardware already present in most computers. To ensureminimum capability, a sound card standard named AC’97 is chosen as commonreference. See appendix A on page 30 for further information regarding AC’97.

3.3 Software demodulation

The demodulation software is considered an application running on a PC operatingsystem among other applications. The challenge in this lies in handling the process-ing resources being controlled by the operating system and less by the programmer.The system will be interrupted many times each second by other PC peripherals i.e.mouse or USB. While this is happening the demodulation software must continueto receive the bit stream from the sound card, process the input stream, and playthe demodulated signal in realtime.

Linux has been chosen as platform because it is known and preferred by the groupmembers.

Linux offers direct access to peripheral hardware, but to support multiple soundcards with the same software, the interface between the demodulation software andthe soundcard will be ALSA, which is a sound API for linux. See appendix F onpage 57 for further information about ALSA.

3.4 System design

Based on the decisions above a possible problem solution is presented in the follow-ing:

The signal to receive is amateur FM radio, with a carrier frequency of 145 MHz anda bandwith of 16 kHz. The signal is further described in the requirement specifica-tion. This particular signal is sampled using an AC’97 compliant PC sound card asdescribed in appendix A on page 30. The modulated signal is first downconvertedto the samplable range of frequencies. Therefore an analogue downconverter hasto be designed. The demodulation will be done by a program running on a linuxdesktop PC. The program will interface with the ALSA sound API for all commu-nication with the sound card. The software must operate in real time, which meansthat it must process data as they come, and continously output processed data,using the sound card in full duplex mode.

9

Page 22: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Chapter 4System description

This chapter introduces the different building blocks used in the system. The FMsignal is received directly from an antenna. The signal passes through the followingblocks:

• Downconverter

• Input filter

• Automatic Gain Control (AGC)

• Capture sound card

• Demodulation algorithm

• Playback sound card

This is shown in figure 4.1. The demodulation algorithm is accessed through theIO system which is marked on the figure. The latter three of the above mentionedblocks represents the PC part of the system. The output from the system is audiothat can be played with headphones or speakers.

Figure 4.1: Block diagram of the system. The signal is moved from the carrierfreqency to 9 kHz and is freqency and amplitude adjusted by the inputfilter and AGC. The signal is then sampled, demodulated and replayedby the PC.

10

Page 23: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 4. SYSTEM DESCRIPTION

4.1 Hardware

The purpose of the hardware part of the system is to prepare a received FM signalfor sampling using the soundcard. The downconverter moves the signal down infrequency, so it can be sampled using the sound card that operates in the audiorange. The input filter is responsible for selecting the bandlimitted radio signal, andattenuating any other signals. The AGC is responsible for adjusting the amplitudeof the received signal to a predefined level, that is suitable for recording with thesoundcard.

4.2 Software

The software houses the demodulation algorithm and the IO system. The IO systemis responsible for recording of the FM signal and delivering it to the demodulationalgorithm for processing. The IO system is also responsible for moving the demod-ulated signal from the demodulator to the soundcard for playback. This is donecontinously while the system is running, providing a continous FM demodulation.

11

Page 24: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Chapter 5Chronological signal processing

In this chapter the signal way through the system is described. This is done withreference to figure 4.1 on page 10 which shows a general block diagram of thesystem.

The system is described in the following order:

• Downconverter, see appendix C

• Input-filter, see appendix D

• Automatic Gain Control (AGC), see appendix I

• Capture and playback sound card, see appendixes F, G, A and E.

• Demodulation algorithm, see appendixes N, L and O.

5.1 Downconverter

The purpose of the downconverter is to downconvert the received FM signal to afrequency range that can be sampled using a sound card. The received signal hasthe specifications as shown in table 5.1

Parameter Value UnitCarrier frequency fc 145 MHzSignal bandwidth fBW 16 kHzSignal magnitude -33 dBm

Table 5.1: Specification of signal received by the downconverter. See appendix Jfor signal magnitude and 3 for information regarding carrier frequen-cency and signal bandwidth.

The aim of the downconversion is to achieve af carrier frequency of 9 kHz. Theblock diagram of the downconverter is shown in figure 5.1.

12

Page 25: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 5. CHRONOLOGICAL SIGNAL PROCESSING

Figure 5.1: Blockdiagram of the downconverter. The downconversion is per-formed by two mixers, which mathematiccaly are multipliers. Themixers require each require a local oscillator fLO. From multiplyingtwo sinusoidal signals, unwanted high frequency mirrors are created.These are filtered out by the band pass and low pass filters.

In order to downconvert the signal from 145 MHz to 9 kHz the two local oscil-lators are chosen to

fLO,1 = 75 MHz (5.1)fLO,2 = 69.991.000Hz (5.2)

The specifications of the output signalin the output signal described in table 5.2

Parameter Value UnitCarrier freqency fc 9 kHzSignal bandwidth fBW 16 kHzSignal amplitude 2.4 mVrms

Table 5.2: Downconverter output specificatons, see appendix J and C.

5.2 Input filter

The purpose of the input filter is to match the signal from the downconverter to thesoundcard. The signal from the downconverter is described in table 5.2. Comparingthis with the specificatinons for the soundcard shown in table 5.3, it is shown thatsome of the signals will be interpreted as noise. This is because the soundcard filterhas a analog frequency responce from 20 Hz - 20 kHz.

parameter Min Max UnitAnalog frequency response 20 20000 HzTransition band 19200 28800 HzStop band rejection -74 - dB

Table 5.3: Specifications for the antialiasering filter in the soundcard. [Intel Cor-poration, 2002]

It is therefore chosen to filter frequencies under 1 kHz and over 17 kHz. This isdone with a 4th order Butterworth band pass filter realized with a Sallen and Keycircuit.

13

Page 26: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

5.3. AUTOMATIC GAIN CONTROL

5.3 Automatic Gain Control

The received radio signal has a varying amplitude, depending on the receptionconditions. To normalize the received signal, an Automatic Gain Control (AGC) isinserted.

This circuit places its output voltage level as close as possible to a predefinedlevel of 100mV, thereby matching the requirements of the soundcard with micro-phone boost. See table A.2 on page 30 for sound card requirements.

The circuit utilizes a SL6270C chip and is implemented according to applicationnotes, see chapter I on page 73 for more information.

5.4 Capture sound card

The output of the AGC is a level adjusted analog signal with frequencies from1 kHz to 17 kHz. This is sampled with a sampling frequency of 48000Hz by theinput soundcard, thereby conforming to the Nyquist theorem. The precision of thesampling is set to 15 bit signed integers, thereby assuming values of ±215 = 32768,with a value of 32768 as the full scale input of table A.2 on page 30. The interfacebetween the sound card and the IO system is the ALSA API, described in appendixF.

The sampling and delivering of data to the demodulation algorithm is handledby the IO system described in appendix G on page 61. To ensure continous captureand playback, the IO system uses two FIFO buffers. Data is captured in chunksand placed in the input FIFO buffer, for later demodulation. Demodulated data isplaced in the output FIFO buffer, for playback. See appendixes F on page 57 forinformation about the chosen ALSA API.

The chosen capture and playback methods require use of multiple programthreads, which allows for pseudo parallel program execution. The program is splitinto 3 threads; an input thread, a processing thread and an output thread. Forfurther information on multithreading see appendix E.

The hard real time demand for the system is that it must sample continously andwithout jitter, since any amount of jitter will make the demodulation impossible,regardless of method. This is solved by prioritizing the input and output threadover the processing thread.

The soft real time demand for the system is a delay from input signal to audiooutput of less than 100ms. This demand is, apart from hardware buffers, completelycontrolled by the demodulation algorithm and the IO system.

5.5 Demodulation algorithm

The demodulation algorithm is responsible for demodulation of the supplied signal,and will be handled in-depth by chapter 6 on the facing page, and is thereforeomitted here.

The algorithm receives one chunk of data from the input FIFO, processes it andplaces the processed data chunk in the output FIFO.

14

Page 27: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 6. DEMODULATION

Chapter 6Demodulation

One of the project goals is to do a demodulation of an FM signal in a PC. To dothe demodulation, a specific algorithm must be selected. Six algorithms have beenimplemented and tested in MATLABTM and this chapter explores the algorithmsand test results.

The chapter will start with a short description of each algorithm, proceed withthe test results, see appendix K.3 on page 82, and finally present which algorithmthat has been chosen for further implementation in C.

The examined algorithms are

• Zero crossing detection:

– Basic zero crossing detection

– Improved zero crossing detection

• Slope detection:

– Single slope detection

• Quadrature detection:

– Arcus tangent demodulation

– Baseband delay demodulation

– Baseband differentiaton demodulation

6.1 Algorithms

The examined algorithms will be explained here in short form. Refer to the specifiedsections for further information regarding specific algorithms.

6.1.1 Basic zero crossing detection

The basic zero crossing detection is based on the fact that the amount of times asine tone crosses zero, scales with the frequency of the signal. The principle of the

15

Page 28: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

6.1. ALGORITHMS

basic zero crossing demodulation algorithm is to generate a pulse of fixed lengthevery time the signal changes prefix. By integrating the pulses over a fixed length,the message signal appears.

The algorithm has difficulties with demodulating messages of high frequency,i.e. close to 3000 Hz, because the carrier frequency of 9 kHz is low relative to thehighest frequency of the message signal which is 3 kHz. To solve this problem eithera higher carrier frequency or a higher sample frequency would be required.

See section L.2 on page 87 for further information.

6.1.2 Improved zero crossing detection

The zero cross detection with frequency estimation algorithm uses 1st order in-terpolation of to estimate the position of the zero crossing whenever two on eachother following samples are found with different signs (positive-negative or negative-positive). The instantaneous frequency is estimated by dividing the samplerate withthe estimated time between two zero crossings, hence it is calculated once betweenevery two crossings. The frequency of an FM signal is proportional to the amplitudeof the modulating signal, hence performing FM demodulation..

This method is theoretically insensitive to noise and mistuned carrier frequency.

See section L.3 on page 89 for further information.

6.1.3 Single Slope detection

The slope detection algorithm works by performing FM to AM and hereafter per-forming AM demodulation. FM to AM conversion is performed by differentiation.The AM demodulation is performed by rectifying the AM signal and performingbandpass filtration. The result of these actions is the envelope of the AM signal,which is proportional to the modulating signal, hence performting FM demodula-tion.

The method excels in simplicity both in theory and digital implementation.Also this is one of the conventional FM demodulation methods, used in analog ra-dio receivers.

See appendix O on page 112 for further information.

6.1.4 Arcus tangent quadrature demodulation

The principle for the arcus tangent quadrature demodulation algorithm, is to de-modulate the FM signal using quadrature signals. The quadrature representaion ofan FM signal is explained in section N.1. The quadrature signals now at hand arethe inphase component of the received signal, I, and the quadrature component,Q, where φ is the instantanous phase of the received signal:

I(t) = A cos(φ(t)) (6.1)Q(t) = A sin(φ(t)) (6.2)

The instantaneous phase of the received signal can be derived by the angle ofthe complex number I + jQ by the use of the arcus tangent function. When this

16

Page 29: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 6. DEMODULATION

is done the ampltitude of the carrier A cancels out. The time derivative of theinstantanous phase of the received signal is directly proportional to the modulatingsignal, hence performing FM demodulation.

This method performs well against additive noise, since this has influence onthe carrier ampltitude, which cancels out, and less on the phase.

See section N.3 on page 103 for further information.

6.1.5 Baseband delay quadrature demodulation

The principle for the baseband delay quadrature demodulation algorithm is almostthe same as for the arcus tangent quadrature demodulation algorithm, in that itobtains the derivative of the instantaneous phase of the FM signal from the I- andQ-signals.

In contrary to the arcus tangent algorithm, the derivative of the phase is calcu-lated by first delaying the I- and Q-signals one sample and then multiplying it withthe un-delayed other. This means that the delayed I-signal is multiplyed with theQ-signal and the delayed Q-signal is multiplyed with the I-signal. The derivative ofthe instantanous phase can be found by substrating the delayed Q-signal multiplyedwith the I-signal from the delayed I-signal multiplyed with the Q-signal. This givesthe following expression for determining the derivative of the instantanous phase

φ′(n) = (I(n− 1) ·Q(n))− (Q(n− 1) · I(n)) (6.3)

As mentioned this result is directly proportional to the modulating signal.

See section N.4 on page 105 for further information.

6.1.6 Baseband differentiation demodulation

The baseband differentiation demodulator is very similar to the above algorithm,however differentiation is used in stead of delaying. Still the point is to determinethe derivative of the phase from the I and Q signals. This is done by differentiat-ing the I- and Q-signals and multiplying it with the other signal undifferentiated.This means that the differentiatet I-signal is multiplyed with the Q-signal and thedifferentiatet Q-signal is multiplyed with the I-signal. The differentiatet I-signalmultiplyed with the Q-signal is substrated from the differentiatet Q-signal multi-plyed with the I-signal. This yields

φ′(t) = (Q′(t) · I(t))− (I ′(t) ·Q(t)) (6.4)

Again this result is directly proportional to the modulating signal. It turns outthat a digital implementation of the baseband differentiation- and baseband delaydemodulation algorithm would be similar, due to how a differentiation is normallycarried out digitally by subtracting the last sample from the current.

See section N.5 on page 108 for further information.

17

Page 30: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

6.2. TEST RESULTS

6.2 Test results

The described algorithms have been implemented in MATLABTM and tested re-garding the following cases:

• SINAD ratio

• SINAD ratio with induced noise

• Visual inspection of DFT output

• Listening test

• Complexity comparisons

The tests and their results are further described in appendix K.3 on page 82.

This chapter will continue with the actual results of the tests.

6.2.1 SINAD ratio

The signal to noise ration is calculated for each MATLABTM implementation ofthe demodulation algorithms. The result of the calculations is shown in figure 6.1.

103

f [Hz]

MatlabZC 1ZC 2SlopeQuad DelayQuad ArctanQuad Diff

Figure 6.1: SINAD ratios. The calculation is done on pure sine waves. BesidesMATLABTMs demodulation algorithm the arcus tangent method ex-cells in SINAD for pure sines.

The algorithms perform differently over the tested frequency spectrum as shownin the figure. However the arcus tangent quadrature demodulation algorithm hasthe best SINAD ratio over the entire frequency range, exept MATLABTMs own.

18

Page 31: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 6. DEMODULATION

6.2.2 SINAD ratio with induced noise

The SINAD ratio is calculated again, this time with noise added to the modulatedsignal. This shows which algorithm is most resistant to noise. The result is shownin figure 6.2.

103

f [Hz]

MatlabZC 1ZC 2SlopeQuad DelayQuad ArctanQuad Diff

Figure 6.2: SINAD ratio width induced noise. The arcus tangent method excels.

The algorithms perform differently over the tested frequency spectrum as shownin the figure. However the arcus tangent quadrature demodulation algorithm hasthe best SINAD ratio over the entire frequency spectrum. The performance of thearcus tangent method is only slightly reduced (≈ 5 dB) when noise is added to theFM signal. This conforms with theory since the amplitude of the carrier, to whichthe noise is added, cancels out in this particular algorithm.

6.2.3 Visual inspection of DFT output

A DFT of the modulated signals has been made as shown in fiure 6.3.As seen some of the algorithms generates 2nd and 3rd order harmonic frequen-

cies. This is also visible in figures 6.1 and 6.2, as these show a SINAD improvementaround 1 kHz, which is where the 3rd harmonic in 3 kHz hits the band pass filter.

6.2.4 Listening test

A listening test is made, in order to test which algorithm produces the most un-derstandable speech signal. The test is performed by demodulating the same twotest signals (male speech and female speech) with the 6 algorithms and rankingthe result after comprehensibility. The test subjects are the group members. Theresult is shown in table 6.1.

19

Page 32: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

6.2. TEST RESULTS

103

104

Basic zero crossing detection

102

103

104

0

0.1

0.2Improved zero crossing detection

103

104

Single slope detection

102

103

104

0

0.1

0.2Quadrature baseband delay

103

104

Quadrature arctan

102

103

104

0

0.1

0.2Quadrature differentiation

Figure 6.3: Frequency spectrum of demodulation of modulated 1 kHz tone.

As seen the arcus tangent quadrature demodulation algorithm is most under-standable when demodulating a female speech signal, and the Baseband delayquadrature demodulation algorithm is most understandable when a male speechsignal is demodulated.

6.2.5 Complexity comparison

The complexity for the different algorithms is calculated in order to evaluate whichalgorithm is most complex to implement.The complexity is evaluated as the numberof comparations and mathematic operations on two numbers in the algorithm,and this number is calculated as comparations and operations per sample in theMATLABTM implementation. Any initialization is left out. The result is shown intable 6.2.

Algorithm Male FemaleQuad Atan 29 30Quad Delay 34 28Quad Diff 26 23Original sound 20 27Improved ZC 13 12Single Slope 6 6Basic ZC 0 0

Table 6.1: Result of the listening test. The quadrature detection methods receivesthe highest score.

20

Page 33: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 6. DEMODULATION

Algorithm ComplexitySingle Slope 2Basic ZC 5Improved ZC 14Quad Atan 27Quad Delay 28Quad Diff 29

Table 6.2: Result of the complexity test. Lower is better (less complexity).

As seen in the table the Single Slope detection algorithm is the least com-plex algorithm, and the Baseband differentiation demodulation algorithm is themost complex. The calculation is unsure since a MATLABTM implementation isin general not comparable to a C implementation, and since not all operations andcomparisons is of equal complexity, i.e. requires the same processing power.

6.3 Decision

The arcus tangent quadrature demodulation algorithm and the baseband delayquadrature demodulation algorithm scored best in the listening test. These warealso the most complex algorithms, whereas the Single Slope detection algorithm isthe least complex algorithm. The arctan quadrature demodulation algorithm hasthe best SINAD ratio with and without noise. The SINAD is simulated to at least38 dB without added noise and at least 35 dB with added noise. It is thereforechosen to implement the arcus tangent quadrature demodulation algorithm.

21

Page 34: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Chapter 7Acceptance test

The acceptance test has been conducted according to the specifications in ap-pendix P on page 117. This is done to test compliance with the requirementspecification of chapter 2 on page 3. The results of the acceptance test will here beexhibited and evaluated.

The three tests involved are

• Demodulation of speech test.

• Delay test.

• SINAD ratio.

7.1 Demodulation

The purpose of the demodulation test is to evaluate if the system can demodulatea FM-speech signal transmitted from a radio transmitter. The test is conducted asa listening test.

The results of the demodulation tests shows that the system is able to demodu-late speech. The demodulated speech is clearly understandable and without audiblenoise.

7.2 Delay

The delay test is conducted to evaluate the delay through the system, that is howlong time it takes from the system recieve a FM-signal to the demodulated signalis present on the output side of the system.

The delay through the system was measured to approximately 400 ms, as shownin figure 7.1 on the next page. This is a violation of the requirement specificationby a factor of 4.

22

Page 35: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 7. ACCEPTANCE TEST

−0.1 0 0.1 0.2 0.3 0.4 0.5−0.8

−0.7

−0.6

−0.5

−0.4

−0.3

−0.2

−0.1

0

0.1

0.2

Time [s]

Am

plitu

de [V

]Received signalDemodulated signal

Figure 7.1: Results of the delay test. The uppermost signal is the signal receivedby the IO system. The signal below is the demodulated output of theIO system. The lowermost signal has its amplitude factored down by5, and offset by −0.5V. The delay of the system is measured from thereception of the transmitted signal to the zeroing on the output.

7.3 SINAD ratio

The SINAD ratio test is conducted to evaluate how much the signal is distortedthoughout the system. A FM-modulated 1 kHz pure sine tone is generated with asignal generator and connected to the system. The SINAD ratio is calculated onthe demodulated signal.

The result of the test is that the system have a SINAD ratio of 28.0 dB, whichis 8 dB better than required.

23

Page 36: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Chapter 8Conclusion

The initial problem was that of constructing a receiver and a PC based demod-ulator. The chosen FM application is that of amateure-radio, which means thatthe FM signal is bandwidth limited to 16 kHz, transported by a carrier wave in thevicinity of 145MHz.

This problem is solved by downconverting to a low IF, sampling with a soundcard and software demodulation. The bandwidth limited signal is downconvertedfrom 145 MHz to a carrier frequency of 9 kHz by the use of mixers. This leaves adownconverted signal that lies in the range of 1 to 17 kHz, which can be sampledusing a standard AC’97 compliant sound card. Before the sampling, the FM signalis bandpass filtered and amplitude adjusted to fit the specifications of the soundcard.

To ensure continuous sampling, demodulation and playback a system of buffershave been implemented, which services the demodulation algorithm by providingthe algorithm with data, and taking processed data from the algorithm to thesound card output. Both the buffer system and final demodulation algorithm isimplemented in C.

6 different demodulation algorithms have been evaluated by MATLABTM im-plementation. The simulations regarded SINAD (SIgnal, Noise And Distortion),robustness, output quality (listening test) and programming complexity. Based onthis the arcus tangent quadrature demodulation algorithm have been chosen forfinal implementation.

The MATLABTM implementation of the chosen demodulation algorithm excelsin output quality, distortion ratio and especially resistance to noise and carrier de-viation. This concurs with preeliminary theory studies, since these shows that thecarrier amplitude, to which noise is added, cancels out.

The end result is a PC based FM demodulator, capable of receiving a 145 MHz FMsignal and replaying the output via a sound card. This is done under lab conditionswith a measured SINAD ratio of 28.0 dB and a delay of approximately 400 ms,producing clearly understandable speech. However the tested PC demodulator asa whole shows to be more sensitive to carrier deviation than expected.

The delay violates the requirement specification by a factor of 4. This is due to

24

Page 37: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

CHAPTER 8. CONCLUSION

latency in the buffer system, induced by the interface to the sound card. This canbe remedied by a different structure of the buffer system. The SINAD and outputquality meets the specified requirements.

25

Page 38: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Chapter 9Perspectivation

The focus in the project has been on amateur radio, however the system describedin this report can be used to receive all radio signals that falls under the category’communication radio’ by only changing the local oscillator of the downconverter.FM communication radio has the same bandwidth and also used for speech trans-mission. Examples are ship radio, police radio and so on.

With only changing the algorithm the system can be used to receive other typesof modulation, such as AM, PM, or different digital modulation methods, requiringstill that the bandwidth does not exceed 16 kHz.

The general theory of this project applies to wide range of application such ascommercial broadcast radio and television. If these application were to be accessedby the system presented, a sound card would not be sufficient for sampling.

Assuming that a sound card has exactly one input channel and one output chan-nel, the system as it is can not function in full duplex. If the system is to be usedfor two way communication, it must be assumed that the system is either sending(modulating) or receiving (demodulating).

Computer receiving has its main advantage in systems where a radio signal is to bereceived and retransmitted through a PC network, i.e. Internet. In these cases theuse of PCs may offer a lower system price, in contrary to specialized radio receiversand transmitting computers. An application of this is coastal radio systems suchas Danphones Coastal Radio System 9000 [Danphone, 2005]. 20 radio stations areplaced along the coast side of Denmark communicating with ships near the coast.The signal is demodulated and sent through the Internet to a central operator whichsupports all the stations.

26

Page 39: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

BIBLIOGRAPHY

Bibliography

ALSA (2005).Advanced Linux Sound Architecture(Advanced Linux Sound Architecture,2005),URL http://www.alsa-project.org. CD, borrowed form acousticsdepartment, AAU.

Biering-Sørensen, Stephen, Hansen,Finn Overgaard, Klim, Susanne &Madsen, Preben Thalund (1988).Handbog i Struktureret Program-Udvikling,1st edition.ISBN 87-571-1046-8(Ingeniøren|bøger, 1988).

B&O (1992).Music for Archimedes(B&O, 1992).

Borch, Ole (2005).Object oriented analysis and design,1st edition(web, 2005),URL http://www.control.aau.dk/~borch/Object%20Oriented%20Software%2%0Construction/E5/index.html. Existed the 7th ofnovember, 2005.

Carlson, A. Bruce (1986).Communication Systems - An Intro-duction to Signals and Noise in Elec-trical Communication,3rd edition.

ISBN 0-07-009960-X(McGraw-Hill, Inc., 1986).

Christensen, Anders (1999).HF-teknik,1st edition.ISBN 87-600-0129-1(Industriens Forlag, 1999),URL www.if.dk.

Danphone (2005).Homepage of Danphone A/S,1st edition(web, 2005),URL http://www.danphone.com. Ex-isted the 13th of december, 2005.

Engelschall, Ralf S. (2005).GNU Pth homepage,2.0.5 edition(web, 2005),URL http://www.gnu.org/software/pth/. Seehttp://www.gnu.org/software/pth/pth-manual.html for manual, existed051111.

ETSI (1991).ETS 300 086(European Telecommunications Stan-dards Institute, 1991).

group 506, Project (2005).Documentation for project code,1st edition(web, 2005),URL http://kom.aau.dk/group/05gr506/doxygen/html/. Main-tained by the project group. TheCD also contains the source code(/code) and the documentiation(/html/doxygen/html/index.html) inhtml.

Haykin, Simon (2001).Communication Systems,4th edition.ISBN 0-471-17869-1(John Wiley & Sons, Inc., 2001).

Huelsman, Lawrence P. (1993).Active and passive analog filter de-sign.

27

Page 40: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

BIBLIOGRAPHY

ISBN 0-07-112519-1(McGraw-Hill, Inc, 1993).

Intel Corporation (2002).Audio Codec ‘97(Intel Corporation, 2002),URL http://www.intel.com/design/chipsets/audio/ac97_r23.pdf. Revision 2.3 Revision 1.0.

IT- og Telestyrelsen (2004).Bekendtgørelse nr. 1266 af 10. de-cember 2004 om anvendelse af ra-diofrekvenser uden tilladelse samt omamatørradioprøver og kaldesignalerm.v.(2004).

Johnson, David E., Johnson, Johnny R.,Hilburn, John L. & Scott, Peter D.(1999).Electric circuit analysis,3rd edition.ISBN 0-471-36571-8(John Wiley & Sons, Inc., 1999).

Laskar, Joy, Matinpour, Babak &Chakraborty, Sudipto (2004).Modern Receiver Front-Ends - Sys-tems, Circuits, and Integration,1st edition.ISBN 0-471-22591-6(John Wiley & Sons, Inc., 2004).

Oppenheim, Alan V. & Schafer,Ronald W. (1998).Discrete time signal processing,2nd edition.ISBN 0-13-754920-2(Prentice Hall, 1998).

www.ni.com (2004).National Instruments - Test and Mea-surement(web, 2004),URL www.ni.com. Existed 051208.

28

Page 41: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Part II

Appendix report

29

Page 42: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Appendix ASound card

Sampling a signal using a PC sound card is only possible if the sound card meetsa certain specification set by the properties of the input signal. The input signalmay also have to be adapted to meet the input specification of the sound card.The purpose of this appendix is to examine the specification of a general PC soundcard. Audio Codec ’97 is a royalty-free sound card standard developed by IntelCorporation. The specification defines the architecture and digital interface of asound card including analog performance characteristics of the input signal. Inorder to sample the input signals there are a few key parameters that have tobe met by the AC’97 standard. These parameters include the bandwidth andthe sampling resolution. In the AC ’97 v2.3 Component Specification the keyparameters concerning the frequency response and sampling frequency are listedas in table A.1. [Intel Corporation, 2002] Other parameters that have to be taken

Parameter Min typ Max UnitsSampling Frequency - - 48000 HzAnalog frequency responce ± 1 dB 20 - 20000 HzTransition band 19100 - 28800 HzStop band 28800 - - HzStop band rejection -74 - - dBGroup delay - - 1 ms

Table A.1: Frequency response of an AC’97 compliant sound card.

into consideration when sampling using an AC’97 sound card are listed in table A.2AC’97 defines the sampling resolution as full-duplex 16 bit.

Parameter Min typ Max UnitsMic full scale input voltage (20 dB boost) - 0.1 - VrmsMic full scale input voltage (0 dB boost) - 1 - VrmsInput imdance 10 - - kΩInput Capacitance - 7.5 - pF

Table A.2: Input parameters of an AC’97 compliant sound card.

30

Page 43: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX B. MODULATION

Appendix BModulation

The purpose of a communication system is to transmit an information-bearingsignal m(t) from a transmitter to a receiver. The information-bearing signal isreferred to as the baseband signal, where the term baseband is used to designatethe band of frequencies representing the original signal.

Often it is necessary to shift the baseband frequencies to a frequency range moresuitable for transmission, which is done by modulation. Modulation is a methodwhere a carrier signal is changed in accordance to a modulation signal. As carriersignal a sinusoidal wave is often used, in which case the modulation becomes acontinuous-wave modulation process. The modulation signal is the baseband signal,and the result of the modulation is referred to as the modulated signal.

In this report two types of modulation technics are described: amplitude mod-ulation (AM) and frequency modulation (FM). In AM the modulation signal m(t)modulates the amplitude of the carrier signal c(t), and in FM the modulation signalm(t) modulates the frequency of the carrier signal c(m). In figure B.1 a AM- andFM-signal is shown. For the AM signal the frequency is determined by c(t) andthe amplitude is determined by m(t), whereas for the FM signal the amplitude isdetermined by c(t) and the frequency is determined by m(t). The appendix is basedon [Haykin, 2001, Page 88-93 and 109-120] and [Johnson et al., 1999, Page 325 andchapter 17].

B.1 Amplitude modulation

AM is defined as a process in which the amplitude of the carrier wave ct is variedabout a mean value, linearly with the baseband signal mt. If the carrier wave isgiven as

c(t) = Ac cos(ωct) (B.1)

then the modulated signal can be described in its general form as

s(t) = Ac[1 + kam(t)] cos(ωct) (B.2)

where:ka is the amplitude sensitivity [V]

31

Page 44: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

B.1. AMPLITUDE MODULATION

2 4 6 8 10 12t [s]

Carrier wave

2 4 6 8 10 12t[s]

Modulation signal

2 4 6 8 10 12t[s]

Amplitude modulated signal

2 4 6 8 10 12t[s]

Frequency modulated signal

Figure B.1: Illustration of the carrier wave, baseband signal, amplitude modulatedsignal and frequency modulated signal.

In equation B.2 it is clear that the value of kam(t) determines the amplitude of themodulated signal. The value of kam(t) must therefore be chosen suitabl in order

2 4 6 8 10 12t[s]

Amplitude modulated signal Ka = 0.5

2 4 6 8 10 12t[s]

Amplitude modulated signal Ka = 1

2 4 6 8 10 12t[s]

Amplitude modulated signal Ka = 2

Figure B.2: Amplitude modulation of a signal using three different values of ka.Values above 1 result in over modulation and phase reversal.

to avoid over modulation and phase reversal. Figure B.2 illustrates an AM signal

32

Page 45: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX B. MODULATION

with three different values of ka and

m(t) = sin(1 · t) (B.3)

The upper graph illustrates the situation with ka = 0.5 where the original signalm(t) is clearly represented as the envelope of the AM signal. The middle graphillustrate the situation with ka = 1. As with ka = 0.5 the original signal is clearlyrepresented as an envelope, but the modulation signal now completely eliminatesthe carrier signal during it’s minimum level. The bottom graph illustrates thesituation with ka = 2 and the baseband signal is no longer an envelope of the AMsignal, hence it follows that to avoid over modulation and phase reversal

|kam(t)| < 1. (B.4)

An other criteria for the modulation to be successful is

fc >> W (B.5)

where:W is the highest frequency component of the baseband signal m(t) [Hz]

If this criterion is not fulfilled it will not be possible to visualize an envelope.The criterion is illustrated in Figure B.3, where the graphs on the left illustratethe AM using a carrier frequency 20 times as fast as the baseband signal, resultingin a clear envelope of the baseband signal, as in the bottom left graph. On theright a carrier frequency only twice as fast as the baseband signal is used, and thebaseband signal can hardly be recognized in the AM signal as in the bottom rightgraph.

2 4 6 8 10 12t [s]

Carrier wave (20 ω/s)

2 4 6 8 10 12t[s]

Modulation signal (1 ω/s)

2 4 6 8 10 12t[s]

Amplitude modulated signal

0 2 4 6 8 10 12

−0.5

0

0.5

1

t [s]

Am

plitu

de

Carrier wave (2 ω/s)

0 2 4 6 8 10 12

−0.5

0

0.5

t[s]

Am

plitu

de

Modulation signal (1 ω/s)

0 2 4 6 8 10 12

−1

0

1

Am

plitu

de

t[s]

Amplitude modulated signal

Figure B.3: Amplitude modulation using two different carrier frequencies.

In order to determine the frequencies contained in the modulated signal equationB.2 is rewritten, and m(t) is replaced by a sinusoidal wave.

33

Page 46: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

B.2. FREQUENCY MODULATION

s(t) = Ac cos(ωct) + Acka cos(ωct) sin(ωmt) (B.6)

From equation B.6 it can be seen that the modulated signal contains the carrierfrequency fc and the frequencies of the product

Acka cos(ωct) sin(ωmt). (B.7)

In order to determine the frequencies of the product, the product is rewritten byEuler.

Acka

j4

(ejωct + e−jωct

)·(ejωmt − e−jωmt

)(B.8)

Acka

j4

(ejωct · ejωmt − ejωct · e−jωmt + e−jωct · ejωmt − e−jωct · e−jωmt

)(B.9)

Acka

j4

(ej(ωc+ωm)t − ej(ωc−ωm)t + ej(−ωc+ωm)t − ej(−ωc−ωm)t

)(B.10)

Acka

2

(sin((ωc + ωm)t) + sin((−ωc + ωm)t)

)(B.11)

Equation B.11 shows that the frequencies contained in the product are (ωc + ωm)and (−ωc + ωm). Figure B.4 shows the frequency spectrum of an AM signal where

fc = cos(2 · π · 200 · t)fm = sin(2 · π · 5 · t)ka = 0.5

Figure B.4 (a) shows that the three frequencies exists as both positive and negativefrequencies. This means that the frequency (−ωc + ωm) also exist as a positivefrequency (ωc − ωm) and (ωc + ωm) exist as a negative frequency (−ωc − ωm). Inpractice negative frequencies do not exist, and only the positive frequencies are leftas shown in figure B.4 (b). Figure (b) shows that the side frequencies (ωc + ωm)and (ωc − ωm) are placed on each side of the carrier frequency with a distance ofωm.

B.2 Frequency modulation

FM is defined as a process in which the frequency of the carrier wave fc is variedabout a mean value, as a function of the amplitude for the baseband signal fm. Ifthe modulation signal is a sinusoidal signal defined as

m(t) = Am cos(ωmt) (B.12)

then the instantaneous frequency is defined by

fi(t) = fc + kfAm cos(ωmt) (B.13)fi(t) = fc + ∆f cos(ωmt) (B.14)

34

Page 47: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX B. MODULATION

185 190 195 200 205 2100

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5x 10

4 (b)

frequency (Hz)

S(f

)

−400 −200 0 200 400

x 104 (a)

frequency (Hz)

Figure B.4: (a) Spectrum of the AM signal (b) Detailed spectrum of the positivefrequencies

where:ωn is the cut-off frequency [rad/s]Q is the quality factor [·]∆f = kfAm [Hz]

The unit ∆f is the frequency deviation, representing the maximum frequency varia-tion from the carrier frequency. The characteristic for FM is that ∆f is proportionalto the amplitude of the modulation signal, and independent of the frequency of themodulation signal. To get a expression for how much the frequency changes overa period from 0 to t equation B.14 is integrated and the phase of the modulatedsignal is obtained.

Θi(t) = 2π

∫ t

0

fi(τ)dτ (B.15)

Θi(t) = 2πfct + 2πkf

∫ t

0

m(τ)dτ (B.16)

A signal having the carrier amplitude Ac and the instantaneous phase discussedabove yields the FM signal:

s(t) = Ac cos(

2πfct + 2πkf

∫ t

0

m(τ)dτ

)(B.17)

The ratio of the frequency deviation ∆f = kf ·Am, to the modulation frequency iscalled the modulation index which is given as

β =∆f

fm(B.18)

If the modulation index is substituted into equation (B.16) a new expression forΘi(t) is achieved.

Θi(t) = ωct + β sin(ωmt) (B.19)

35

Page 48: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

B.2. FREQUENCY MODULATION

From equation B.19 it can be seen that the β represents the phase deviation of theFM signal. This means that β represents the maximum variation from the angleωct. The FM signal can now be expressed as

s(t) = Ac cos[ωct + β sin(ωmt)

](B.20)

Determining the spectrum of a FM signal is not as easy as it was for a AM signal.This is because an FM signal modulated by a sinusoidal wave shown in equationB.20 is not a periodic function unless the carrier signal frequency fc is a integermultiple of the modulation signal fm. A different method to determine the spectrumis therefore necessary. By rewriting equation B.20 the following expression for s(t)can be achieve

s(t) = Re[Ace

jωct+jβ sin(ωmt)]

(B.21)

s(t) = Re[s(t)ejωct

](B.22)

Where s(t) is a complex envelope of the FM signal s(t), given by

s(t) = Acejβ sin(ωmt) (B.23)

Unlike the FM signal, the complex envelope s(t) is periodic over time. This meansthat s(t) can be expanded by the complex fourier series, which is defined as

s(t) =∞∑

n=−∞cnejωmnt (B.24)

where the complex fourier coefficient cn is defined by

cn =1T

∫ T2

−T2

s(t)e−jωmntdt (B.25)

Inserting the value of s(t) from equation B.23 into equation B.25

cn =Ac

∫ π

−π

ejβ sin(ωnt) · e−jωntdt (B.26)

cn =Ac

∫ π

−π

ejβ sin(ωnt)−jωntdt (B.27)

Defining a new variable x = ωmt and inserting it in equation B.27 gives

cn =Ac

∫ π

−π

ej(β sin(x)−nx)dx (B.28)

Except for Ac equation B.28 can be recognized as the n‘th order Bessel function ofthe first kind and argument β, which is commonly denoted as

Jn(β) =12π

∫ π

−π

ej(β sin(x)−nx)dx (B.29)

36

Page 49: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX B. MODULATION

This gives a new expression for cn

cn = Ac · Jn(β) (B.30)

Substituting equation B.30 into equation B.24

s(t) = Ac

∞∑n=−∞

Jn(β)ejωmnt (B.31)

Now substituting the new expression for s(t) back into equation B.22 gives

s(t) = Ac ·Re[ ∞∑

n=−∞Jn(β)ej(ωc+nωm)t

](B.32)

By remembering that

Re[ej(ωc+nωm)t

]= cos

[(ωc + nωm)t

](B.33)

equation B.32 can be rewritten to

s(t) = Ac

∞∑n=−∞

Jn(β) · cos[(ωc + nωm)t

](B.34)

Fourier transform of equation B.34 is done by using the cosine fouries transformpair, thus the frequency spectrum of a FM signal equals

S(t) =Ac

2

∞∑n=−∞

Jn(β) ·[δ(f − nfm − fc) + δ(f + nfm + fc)

](B.35)

A plot of the Jn(β) is shown in Figure B.5. The first 4 orders are plotted with βvalues from 0 to 15. Figure B.6 show the besselfunction order from n = −25to25with β = 1 5 15. The figure clearly shows that the bandwidth needed whenfrequency modulating a fixed single tone base band signal (fm = constant) increasewhen β is increased. The absolute of the besselsfunction are symmetric around n =0, thus the side frequencies is symmetric around fc. The needed bandwidth can beestimated by inspection of the amplitude of each of the delta functions in equationB.35. If the amplitude of a delta function (or side frequency) is e.g. less then 1%of the maximum amplitude, it is said not to hold important information about theoriginal signal, and the amount of significant side frequencies can be calculated.The amplitude of the side frequencies is scaled by |Jn(β)|. Thus all significantfrequencies have |Jn(β)| > 0.01. Figure B.7 on page 39 shows the numbers of sidefrequencies with β values from 0.1 to 15.

37

Page 50: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

B.2. FREQUENCY MODULATION

5 10 15

β

0 order1st order2nd order3rd order

Figure B.5: Besselfunktions of 0 to 3 orders as a function of β.

−20 −15 −10 −5 0 5 10 15 20 25

n

−20 −15 −10 −5 0 5 10 15 20 25

n

−20 −15 −10 −5 0 5 10 15 20 25

n

Figure B.6: First 25 orders of the besselfunction with 3 fixed β values

38

Page 51: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX B. MODULATION

5 10 15β

Significant side frequencies

Figure B.7: Numbers of significant side frequencies (|Jn(β)| > 0.01)

39

Page 52: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Appendix CDownconverter

A modulated radio signal that is received through an antenna, sr(t), has two im-portant characteristics; a carrier frequency fc and a signal bandwidth fBW. Thebandwidth is centered around the carrier frequency as illustrated in figure C.1.In order to restore the message signal from the modulated signal, it is convenientto translate the signal down in frequency by some fdis as also shown in figureC.1. Displacement of a signal spectrum is referred to as frequency translation andtranslating a signal down in frequency is referred to as frequency down-conversion.[Haykin, 2001, page 103]

f

|S(f)|

fc − fdis fc

fdis

Figure C.1: Displacement of frequency spectrum.

C.1 Requirements

In this particular project the requirement for downconversion is to displace a smallspectrum FM signal so that the signal can be sampled using an AC’97 compliantsound card, described in appendix A, which yields the specifications mentioned intable C.1. The received signal will be the one described in chapter 2, hence thecarrier frequency is approximately known and so is the bandwidth of the signal. Aquick calculation yields that it should be possible to fit the received signal band-width of 16 kHz, into the valid band of input frequencies of the sound card whichis ≈ 19.2 kHz. In the design it is assumed that the received radio channel does nothave any neighbouring channels.

40

Page 53: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX C. DOWNCONVERTER

Parameter Value UnitsReceived signal fc 145 MHzReceived signal fBW 16 kHzDownconverted signal fmin 20 HzDownconverted signal fmax 19.2 kHz

Table C.1: Specifications of input and output of the downconverter.

C.2 Building blocks

Downconverters are very common and despite the fact that they can be constructedin many ways, they all consist of a few simple building blocks, which will be de-scribed in the following.

C.2.1 Mixer

The mixer is essentially a product modulator, that multiplies the received signalsr(t) with a local oscillator (LO) signal Ac cos(ωLOt). As a result of this, thespectrum of sr(t) is moved along the frequency axis by fLO. The amplitude ofthe translated signal will be (Ac/2)sr(t). Whenever a signal is mixed in order totranslate it in frequency, two spectras are created - each with the same bandwidthbut with different carrier frequencies; the one is the received signal shifted down-wards and the other is the received signal shifted upwards in frequency. This issketched in figure C.2 and shown mathemathically in section C.4. [Haykin, 2001,pages 94-95,103-104]

f1 = fc − fLO (C.1)f2 = fc + fLO (C.2)

Refering to figure C.2, fLO should be chosen so that the spectrum near −f1 does

f

|S(f)|

−fc −f1 f1 fc f2−f2

Figure C.2: Mirrors as a result of product modulation.

not overlap with the spectrum near f1, because sideband overlapping complicatesthe situation significantly. This is also why it is not trivial to build zero IF receivers,i.e. conversion directly to baseband. [Laskar et al., 2004, pages 32-44]

Mixers are available as premanufactured building blocks for various frequency ranges.A mixer has 3 terminals; RF (Radio Frequency), LO (Local Oscillator) and IF (In-

41

Page 54: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

C.3. BLOCK DIAGRAM

termediate Frequency). The block diagram symbol of a mixer is shown in figureC.3.

Figure C.3: Symbol of a 3-terminal mixer.

C.2.2 Filter

To perform image rejection on either the down converted or up converted signal,a bandpass filter can be applied. The filter should have a midband frequency neareither f1 or f2 depending on which one is wanted, and a bandwidth equal to thebandwidth of the signal fBW . Most modern wireless standards require 60 - 90 dBof image rejection. [Laskar et al., 2004, page 30]

Filters are available as premanufactured building blocks, with various standardintermediate frequencies. There are other building blocks that can be utilized indownconverters, e.g. phase-locked loops (PLLs) and phase shifters. Since these arenot nescessary for this application, they will not be discussed further.

C.3 Block diagram

Often the design of the downconverter is closely related to the demodulator thattypically follows it, and they are often very integrated, as the downconverter doesa part of the demodulation or prepares the signal for a particular demodulation.

In this project the aim is to keep as much of the processing as possible in thedigital domain, and therefore it is desireable to capture the received signal as un-processed as possible, hence simplifying the downconverter. One solution is shownin the block diagram of figure C.4. The downconversion is done in two steps using

Figure C.4: Block diagram of a possible downconverter solution.

two mixers. At the output of each mixer a filter is applied for mirror selectivity. Tointerface correctly with the sound card described in appendix A, the filter shouldbe followed by an automatic gain control (AGC).

42

Page 55: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX C. DOWNCONVERTER

C.4 Mathematical analysis

The purpose of the downconverter is to translate the RF bandpass signal, into alow IF bandpass signal, which can be sampled by an soundcard. The input signalto the downconverter will be in the form as shown in appendix B:

s(t) = Ac cos[ωc · t + β sin(ωct)

](C.3)

At any give time the signal can be described as:

si(t) = A1 cos(ω1t) (C.4)

This signal is then multiplied with a cosine in a circuit known as a product mixer.This yields:

A1 · cos(ω1 · t) ·A2 · cos(ω2 · t) (C.5)

By means of Euler this is:

12A1A2 · (ej·t·ω1 + e−j·t·ω1) · 1

2· (ej·t·ω2 + e−j·t·ω2) = (C.6)

A1A2

4

[ej·t·ω1ej·t·ω2 + e−j·t·ω1ej·t·ω2 + ej·t·ω1e−j·t·ω2 + e−j·t·ω1e−j·t·ω2

]= (C.7)

A1 ·A2

2·[cos[(ω1 + ω2) · t] + 1

2·(e−j·t·ω1 · ej·t·ω2 + ej·t·ω1 · e−j·t·ω2

)]= (C.8)

A1 ·A2

2·[cos[(ω1 + ω2) · t] + cos[(ω1 − ω2) · t]

](C.9)

The result of the mixing is two frequency components, the sum and differencefrequencies. By bandpass filtering at (ω1−ω2) the incoming signal is translated toa lower frequency. Next the new signal is again mixed with a cosine at frequencyω3:

A1 ·A2

2· cos[(ω1 − ω2) · t] ·A3 · cos(ω3 · t) (C.10)

The result of this mixing is:

A1 ·A2 ·A3

4·[cos[(ω1 − ω2 − ω3) · t] + cos[(ω1 − ω2 + ω3) · t]

](C.11)

After a bandpass or lowpass filter only the low frequency components are passedyielding:

A1 ·A2 ·A3

4· cos

[(ω1 − ω2 − ω3) · t

](C.12)

Remembering that the input signal was substituted for equation (C.4) this yieldsthat the output signal will be:

Ac ·A2 ·A3

4· cos

[(ωc − ω2 − ω3) · t + β · sin(ωm · t)

](C.13)

43

Page 56: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

C.5. DIMENSIONING

C.5 Dimensioning

As the intermediate frequency between the mixers the frequency 70 MHz, is chosen.The LO frequencies is determined, selecting the center frequency of the downcon-verted signal to approximately the center frequency of the sound cards band ofvalid input frequencies, 9 kHz:

fLO,1 = 75 MHz (C.14)fLO,2 = 145 · 106 − 75 · 106 − 9 · 93 = 69.991.000 Hz (C.15)

As generators for fLO,1 and fLO,2, laboratory RF signal generators are used.The model names of the ones used can be found in appendix C.6. The mixers arechosen on the basis of the needed frequency ranges. The types used are mentionedin table C.2.

Manufacturer Model No. LO/RF IF UnitsMini-Circuits ZFM-3 0.04 - 400 DC - 400 MHzMini-Circuits ZFM-15 10 - 3000 10 - 800 MHz

Table C.2: Specifications of mixers.

The component mentioned in table C.3 is the used bandpass filter.

Manufacturer Model No. Type fc fBW SectionsTexscan (Trilithic) 3BC 70/5-3-KK BP 70 MHz 5 MHz 3

Table C.3: Specifications of bandpass filter.

The lowpass filter used is mentioned in table C.4 The attenuation is less than 1dB in the pass band and more than 40 dB in the stop band.

Manufacturer Model No. Type Passband Stop band UnitsMini-Circuits SLP-1.9 LP DC - 1.9 4.7 - 200 MHz

Table C.4: Specifications of lowpass filter.

C.6 Measurements of downconverter

The purpose of the measurements is to document that the downconverter is capableof translating radio frequency signals at fRF = 145 MHz down to fIF = 9 kHz. Thebandwidth of the signal is fBW = 16 kHz. The downconverter is being tested trans-lating a number of sinusoidal signals having fixed frequencies between fRF−0.5·fBW

and fIF + 0.5 · fBW. The frequency of the output signals is measured with an os-cilloscope, and it is verified that the waveforms have the correct frequency and form.

44

Page 57: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX C. DOWNCONVERTER

C.6.1 Method

The test setup is shown i figure C.5. Note that the generators for the LO signalsare considered as part of system. The generator and indicators used are mentionedin table C.5.

Figure C.5: Test setup for downconverter.

Symbol Type Model Manufacturer AAU-nrSG1 Signal Generator 2022 Marconi 08158IND1 Oscilloscope 2254A Tektronix 08388LO1 Signal Generator 2022D Marconi 33336LO2 Signal Generator 2022D Marconi 33337

Table C.5: Equipment used in test.

The test frequencies is chosen to cover the maximum and minimum frequenciesin a 16 kHz wide signal around 145 MHz:

f1 = fRF − 0.5 · fBW = 145 · 106 − 0.5 · 16 · 103 = 144.992.000 Hz (C.16)f2 = fRF = 145 MHz (C.17)f3 = fRF + 0.5 · fBW = 145 · 106 + 0.5 · 16 · 103 = 145.008.000 Hz (C.18)

The outcome of these three inputs should be 1 kHz, 9 kHz and 17 kHz.

1. Adjust the SG1 to a sine wave with with amplitude of -30 dBm, withoutmodulation.

2. Adjust the frequency of SG1 to f1.

3. On IND1, adjust the timebase and volt input attenuator to obtain the bestaccuracy.

Repeat above procedure for the three test cases.

C.6.2 Results

The results of the test is shown in table C.6.

45

Page 58: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

C.7. SUMMARY

Carrier frequency Output frequency Output level Time base Input attenuator144.992 MHz 1.0 kHz 3.36 mV 200 µs 2 mV145.000 MHz 9.0 kHz 3.36 mV 20 µs 2 mV145.008 MHz 17.0 kHz 3.32 mV 10 µs 2 mV

Table C.6: Result of test.

The total voltage loss through the converter can be calculated as

VLoss = 20 · log10

( Vin

Vout

)[dB] (C.19)

In radio communication a unit of measure called dBm is often used this is definedby the logarithm to the input signal relative to 1 mW into the working impedance,as follows

X = 10 · log10

( Pin

10−3

)[dBm] (C.20)

where:X is the input level. [dBm]Pin is the input power. [W]

Solving for the input power yields

Pin = 10( X10 ) · 10−3 [W] (C.21)

With an input level of -30 dBm this yields 1 µW, which is the equivalent of 7mV assuming 50 Ω impedance. Inserting the results of table C.6 and the 7 mV inequation (C.19) yields a loss of:

VLoss = 6.46 [dB] (C.22)

C.7 Summary

The test described in appendix showed that the downconverter is able to translateRF signals near 145 MHz to a low IF of 9 kHz. Furthermore the insertion loss ismeassured to 6.46 dB with an input level of -30 dBm. The insertion loss may varyfor other input levels.

46

Page 59: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX D. INPUT-FILTER

Appendix DInput-filter

The FM signal from the downconverter is to be sampled in the soundcard of thecomputer. Implemented in the soundcard of the computer is a filter. In this ap-pendix this filter will be analyzed in order to compare it with the input signal.

D.1 Filter-specifications

In appendix C and C.6 the signal from the downconverter is described and verified.From these appendices the signal is known to have the specifications shown in tableD.1.

FrequencyfBW 16 kHzfcenter 9 kHzfmin 1 kHzfmax 17 kHz

Table D.1: Specifications for the signal from the downconverder.

The filter implemented in the soundcard of the computer has the specificationsshown in table D.2.

Min Max UnitsAnalog frequency response 20 20000 HzTransition band high 19200 28800 HzStop band 28800 - HzStop band rejection -74 - dB

Table D.2: Specifications for the antialiasering filter in the soundcard. [Intel Cor-poration, 2002]

Comparing the signal from the downconverter with the soundcard filter it isclear that the signal bandwidth is less then the analog frequency response of the

47

Page 60: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

D.2. FILTER-DESIGN

soundcard filter. Because the frequencies below 1 kHz and above 17 kHz will beinterpret as noise, it is chosen to build a band pass filter, with cut-off frequenciesat 1 kHz and 17 kHz.

In the following section a 4th order Butterworth band pass fiter will be designedwith the specified cut-off frequencies at 1 kHz and 17 kHz.

D.2 Filter-design

The band pass filter will be designed as a combination of a high pass- and a low passfilter with cut-off frequencies of 1 kHz and 17 kHz respectively. In the following thelow pass filter and the high pass filter will be designed separately and afterwardscombined to make the band pass filter. The filters will be realized with a Sallenand Key filter with 0 dB attenuation in the passband.

Each of the filters are designed after the following procedure

• Find the transfer function with cut-off frequency normalized to 1 rad/s.

• Find the values for the components used to realize the Sallen and Key filter.

• Denormalize the component values to get the desired cut-off frequencies at 1kHz and 17 kHz.

D.2.1 Low pass-filter

From [Huelsman, 1993] the transfer function for a 2nd order low pass Butterworthfunction with cut-off frequency at 1 rad/s is defined as

NLP(s) =1

s2 + 1.414s + 1(D.1)

From appendix H the design formulas for a low pass 2nd order Sallen and Key filterwith 0 dB attenuation in the pass band are given as

ωn =1√

mnRC(D.2)

1Q

= (n + 1)√

m

n(D.3)

K = 1 (D.4)

where:ωn is the cut-off frequency [rad/s]Q is the quality factor [·]m = C104

C102[·]

n = R103R101

[·]R = R101 [Ω]C = C102 [F]

Choosing m so that

48

Page 61: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX D. INPUT-FILTER

m ≤ 14Q2

(D.5)

then n can be found as

n =( 1

2mQ2− 1

)± 1

2mQ2

√1− 4mQ2. (D.6)

From equation D.1, Q can be found as

Q =√

11.414

= 0.707 (D.7)

Now m can be found by inserting Q in equation D.5

m ≤ 14 · 0.7072

(D.8)

m ≤ 0.5 (D.9)

Choosing m to be 0.3, it is now possible to find n by inserting the value of m andQ in equation D.6

n =( 1

2 · 0.3 · 0.7072− 1

)± 1

2 · 0.3 · 0.7072

√1− 4 · 0.3 · 0.7072 (D.10)

n = 5 ∧ −0.25 (D.11)

Choosing n to be 5, it is possible to find the value of the product RC in equationD.2

1 =1√

0.3 · 5RC(D.12)

RC = 0.8 [Ω · F] (D.13)

Choosing C to 0.001 F, R can be found to be

R =0.8

0.001≈ 750 [Ω] (D.14)

From the definition of m and n C104 and R103 can now be found

C104 = C · 0.3 = 0.0003 [F] (D.15)

and

R103 = R · 5 = 3750 [Ω] (D.16)

49

Page 62: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

D.2. FILTER-DESIGN

In order to get a cut-off frequency at 17 kHz an impedance denormalization is made.This is done by dividing the capacitors with the denormalization factor, which isthe cut-off frequency in rad/s. This gives the following capacitors

C102D =C102

2 · π · 17000≈ 10 · 10−9 [F] (D.17)

C104D =C104

2 · π · 17000≈ 3.3 · 10−9 [F] (D.18)

D.2.2 High pass-filter

In order to obtain the transfer function of the 2nd order high pass Butterworthfunction, a transformation of the low pass 2nd order Butterworth function is made.

Recall from above that the transfer function for a 2nd oder low pass Butterworthfunction is given as

NLP(s) =1

s2 + 1.414s + 1(D.19)

By replacing s with 1s the low pass filter can be transformed to a high pass filter

which gives

NHP(s) =s2

s2 + 1.414s + 1(D.20)

Now the filter can be designed using the design formulas from appendix H

ωn =1√

mnRC(D.21)

1Q

=m + 1√

mn(D.22)

where:m = C103

C101[·]

n = R104R102

[·]R = R102 [Ω]C = C101 [F]

Setting m to 1 gives

ωn =1√

nRC(D.23)

Q =√

n

2(D.24)

In equation (D.7), Q was found to be 0.707, which gives a value of n

0.707 =√

n

2(D.25)

n = 2 (D.26)

50

Page 63: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX D. INPUT-FILTER

Knowing n, it is now possible to find the value of the product RC in equation(D.23)

1 =1√

2RC(D.27)

RC = 0.707 [Ω · F] (D.28)

Choosing C to be 6 · 10−4 F gives

R =0.707

6 · 10−4(D.29)

R = 1178 [Ω] (D.30)

Now C103 and R104 can be found from the definition of m and n

C103 = C · 1 = 6 · 10−4 [F] (D.31)

and

R104 = R · 2 = 2357 [Ω] (D.32)

In order to get a cut-off frequency at 1 kHz a impedance denormalization is made.This is done by dividing the capacitors with the denormalization factor, which gives

C103D =C103

2 · π · 1000≈ 100 · 10−9 [F] (D.33)

C101D =C101

2 · π · 1000≈ 100 · 10−9 [F] (D.34)

Now that both the low pass- and high pass filter have been designed, it is possibleto combine the filters in order to make the band pass filter.

D.2.3 Band pass-filter

Combining the low pass- and high pass filters gives the band pass filter shown infigure D.1.

Component Value [Ω] Component Value [F] Component TypeR101 750 C101D 100n IC101 TLC072R102 1178 C102D 10n IC102 TLC072R103 3750 C103D 100nR104 2357 C104D 3.3n

Now a band pass filter which meets the specifications listed in section D.1 hasbeen designed. Before constructing the filter a simulation is made to verify that itsatifies the design specifications.The simulation has been done in LT-SPICE.

51

Page 64: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

D.3. FILTER-SIMULATION

C104R104C103Vin VoutR102 C102

R103R101C101Figure D.1: 4th order band pass Sallen and Key filter

D.3 Filter-simulation

In this section the bandpass filter is simulated. This is done using a simulationprogram (LT-spice). The simulation is made in the frequency spectrum from 1 kHzto 90 kHz.

The result of the simulation is shown in figure D.2. In the figure it can be seenthat the filter has the 3 dB cut-off frequencies at around 1 kHz and 17 kHz, whichwere the specifications of the filter. It can also be seen that the filter has 0 dB gainin the pass band.

103

104

Frequency

Figure D.2: Simulation of the bandpass filter.

This shows that the filter design works as desired. The final filter test will bemade as a part of the system test.

52

Page 65: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX E. MULTITHREADING

Appendix EMultithreading

This chapter describes the concept of multithreading, and later introduces the”standard” posix threading library, and the library used in this project: the GNUPth library.

E.1 General multithreading

Multithreading gives the programmer the possibility of splitting the program execu-tion into multiple ”threads”, or multiple sub-programs. One sub-program (hence-forth thread) can handle for example polling of input. The main program couldcontinue executing, while the polling-thread wakes up periodically and polls theinput source. This gives a better code structure, and possibly a better utilisation ofthe processing power than conventional approaches to polling via while-loops andthe likes.

E.1.1 Multithreading pros

One attribute of multithreading is the possibility of parallel running tasks. The ad-vent of multicore processors has enabled “true” parallelism. Logically, a processorcan only do one calculation at a time, which causes the case of “pseudo-parallelism”,wherein a single processor switches thread according to its orders. But only onethread is actually running at a single time. With multiple processors it is actuallypossible to run several tasks at once. But a program must be written with multi-threading in mind, if it is to take advantage of multiple processors.

Multithreading grants the programmer improved control of which task is executedwhen, and for how long. This is important in realtime applications, where the “re-altime task” can be granted more or fewer cpu-cycles, at the cost of degraded theperformance of other tasks in the program (the user interface, for instance).

E.1.2 Multithreading cons

Using multithreading in an application requires more preparation and design thanconventional single thread programming. The two primary cases to consider are

53

Page 66: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

E.2. SELECTION OF THREADING API

1. Preemptivity

2. Data access

Preemptivity is the mechanism the processor uses to switch threads. Generallythere are two types; voluntarily switching (non-preemptive) and forced switching(preemptive). In preemptive mode, a scheduler controls the amount of cpu-cyclesgranted to a thread, and when the thread has used its cpu cycles, it is stoppedand another thread resumes. When the scheduler assigns more cpu-cycles to thethread, it resumes from where it last stopped.

Non-preemptive program execution allows the threads to decide for themselveswhen they will release control to the scheduler. This can be done by calling ayield function, which causes the scheduler to assume control and then decide whichthread to activate next. This gives more control to the programmer, who thencarefully must decide when to yield control to the general scheduler.

Data access is an area which requires special consideration in multithreaded ap-plications. The impact is most profound in preemtive execution mode, where astatement can cause a read from the harddrive and then get interrupted by thescheduler, which then orders another thread to write to the same harddisk area.This would cause a conflict and possibly invalid data. This problem is not soprofound in non-preemptive execution, as the threads themselves yield control.

The solution for this problem is in using a “mutex” (mutual exclusion) variable,that can be claimed by various threads in turn, thereby ensuring that only onethread has access to a specific memory area at a time. See section E.3.2 for moreinformation about events.

E.2 Selection of threading API

The main threading libraries/APIs considered for this project, are the Posix threadsand GNU Pth. Posix threads are the inbuilt thread mechanism in linux, and in-terface directly with the kernel. The GNU Pth is a ”lightweight” threading librarywhich does userspace threading control. In short, the Posix threads use the kernelthread switching and Pth uses its own scheduler.

This poses a significant difference between the libraries, namely the Posix li-brary being preemptive and the Pth library being non-preemptive.

The chosen API for this project is the GNU Pth as it is

• Non-preemptive

• Relatively small

• Well-documented

In using a non-preemptive threading model, the code execution is more predictableand thus eases the task of management and implementation. Being non-preemptiveand userspace controlled, the GNU Pth library cannot benefit from multiple pro-cessors. This is a drawback, but not of great importance to this project, as multi-processor machines are still uncommon in the pool of household PCs.

54

Page 67: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX E. MULTITHREADING

The size of the API and its documentation level plays a significant role in thedevelopment of the software. The Posix threading library has many different im-plementations and function calls, and choosing between them seems like a dauntingtask. The GNU Pth library has just one implementation, which is easy to examineand understand. The homepage and manual for GNU Pth can be found at [En-gelschall, 2005].

The documentation and ease of use are the main reasons for the choice of GNUPth. This project uses the following version of the GNU Pth packages: libpth2(2.0.1-2.1) and libpth-dev (2.0.1-2.1).

E.3 GNU Pth general usage

This section will briefly cover the commands used.

E.3.1 Thread control

The basics of the thread control lie in the GNU Pth inbuilt scheduler. The mecha-nism is shown in figure E.1. The ready-queue contains threads that wish to use thecpu. Each thread has a priority, with the highest priority being picked first. Thepicked thread is placed in the running queue, and all the remaining threads in theready queue have their priority increased by 1.

New

Ready

Waiting

Suspended

Running

Dead

Figure E.1: Scheduling mechanism of GNU Pth. A thread can be placed in a singlequeue, according to its state.

A thread can exit the running state by calling pth yield(), which places thecalling thread in the ready queue with its priority reset, and relinquishes control tothe scheduler.

The waiting queue is used for threads awaiting an event (pth wait()), threadssuspended for a certain amount of time (pth nap()) or similar, see section E.3.3 formore information about events.

55

Page 68: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

E.3. GNU PTH GENERAL USAGE

The suspended state is used by suspended threads (pth suspend()). In thisstate, threads are dormant and will only enter the ready queue if unsuspended byanother thread.

The new and dead queues are used for newly created threads, and threads whichare to be removed from the program.

E.3.2 Mutexes

One way to ensure the integrity of shared data used by multiple threads is byapplying a mutex. A critical section is a part of the program that must only beaccessed by one thread at a time. A mutex works like a lock; before a thread entersa critical section in a program it acquires the lock. The thread now owns the lockand can enter the critical section. Any other threads trying to access the criticalsection will be unsuccessful, because they can not acquire the lock. These threadsare suspended and placed in a queue.

When the lock is released by its owner upon exit of the critical section, the firstthread in the queue will be placed in the ready queue. Locking parts of a programis not without drawbacks and the order in which the critical sections are lockedis important to ensure fast execution of the code and to avoid deadlocks. Criticalsections that have long execution times should be locked before sections with lowerexecution times or more heavily loaded sections.

Deadlocks can occur if e.g. thread A locks section A and then thread B lockssection B. Thread A now wants to lock section B, but can’t because thread B ownsthe lock, thus thread A is suspended. Thread B now wants to lock section A, butcan’t because thread A owns the lock, thus thread B is suspended. The result isthat both threads wait for each other to unlock the sections and the threads are indeadlock. A solution to this problem is to decide on the order in which the sectionsare locked. Had both thread A and B tried to lock section A first, then threadB would be suspended trying to lock section A and the deadlock would not haveoccurred.

E.3.3 Events and message queues

Inter-thread communication can be achieved with the use of message queues. Threadscan post and tap messages to and from the queue, and thereby share data etc. Amessage queue is created with pth msgport create() and utilized with pth msgport put()and pth msgport get(), which places and gets messages from the message queue.

Events are used as a means of synchronizing the program execution. Threadscan be instructed to wait or emit a specific event. Events can take many forms, theone used in this software is a message queue event.

A message queue event occurs whenever a message is put into a specified messagequeue. In this way one thread can control the execution of another thread, byinjecting messages into the queue at specified times.

56

Page 69: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX F. ADVANCED LINUX SOUND ARCHITECTURE

Appendix FAdvanced Linux SoundArchitecture

The purpose of this appendix is to describe the basics of Advanced Linux SoundArchitecture (ALSA), which is an open source project that provides a kernel driverfor most sound cards and an application programming interface (API).

An analog input signal must be sampled before it can be used in an computer.The sampling of the analog signal is done in the sound card, and this produces datawhich must be handled by the computer. If the data is not handled properly onesample may be overwritten by the next sample, thus losing data.

A continuous analog output signal requires a constant stream of data, if thesound card does not receive these data, the output will fail or at least pauses willbe added to the sound. The ALSA API provides options to control the data flow toand from the sound card as well as options to configure the sound card. This projectuses the following versions of the ALSA packages: alsa-base (1.0.10-1), libasound2(1.0.10-1), libasound2-dev (1.0.10-1). The appendix is based on [ALSA, 2005].

F.1 Data flow

During configuration of the sound card two ring buffers are created. These bufferseither hold data from the sound card (input) or hold data that are to be sent tothe sound card (output). During playback ALSA will tranfer data from the outputbuffer to the sound card, and during capture ALSA will tranfer data from thesound card to the input buffer. ALSA has implemented three different ways ofcontrolling the data flow between a user application and these buffers. The treedifferent transfer methods will be described next.

F.1.1 Standard I/O transfers

The standard I/O transfer method is based on the UNIX read() and write() func-tions. Attempts to read or write a specified amount of bytes from a file descriptor(often a buffer) into the input or output buffer. If successful the number of trans-fered bytes is returned. If zero is returned the file descriptor has reached End Of

57

Page 70: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

F.2. DATA STRUCTURE

File. If there is not enough space in the buffer to transfer all the specified data, thebuffer will be filled and the bytes actually transfered will be returned. There aretwo different modes in which the function can be used; blocked and non-blocked.In blocked mode the read() or write() function halts until there are enough dataor space in the input or output buffer buffer to complete the call with the speci-fied amount of byte transfers. Using non-blocking the functions wouldn’t halt, butreturn -EAGAIN error code.

F.1.2 Event waiting routines

The event waiting transfer method is based on the UNIX poll() and select() func-tions. The method waits for a event in the input or output buffer (change of status).When the input or output buffer buffer is ready for data transfer a standard I/Otransfer is used to transfer data to or from the buffer. The poll() and select() blockswhen it waits for a event.

F.1.3 Asynchronous notification

The asynchronous notification transfer method is based on the UNIX signal() func-tion. During capture or playback the input or output buffer is either being filledwith data or drained from data, once the input or output buffer have reached athreshold level the sound card will generate an interrupt. The interrupt is servicedwith a user programmable callback function, which insures data is moved to orfrom the data buffers.

F.2 Data structure

ALSA supports two ways of storing, writing and reading audio data in buffers;interleaved and noninterleaved. Picture F.1 illustrates the difference.

Channel 1

Higher byte

First sample

Third sampleFirst sample

Second sample Fourth sample

Channel 1

Channel 2 Lower byteHigher byteLower byteHigher byte

Lower byteLower byteHigher byte Higher byte

First frame Second frame

Non interleaved

InterleavedFirst frame

Second sample

Channel 2

Higher byte Lower byteLower byte

Figure F.1: Structure of the interleaved and non-interleaved buffer structure usedin ALSA. The uppermost part is of a non interleaved buffer structure,where the channels are kept separated. The lover most part is of ainterleaved buffer structure, where the channels are mixed together inone buffer.

58

Page 71: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX F. ADVANCED LINUX SOUND ARCHITECTURE

The figure illustrates a two channel signal sampled with a bit resolution of 16bits (2 bytes). The samples at a given sample time for all the channels are calleda frame. Using the non-interleaved approach each channel is stored in a separatebuffer. In the interleaved mode the samples are mixed together in a single buffer. Aperiod contain multiple samples. ALSA supports a wide range of different samplingformats.

F.3 Alsa API

To control the data flow, implement the transfer system, configure the sound cardsetc. the ALSA API calls are used. The API calls can be divided into groupsdepending on which interface they are designed to control.

• Control interface: Configuring the sound card e.g setting sampling rate, read-ing status from the sound card and querying available settings, devices, etc.

• Pulse code modulation interface (PCM): Controlling the flow of data duringplayback and/or recording.

• Raw Musical Instrument Digital Interface (MIDI): Controls the MIDI busdirectly on the sound card. The timing and protocols of the MIDI interfaceon the sound card have to be controlled manually.

• Sequencer: A higher level MIDI then the Raw MIDI, controling much of thetiming and protocols.

• Mixer interface: Selects the input and output sources on the sound card andthe volumes. A higher level interface to the Control interface.

• Timer: Provides access to timing hardware on the sound card.

Since the PCM interface and the control interface are the only interfaces used inthe project, the appendix will focus on these.

F.4 Control interface

The control interface is divided into two groups, one group control settings whichdeal with hardware and the other group deals with software settings. The twogroups are configured in the same way. A configuration space is allocated in mem-ory to hold any settings. After all the desired settings have been passed into theconfiguration space, the configuration space is applied to the hardware and/or thesoftware driver for the sound card. There are a few hardware settings that aremandatory such as sampling frequency and data format. All the settings are passedto the configuration space using API calls. Hardware settings are configured usingsnd pcm hw params set <Parameter>(). Table F.1 on the following page lists allthe hardware settings that are used in this project.

Software settings are configured using snd pcm sw params set <Parameter>().This project only uses start threshold(), which starts the playback or capture whena threshold level of data is reached in the buffer. Setting a high playback thresholdlevel ensure a high amount of data in the playback buffer, which help to aviod thebuffer running empty.

59

Page 72: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

F.5. PCM INTERFACE

<Parameter> valueaccess() SND PCM ACCESS RW INTERLEAVEDAccess type to be used when transferring and storing data from the sound card.format() SND PCM FORMAT S16 LEPulse code modulation format. Here 16 bit signed little endian.channels() 1Numbers of channels. Mono is used.rate near() 48000 HzSound card sampling frequency.periods() 4Numbers of periods in the buffer. Here 4 is used.buffer size() 4 · 4096The total size of the buffer. Each period is set to 4096 frames.

Table F.1: Hardware settings passed to the sound card.

F.5 PCM interface

As with the control interface the PCM interface can roughly be divided into twogroups, one group that manages the stream of data to or from the sound card andanother group used to obtain thr status on the stream. As mentioned earlier ALSAsupports three different ways of controlling the flow of data (stream) between theuser application and the sound card, which differ on the method used to detectwhen to transfer data. The actual transfer is done in the same way, using an APIcall specifying what and how much data to transfer. The API call snd pcm readi()is used to read data from the input buffer and snd pcm writei() is used to writedata to the output buffer. Other API calls to manage the stream are e.g. stop, startor pause which, as the name implies, stop, start or pause the playback or capture.This project uses the data transfer calls and the start call snd pcm start(). Thesecond group contain calls that e.g. return available frames for transfer, the positionof the head-pointer in the ring buffer or delay before a new sample will be played.This project uses the available frames call snd pcm avail update().

60

Page 73: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX G. IO SYSTEM

Appendix GIO system

To facilitate the demodulation algorithm, a software system for managing the soundcard input- and output is constructed. The purpose of this software is thus tocontinuously record audio from the sound card, provide it to the algorithm fordemodulation and finally continuously play it on the speakers of the PC. Thisrelationship is shown in figure 4.1 on page 10.

This appendix describes the design and implementation of this system, whichwill be referred to as the IO system. Before reading this appendix, it is recom-mended to read appendix F on page 57 about ALSA (Advanced Linux SoundArchitecture) and appendix E on page 53 about general threading and the usedlibrary, GNU Pth.

The used analysis and design method is mainly geared towards object orienteddesign, and uses UML (Unified Modelling Language) notation. The IO system willbe written in the procedural programming language C (basically not object ori-ented), but the design method still applies in a shortened form. See [Borch, 2005]for further information regarding the design method.

The following steps will be used in the design:

1. Analyze deployment (analysis of the environment in which the software willbe deployed)

2. Define user interactions (analysis of the way the system is used)

3. Find use-cases (formalization of uses found in the previous step)

4. Describe use-cases (analysis of internal mechanism in use-cases)

5. Find and describe functions (listing of functions/methods found in the previ-ous step)

6. Classify activities into stereotype objects (grouping of the discovered functionsinto domains)

Each step leads from one abstraction level to the one just below it. The result willbe a definition of used functions and a grouping of these. This is later used in theimplementation of the software.

61

Page 74: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

G.1. ANALYSIS AND DESIGN

G.1 Analysis and design

The main goal of the IO system is to take the input from the sound card (FM signal),provide it for processing by the demodulation algorithm and play the processed FMsignal in the speakers. The sound cards capture and playback and the algorithmare defined as actors, with the IO system as a transport channel between these.

G.1.1 Analysis of deployment

The first step in the design is to consider the deployment of the system. This isshown in figure G.1 where the target environment is a PC.

Capture Playback

Algorithm

ALSA ALSA

FIFO1 FIFO2

IOSYSTEM<<PC>>

Figure G.1: Deployment diagram for IO system.

G.1.2 Define user interactions

The three actors of figure G.1 are capture, playback and algorithm.The capture and playback actors model the capture and playback mechanisms

of the sound card. These have an amount of data that can be kept in buffers, andthe capability to signal when their buffer is almost full (capture) or almost empty(playback).

The algorithm actor is able to process the supplied data, but with respect tothe IO system, it is a transparent entity, behaving like a FIFO (First-in First-out)queue. This allows the algorithm to be developed in parallel with the IO system.

The actor interactions are sequentially described as getting input from the captureactor and passing the captured data on. The capture actor communicates with theIO system by means of the ALSA library. The IO system places the captured datain the FIFO1 queue which is passed to the algorithm, which processes the data andplaces the processed data into the FIFO2 queue. The IO system uses ALSA to passthe processed FM signal to the playback actor, which plays the processed data.

62

Page 75: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX G. IO SYSTEM

G.1.3 Find use-cases

The user interactions can be broken down into two use-cases, shown in figure G.2.Both are running at all times and are asynchronous.

The first, titled ”buffer filled”, happens when the capture actors buffer is almostfull. The capture actor signals the IO system which moves the recorded data fromthe capture buffer to the FIFO1 queue.

The second use-case, titled ”Data ready”, is initiated when the algorithm isfinished with processing data. The algorithm places the processed data in a FIFOqueue and processes more data. The playback actor signals whenever its playback-buffer is almost empty, thus animating the IO system to move data from the FIFO2queue and into the playback buffer.

Capture Algorithm

Algorithm Playback

Buffer filled

Data ready

Figure G.2: Use-cases for IO system. The buffer filled use-case s initiated whenthe capture sound card has data ready for recording. The data readyuse-case is applicable when the algorithm has demodulated data ready.

G.1.4 Describe use-cases

The in-depth description of each use-case happens with the use of activity diagrams,shown in figure G.3 on the next page and figure G.4 on page 65. A preliminarygrouping of functionality is shown by the bounding boxes.

The ”buffer filled” use-case shown in figure G.3 is initiated when a message fromthe capture actor is received. The captured data is then read and placed into theFIFO1 queue. The data will later be read from FIFO1 and passed to the algorithm.

The ”data ready” use-case takes processed data from the algorithm and placesit in the FIFO2 queue. Action is suspended until the playback actor signals that itneeds more data for playback, whereafter the processed data is read from FIFO2and placed in the playback buffer.

G.1.5 Find and describe functions

With the activities described in figure G.3 and G.4 a table of functions can bewritten. This is seen in table G.1 on page 65.

63

Page 76: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

G.1. ANALYSIS AND DESIGN

Wait for message

Capture buffer full

<<Message>>

Read data from soundcard

Put data to FIFO1

Get data from FIFO1

Fifo

Alsa

Processing by algorithm

Figure G.3: Activity diagram for buffer filled use-case. When the capture bufferis almost full, the capture actor (the sound card) emits a message tothe IO system. The IO system then moves the data from the soundcard to the demodulation algorithm.

To achieve better control of code execution and easier maintainable code, the pro-gram is split into 3 threads. Each thread roughly corresponds to servicing a specificactor. See appendix E on page 53 for further information regarding threads.

Input thread Handles the moving of captured data from the sound card bufferto FIFO1. This thread implements the use-case ”buffer filled”.

Processing thread Handles passing of data from FIFO1 to the algorithm andlater places the processed data in FIFO2. This thread partly implements theuse-case ”data ready”.

Output thread Handles the playback of data from FIFO2. This thread partlyimplements the use-case ”data ready”.

G.1.6 Classify activities into stereotype objects

With the previous analysis in place, a complete grouping of activities and functionscan be achieved. As an additional tool, options and stuctures holding parametersand program information are assigned to their own grouping. Each group is assignedto a header and a source file. The result is shown in table G.2 on page 66 with theassociated component diagram in figure G.5 on page 67.

64

Page 77: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX G. IO SYSTEM

Put data to FIFO2

Get data from FIFO2Wait for message

Playback buffer empty

<<Message>>

Write to buffer

FIFO

ALSA

Processed by algorithm

Figure G.4: Activity diagram for data ready use-case. The data ready use-case isinitiated when the playback buffer of the playback sound card is almostempty. The playback actor emits a message to the IO system, whichthen moves data from the demodulation algorithm to the playbackbuffer.

Name Activity GroupingfifoGetData() Gets data from a FIFO queue FIFOfifoPutData() Puts data to a FIFO queue FIFOalsaGetData() Gets data from capture buffer ALSAalsaPutData() Put data to playback buffer ALSAwaitForMsg() Waits for message specialalgorithm() Runs algorithm PROCESS

Table G.1: Summary of IO system functions. Functions discovered in the initialanalysis is placed into corresponding groups.

G.2 Implementation

The implementation description is based on figure G.6 on page 68. This section willdescribe the general implementation considerations and mention the used functions.For further insight into the code, see [group 506, 2005] which contains all the sourcecode and documentation in a web page.

G.2.1 Init functions

To initialise the ALSA hardware, a function alsaInit() is added to alsa.h/c. Thishandles hardware configuration by calls to the underlying ALSA library, and is runat the start of the input- and output threads.

All 3 threads are initialised from the main() function, found in main.c. Theirattributes (individual priorities, names etc.) are set here, and the threads arecreated. As soon as the processing thread is entered, the main thread is suspended.

65

Page 78: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

G.2. IMPLEMENTATION

Functions Group DescriptionfifoGetData(), fifoPutData() fifo.h/c Implementaton of FIFO queuealsagetData(), alsaPutData() alsa.h/c Usage of ALSAalgorithm() process.h/c Implementation of algorithm

prThread.h/c Processing threadouThread.h/c Output threadinThread.h/c Input threadthreadStruct.h/c Structures for options/data

Table G.2: Grouping of functions for the IO system. Each found function is placedinto a corresponding header and source file. Additional headers andsource files are specified for further use.

If the main thread is ever resumed, it will exit the program.

G.2.2 Thread activities

All 3 threads run concurrently, as shown in figure G.6. The activity waitForMsg()is not implemented as a single function, but rather as a cooperation between thecapture- and playback threads, and a callback function from the ALSA library. Asexplained in section G.1.2 the capture- and playback actors can signal whenevertheir buffers are nearing their limits. This signal consists of executing a callbackfunction, which is named inCalled() for the capture thread, and ouCalled() for theplayback thread.

The threads will stay suspended until the associated function is executed. Thefunctions ouCalled() and inCalled() sends a message to the associated thread,thereby activating the thread which then empties/fills the buffer and is resus-pended. The message is sent by the builtin message queue in the thread library,see section E.3.3 on page 56 for further information about message queues.

This mechanism is shown as the loop in figure G.6 between inCalled() and al-saGetData() for the input thread, and ouCalled() and alsaPutData() for the outputthread.

When both input and output threads are suspended (no immediate capture orplayback actions needed), the processing thread takes over, and processes availabledata from FIFO1 and places the data in FIFO2.

G.2.3 Argument passing

The parameters for hardware access and capture/playback are set in the struc-ture threadParams in the main() function, by means of the configThreadParams()from threadParams.h/c, and from manual manipulation of the structure. A thread-Params struct is passed by reference to each input and output thread, which thencan rely on options given in this structure.

A special structure prParams is passed to the processing thread, containingpointers to each threadParams-struct and a special thread pointer to the mainthread. This thread pointer is later used to suspend the main thread.

All code for these structs can be found in threadStruct.h/c.

66

Page 79: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX G. IO SYSTEM

Capture PlaybackAlgorithm

IO system

<<thread>>inThread.h/c

<<thread>>ouThread.h/c

<<thread>>prThread.h/c

<<implementation>>fifo.h/c

<<implementation>>alsa.h/c

<<implementation>>process

<<implementation>>threadStruct.h/c

Figure G.5: Component diagram for IO system. No internal dependencies showninside the IO system package.

G.2.4 FIFO queue

The used FIFO queues are implemented like standard first-in first-out queues, withthe additional use of mutex’es. See section E.3.2 on page 56 for further referenceabout mutexes. All the code for the FIFO-queue can be found in fifo.h/c.

The two FIFO queues are initialised in the main() function by fifoInit(), andpassed via the threadParams-struct to each thread.

The interface to the FIFO-queue is mainly fifoAddData() and fifoGetData(),supplemented by fifoGetCount() which returns the available data-chunks availablein the FIFO-queue and respects the mutex status of the queue.

If an application tries to get data from the FIFO queue, without any availabledata, the FIFO will unlock the associated mutex and yield processing time to an-other thread. The FIFO will suspend for a short time, and check again, until dataare available. The external application will thus ”halt” until data is placed in theFIFO-queue.

67

Page 80: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

G.2. IMPLEMENTATION

Processdata

main

start

Initiateprocessing

Setupinput

inC

alle

d

alsa

Get

Dat

a

inThread

Setupoutput

ouC

alle

d

alsa

PutD

ata

ouThread

main

exit

prThread

FIFO1 FIFO2

Figure G.6: Flowchart of the 3 threads of the IO system. Each thread is runconcurrently and indefinetely, with the main thread suspended (notrunning).

68

Page 81: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX H. SALLEN AND KEY FILTER

Appendix HSallen and Key filter

In this appendix a method for filter implementation using a Sallen and Key filteris described. This is done in order to use the implementation method of the Sallenand Key filter in appendix D.

First the low pass Sallen and Key filter realization is described and afterwardsthe high pass filter is described.

This appendix is written with reference to [Huelsman, 1993].

H.1 Low pass Sallen and Key filter realization

Figure H.1 shows a low pass Sallen and Key filter with 0 dB gain.

V2V1 C104R101 R103C102

Figure H.1: Low pass Sallen and Key filter.

The transfer function for the filter is

V2(s)V1(s)

=1

R1R3C2C4

s2 + s( 1R1C2

+ 1R3C2

) + 1R1R3C2C4

(H.1)

Comparing equation H.1 with the general form of the second order low pass filter

V2(s)V1(s)

=H0ω

2n

s2 + (ωnQ )s + ω2

n

(H.2)

69

Page 82: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

H.1. LOW PASS SALLEN AND KEY FILTER REALIZATION

where:ωn is the cut-off frequency [rad/s]Q is the quality factor [·]

the following set of equations can be found

ωn =1√

R1R3C2C4

(H.3)

1Q

=√

R3C4

R1C2+

√R1C4

R3C2(H.4)

H0 = 1 (H.5)

Because there are four unknowns and only three equations, some definitions needto be made in order to find a unique solution.

The parameters n and m are defined as

n =R3

R1

m =C4

C2

and

R = R1

C = C2

With these definitions equation H.1 can be rewritten as

V2(s)V1(s)

=1

mnR2C2

s2 + ( 1RC )(n+1

n )s + 1mnR2C2

(H.6)

Comparing Equation H.6 with H.2 gives the following two design formulas

ωn =1√

mnRC(H.7)

1Q

= (n + 1)√

m

n(H.8)

A practical approach to select a value of m compatible with standard capacitorvalues is choosing m so that

m ≤ 14Q2

(H.9)

Then n can be calculated from

n =( 1

2mQ2− 1

)± 1

2mQ2

√1− 4mQ2 (H.10)

70

Page 83: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX H. SALLEN AND KEY FILTER

H.2 High pass Sallen and Key filter realization

Figure H.2 shows a high pass Sallen and Key filter with 0 dB gain.

V2V1 R104R102

C101 C103Figure H.2: High pass Sallen and Key filter

The transfer function for the high pass Sallen and Key filter is

V2(s)V1(s)

=s2

s2 + s( 1R4C3

+ 1R4C1

) + 1R2R4C1C3

(H.11)

By comparing equation H.11 with the general form of the second order high passfilter

V2(s)V1(s)

=H0s

2

s2 + ωnQ s + ω2

n

(H.12)

the following equations can be obtained

ωn =1√

R2R4C1C3

(H.13)

1Q

=√

R4C3

R2C1+

√R2C1

R4C1+

√R2C3

R4C1−

√R4C3

R2C1(H.14)

H0 = 1 (H.15)

Similar to the low pass function, some definitions must be made in order to find aunique solution. Defining n and m to be

m =C3

C1

n =R4

R2

(H.16)

and

C = C1

R = R2

71

Page 84: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

H.2. HIGH PASS SALLEN AND KEY FILTER REALIZATION

With these definitions the transfer function H.11 can be rewritten as

V2(s)V1(s)

=s2

s2 + sRC

1n

m+1m + 1

mn(RC)2

(H.17)

Comparing the new transfer function H.17 with equation H.12 the following designformulas can be obtained

ωn =1√

mnRC(H.18)

1Q

=m + 1√

mn(H.19)

In order to simplify the design formulas m is set to 1 which means that C3 = C1

ωn =1√

nRC(H.20)

Q =√

n

2(H.21)

72

Page 85: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX I. AUTOMATIC GAIN CONTROL

Appendix IAutomatic Gain Control

The purpose of the Automatic Gain Control (AGC) is to maintain a constantvoltage level at the output even though the input voltage may vary. The circuitcan do this over a limited range eg. 30 dB. The circuit is some times referred to asa compressor due to its dynamic limiting nature.

I.1 Theory of operation

An integrated circuit known as a Voice Operated Gain Adjusting Device (VOGAD)is chosen for the AGC circuit, see figure I.1. The IC is the SL6270C which is ableto keep the output amplitude at a constant level of approximately 100 mV over a50 dB input range. The chip requires only a few external components, these willdetermine how fast AGC will respond to a change in input level. Internally thereare two amplifiers, an input amp and an output amp. The output amp feeds thesignal to a detection circuit which produces a DC voltage that controls the gain ofthe input stage.

To be able to adjust the input level of the AGC circuit an opamp is added tothe input of the VOGAD. The configuration is the inverting amplifier, becausethen the amp will be able to handle gains lower that 1.

I.2 Design

The external components for the VOGAD must be calculated before the circuitcan be implemented. The frequency range of the VOGAD is set by two externalcapacitors which are calculated by the following equations:

C205 =1

2 · π · 680 · f [F ] (I.1)

C206 =1

2 · π · 10 · 103 · f [F ] (I.2)

From appendix C.6 the upper and lower frequencys are 17 kHz and 1 kHz. Usingthis in the equations yields

73

Page 86: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

I.2. DESIGN

C205 =1

2 · π · 680 · 1 · 103[F ] (I.3)

= 234 · 10−9[F ] (I.4)

C206 =1

2 · π · 10 · 103 · 17 · 103[F ] (I.5)

= 936 · 10−12[F ] (I.6)

The capacitors are chosen to 470 nF and 470 pF. This is done so that the frequencyrange is passed with a minimum of phase distortion.Since there are no demands on the response time of the AGC circuit the applicationnote is followed with respect to the values of the response time dependent compo-nents.The circuit will be tested as a part of the final system.

Detector

R201

Vcc C206C205

R206

C207

C204

R204

C202

C201

R202

IC202

IC201

C203

R205R203

Figure I.1: Schematic of AGC

Component Value [Ω] Component Value [F] Component TypeR201 10k C201 100n IC201 TL082R202 10k C202 100n IC202 SL6270CR203 10k C203 4.7µR204 100k C204 47µR205 22k C205 470nR206 1M C206 470p

C207 100n

Table I.1: Components used in the AGC circuit

74

Page 87: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX J. MEASUREMENTS OF SIGNAL STRENGTH

Appendix JMeasurements of signal strength

The purpose of this measurement is to document what the input power of thedownconverter is with a transmitter placed at a distance of 5 meters. In the testthe Effective Radiated Power (ERP) of the transmitter should be 200 mW. [IT- ogTelestyrelsen, 2004, page 14].

J.1 Method

The test setup is shown i figure J.1.

Figure J.1: Test setup for signal strength measurement. The signal is transmittedfrom the transmitter (TX1) to the attenuator (ATT1), and then fromantenna 1 (ANT1) to antenna 2 (ANT2). The signal then crosses theboundary from the source block into the system. It is downconverted(DOWN1) and enters the oscrilloscope (IND1). The distance betweenthe antennas is 5 metres.

The test frequency is chosen to 145.525 MHz as this is a dedicate simplex fre-quency. A check for activity is made before use.

1. Adjust the TX1 to the chosen frequency.

75

Page 88: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

J.2. RESULTS

Symbol Type Model Manufacturer AAU-nrTX1 Transmitter IC-2100 Icom 33480ATT1 Attenuator 20 dB N/A N/A N/AANT1 Antenna X30 Diamond 01208-00DOWN1 Downconverter N/A N/A N/AIND1 Oscilloscope 2254A Tektronix 08388

Table J.1: Equipment used in test.

2. Set the output power of TX1 to 10 W using low power switch display shouldnow read LOW*. The output of 10W is attenuated 20 dB and the antennahas a gain of 3 dB this yields 200 mW ERP.

3. On IND1, adjust the timebase and volt input attenuator to obtain the bestaccuracy.

4. Read the voltage level of the output signal measured at IND1.

J.2 Results

The results of the test is that the output of the downconverter described in appendixC.6 will be in the order of 2 - 12 mVpp. The variation is due to the indoor testenvironment. Remembering from section C.6 on page 44 that the total voltage lossthrough the converter is approximately 6 dB the input voltage is 1.4 - 8.5 mV. Thisis equal to an average of -33 dBm.

J.3 Conclusion

The test shows that the input level is approximately -33 dBm which the level usedin the test of the converter.

76

Page 89: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX K. TEST OF ALGORITHM

Appendix KTest of demodulation algorithm

In order to compare the various demodulation algorithms, an evaluation methodis developed. The method is applied to the demodulation algorithms in order todecide on which one to implement in the final product. The demodulation algorithmwill be tested using the following methods:

SINAD: Evaluation of the SINAD ((Signal + Noise + Distotion)/ (Noise + Dis-tortion)) ratio of the output of the algorithm. The message signal will bebetween 300 Hz and 3 kHz in 100 logarithmic steps.

Robustness: Evaluation of the SINAD ratio of the output of the algorithm, wherethe modulated signal has some induced noise. The message signal will bebetween 300 Hz and 3 kHz in 100 logarithmic steps.

DFT analysis: DFT analysis of a 1 kHz demodulated signal.

Listening test.

Complexity: Complexity of the demodulation algorithm.

The SINAD ratio tests, the robustness of the algorithm and the DFT analysistest will be implemented as automated tests in a MATLABTM script file. Thescript files are included on the enclosed CD.

K.1 Principle

In the following the principle for each of the evaluation methods is described.

K.1.1 SINAD

SINAD is defined as

SINAD = 20 · log10

(VSND

VND

)(K.1)

where:VSND is the RMS value of the signal amplitude with noise and distortion. [V]VND is the RMS value of the noise and distortion. [V]

77

Page 90: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

K.1. PRINCIPLE

A set of test signals is created with MATLABTM with frequencies from 300 Hzto 3 kHz in 100 logarithmic steps. The 100 test signals are frequency modulatedusing the MATLABTM command fmmod(), with a frequency deviation of 5 kHz.The modulated test signals are then demodulated using the demodulation algo-rithm under test. The SINAD ratio is then calculated for each of the 100 testsignals and the ratio is plotted in MATLABTM. Figure K.1 illustrates how the testis implemented in MATLABTM.

Figure K.1: Implemention of the SINAD test in MATLABTM

The demodulated signal will contain some distortion from the modulation anddemodulation process. Figure K.2 illustrate a way to calculate the SINAD ratio.

Figure K.2: Signal to distortion block diagram.

The demodulated signal with distortion (SND) is bandpass filtered to removethe distortion, thus a signal without noise and distortion is obtained (S). The SNDand S signal are subtracted and the noise + distortion signal is obtained (ND).The RMS of the SND and ND are calculated. The SINAD ratio is then calculatedusing equation (K.1). Since the distortion introduced by the modulation algorithmin MATLABTM is the same for all the tests, it’s possible to compare the distortionintroduced by the demodulation algorithms.

The only nontrivial part in the calculation of the SINAD ratio is the filter. Thepassband must be small and the attenuation outside the passband must be high inorder to separate the signal from the distortion. Some distortion in frequencies nearthe signal frequency may be left in the filtered signal, which may cause a higherSINAD ratio. The effect of this will be minimized using a high order filter and asmall passband. If the bandpass filter doesn’t have unity gain in the passband thesignal will be calculated wrong. It’s also important that the filtered signal isn’tphase shifted, when substracting it from the unfiltered signal.

A simple way of automating the filter generation for different frequencies, isto use the MATLABTM command fir1(). The wanted filter order, the passband

78

Page 91: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX K. TEST OF ALGORITHM

frequencies and the filter window type is passed to the fir1(). The fir1() returnsthe filter coefficients of a FIR filter with unity gain at the passband and as muchattenuation as possible outside the passband.

The hamming window is chosen as a compromise between width of the mainlobe and the peak amplitude of the side lobes. The order of the filter is chosen tobe 1000. In priciple the order could be much higher, but since an N order filterneeds N samples to settle, increasing N would require more samples in the testsignal, thus the execution time of the test would increase. Figure K.3 shows thenormalized frequency response of the filter, designed to pass frequencies between975 Hz and 1025 Hz with a sampling frequency of 48 kHz. The filter is used in theSINAD evaluation of the 1 kHz test signal.

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1Normalized frequency [x pi rad/sample]

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1Normalized frequency [x pi rad/sample]

Figure K.3: Frequency responce of a 1000 order hamming window FIR filter.

The MATLABTM command filtfilt() first filters the signal in the forward di-rection and then reverses the signal and filters it again, thus avoiding any phaseshifting that normally would be caused by filtering in one direction. As the filterhas a settling time of 1000 samples, the first and last 1000 samples are left outwhen calculating the signal to distortion ratio.

K.1.2 SINAD ratio with induced noise

The robustness of the demodulation algorithms is tested by adding noise to themodulated signal and then calculating the SINAD ratio of the demodulated signal,as in the previous test. Figure K.4 on the following page illustrates how the test isimplemented in MATLABTM.

The noise is generated using the MATLABTM command randn(), which gen-erates random numbers with mean zero and variance of one. Using the randomgenerator a noise signal is generated with the same length as the test signal. Thenoise signal is filtered in a 4th order bufferworth filter made with the MATLABTM

79

Page 92: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

K.1. PRINCIPLE

Figure K.4: Implemention of the SINAD test, where noise has been added to themodulated signal before demodulating.

command butter(). The filter matches the input filter designed in appendix D onpage 47. The noise signal is scaled to be -26 dB (-26 dB ≈ 6%) maximum amplitudecompared to the maximum amplitude of the modulated signal. The level of addednoise is taken from [Christensen, 1999, p. 288].

K.1.3 DFT analysis

A discrete fourier transform on a 1 kHz modulated in MATLABTM and demodu-lated by the algorithm under test is used to visually inspect the frequency spectrumof the signal. Unwanted frequency components inside the pass band, 300 Hz to 3kHz, are especially critical because it’s impossible to attenuate them in a filter.Figure K.5 shows how the test is implemented in MATLABTM. A 1 kHz sinusoidalsignal is generated and modulated using MATLABTM. The modulated signal isthen demodulated in the tested FM-demodulating algorithm. Finally a DFT of thesignal is plotted.

Figure K.5: Implemention of the DFT analysis test.

The DFT can be calculated by

X[k] =N−1∑n=0

x[n]w[n]W knN (K.2)

where:x[n] is a discrete signal.g[n] is a window.N is the resolution of the DFT.WN is e−j·2·π/N .

The window g[n] is applied to x[n] to limit the length on x[n]. There are manydifferent types of windows, the rectangular window can be described as follows

g[n] =(

1, 0 ≥ n ≥ L

0, else

)(K.3)

where:L is the size of the window in samples.

80

Page 93: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX K. TEST OF ALGORITHM

The best frequency resolution is achieved by using a large window. The DFT willbe implemented using the fft() command in MATLABTM, this is a speed optimizedversion of the DFT. Passing the entire signal x[n] to the fft() function is the equiv-alent of using a rectangular window with the same size as the signal. [Oppenheim& Schafer, 1998, cha. 8]

K.1.4 Complexity

The complexity of the demodulation algorithm is evaluated using the followingpoint-system:

• Every comparison and command that is executed on every sample, is worth1 point.

• Everything else (initialization, etc.) is worth 0 points.

The points are added, and the best algorithm will be the one with the lowestnumber. This test is applied to the matlab() implemention of the code. The codeis included on the enclosed CD.

K.1.5 Listening test

The final test is a listening test, which will be a subjective evaluation of the audiblesound quality of the algorithm. A 30 second long speech sound clip is taken from[B&O, 1992, track 4, 5] and bandpassed filtered with cut-off frequencies of 300 Hzand 3000 Hz. The two sound clips are of a male and female reading a text. Thesound clips are included on the enclosed cd. Each test person will listen to allthe demodulations and the original sound clip on the same audiosystem (computer,software player, sound card and headphones). Thereafter the sound clips are sortedafter what sounds best. The test persons are not allowed to know which algorithmis used. The worst sounding sound clip will receive a score of 0, the second worsta score of 1 and so on. The best algorithm will be the one with the highest totalscore. The test persons are the six members of the group.

K.2 Verification of test algorithms

The SINAD evaluation algorithm is tested by utilizing it on:

1. A sine wave with a frequency of 1000 Hz where the expected frequency is1000 Hz. The result should be a high SINAD ratio.

2. A pure sine wave with a frequency of 2000 Hz where the expected frequency is1000 Hz. The result should be about zero, as the SND signal is aproximatelythe same as the ND signal, with the exception of windowing effects.

3. Two pure sine waves with frequencies of 1000 and 2000 Hz and the sameamplitude where the expected frequency is 1000 Hz. The result should beabout 6 dB, as the SND is twice as big as the ND signal.

81

Page 94: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

K.3. RESULTS

The DFT analysis will be tested by utilizing it on a sine wave with a frequency of1000 Hz and viewing the result. The listening test and the complexity evaluationare not tested due to the nature of the evaluation.

K.2.0.1 Results of the verification

The result from the SINAD ratio test can be seen in table K.2.0.1

Test 1 635.5 dBTest 2 3.8 · 10−10 dBTest 3 6.9 dB

The result from the FFT analysis can be seen in figure K.6.

100

101

102

103

104

f [Hz]

Frequency spectrum

Figure K.6: FFT analysis of 1 kHz sine tone, used to verify the implemention ofthe FFT test in MATLABTM

K.2.0.2 Discussion

The result from the SINAD ratio is the same as the expected. The DFT is asexpected, a large frequency component at 1 kHz and some windowing effects.

K.3 Results

The described test methods are applied to the MATLABTM implemented demod-ulation algorithms.

K.3.1 SINAD

The SINAD ratio is calculated for all the demodulation algorithms and the demodu-lation algorithm implemented in MATLABTM, for comparison purposes. Figure K.7

82

Page 95: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX K. TEST OF ALGORITHM

shows the result of the calculations. Over the tested frequency range the algorithms

103

f [Hz]

MatlabZC 1ZC 2SlopeQuad DelayQuad ArctanQuad Diff

Figure K.7: Comparison of SINAD ratio. Quad delay and Quad diff are coincid-ing. ZC 1 is the basic zero crossing detection algorithm, and ZC 2 isthe improved zero crossing detection algorithm.

perform differently. The demodulation done by MATLABTM is the best below 1.5kHz, above 1.5 kHz the QuadDelay algorithm matches MATLABTM. The QuadDe-lay, QuadAtan and QuadDiff generate some 3rd order harmonic frequencies, whichare attenuated for frequencies above 1 kHz in the bandpass filter. The attenuationof the 3rd order harmonic frequencies clearly shows as an improved S/N ratio above1 kHz. The low frequency roll-off is due to a high-pass filter with a cut-off frequencyof 300 Hz.

K.3.2 SINAD ratio with induced noise

The SINAD ratio is calculated, this time with added noise to the modulated sig-nal. The resulting SINAD ratio can be seen on figure K.8 on the next page. TheQuad Arctan algorithm is more robust than the other algorithms, as it SINADratio only decreases a little with the added noise. The demodulation done byMATLABTM is the best below 1.5 kHz, above 1.5 kHz the QuadDelay algorithmmatches MATLABTM.

83

Page 96: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

K.3. RESULTS

103

f [Hz]

MatlabZC 1ZC 2SlopeQuad DelayQuad ArctanQuad Diff

Figure K.8: SINAD ratio with noise added to the modulated signal. Quad delayand Quad diff are coinciding. ZC 1 is the basic zero crossing de-tection algorithm, and ZC 2 is the improved zero crossing detectionalgorithm.

K.3.3 DFT analysis

The result of the DFT analysis can be seen on figure K.9 on the facing page. Theplot is scaled to a maximum amplitude of one, but only values from (0 − 0.2) areplotted. The 3rd order harmonic frequencies of the QuadDelay and QuadDiff canbe seen, but the 3rd of the QuadAtan is invisible on the graph. Some 2nd and3rd order harmonic frequencies are visible on the ZeroCross and Slope detectionalgorithms.

84

Page 97: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX K. TEST OF ALGORITHM

103

104

Basic zero crossing detection

102

103

104

0

0.1

0.2Improved zero crossing detection

103

104

Single slope detection

102

103

104

0

0.1

0.2Quadrature baseband delay

103

104

Quadrature arctan

102

103

104

0

0.1

0.2Quadrature differentiation

Figure K.9: DFT plot of a 1 kHz demodulated test signal, normalized

K.3.4 Listening test

The result of the listening test can be seen in table K.1. The listening test wasperformed by 6 members of the group. The Quad Delay demodulation algorithm

Algorithm Male FemaleQuad Atan 29 30Quad Delay 34 28Quad Diff 26 23Sound clip 20 27ZC 2 13 12Slope 6 6ZC 0 0

Table K.1: Result of the listening test.

scored highest for the male sound clip and the Quad Atan algorithm scored highestfor the female sound clip. The original sound clip ranked 4th for the male soundclip and 3rd for the female sound clip.

K.3.5 Complexity

The result of the complexity tests can be seen in table K.2 on the following page.The slope detection and the zero-cross algorithm are the least complex to implementand use no functions with unknown complexity such as cos, tan etc. The improvedzero-crossing is more complex to implement. The most complex to implement are

85

Page 98: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

K.4. CONCLUSION

Algorithm ComplexitySlope 2ZC 5ZC 2 14Quad Atan* 27Quad Delay 28Quad Diff 29

Table K.2: Result of the complexity test. (*) Uses functions with unknown com-plexity.

the Quad demodulations algorithms. The Quad Atan uses an atan function andthe MATLABTM unwrap() both set to a complexity of 1.

K.4 Conclusion

The Quad Atan demodulation algorithm have the best SINAD ratio over the entirefrequency range both with and without induced noise to the modulated signal(excluding MATLABTM demodulation algorithm). The Quad Atan has a muchbetter SINAD ratio when noise is induced than the Quad Delay algorithm. TheQuad Atan and Quad Delay scored best in the listening test. The Quad Atan hasbeen chosen over the Quad Delay, because it offers a much better SINAD whennoise is induced. The disadvantage of using the Quad Atan is that it’s one of themost complex to implement.

86

Page 99: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX L. ZERO CROSS DETECTION

Appendix LZero cross Detection

The baseband signal information is contained in the frequency of the FM mod-ulated signal, so any amplitude information can be removed without loosing anyinformation about the baseband signal.

L.1 Principle

The zero cross detection demodulation algorithm [Carlson, 1986, p. 262-263] utilizesthe fact that is described in equation (L.1).

f =1λ

(L.1)

wheref is the frequency. [Hz]λ is the wavelength. [s]

As zero cross detection only uses the points of the modulated signal where it crosseszero, it is insensitive to clipping and carrier frequency deviation, as long as the car-rier frequency is constant.

L.2 Basic zero cross detection

From L.1 it is clear that the frequency of the FM modulated signal can be found bymeans of the wavelength. The wavelength of the signal can be determined from thezero-crossing of the FM signal. A block diagram of ZC can be seen in figure L.1.The principle of the ZC is to generate a pulse whenever a zero-crossing occurs. Thegenerated pulses are then passed though a low pass filter and finally the signal isDC-blocked.

L.2.1 Mathematic description

The pulse generator produces a pulse with fixed amplitude A and a fixed durationτ each time a positive (or negative) going zero-crossing occurs. In most systems,the carrier frequency is much higher than the frequency of the message signal,

87

Page 100: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

L.2. BASIC ZERO CROSS DETECTION

Figure L.1: Block diagram Zero-crossing Detection Demodulation Algorithm.

thus negating the need for detecting both zero-crossings. The output of the pulsegenerator is a pulse train v(t). If the pulse train is viewed over a short period Tseconds, where 1/T << fc, the numbers of pulses in T can be calculated by

Pulses within T = T [fc + ∆f ·m(t)] (L.2)

where:∆f is the maxmium frequency deviation. [Hz]m(t) is the base band signal, with a maximum amplitude of 1.

Continuously integrating v(t) over W << 1/T second, where W is the maximumfrequency of the baseband signal, yields

1T

∫ t

t−T

v(t)dτ = A[fc + ∆fm(n)]τ (L.3)

= Afcτ + A∆fm(t)τ (L.4)

Adding a DC-block yields

y(t) = A∆fm(t)τ (L.5)

Figure L.2 on the facing page illustrates the zero-cross demodulation process.

L.2.2 Digitization considerations

A method of detecting zero-crossing in discrete signals, is to compare the sign ofthe sample with the sign of the previous sample. The problem with detecting thezero-crossing in a sampled signal is the limited time resolution of the signal.

The value of τ in samples must be chosen so that the pulses doesn’t overlapon the highest frequencies of the modulated signal. The maximum value can becalculated by fs/(fc∆F ), which results in a maximum τ integer of 2 samples. Theintegration and DC-block is replaced by a bandpass filter, which has the effect ofintegration, but also removes any low-frequency noise.

L.2.3 MATLABTM implementation

The implementation of the algorithms is quite simple, due to the fact that the mainfunction of the algorithm is to detect whether zero has been crossed or not.

L.2.4 C implementation considerations

The MATLABTM implementation is quite close to the way it will be implementedin C, as the only functions that are being used are:

88

Page 101: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX L. ZERO CROSS DETECTION

0.02 0.0205 0.021 0.0215 0.022

Base band signal

0.02 0.0205 0.021 0.0215 0.022

Modulated signal

0.02 0.0205 0.021 0.0215 0.022

Zero−cross detection

0.02 0.0205 0.021 0.0215 0.022

Pulse generator

0.02 0.0205 0.021 0.0215 0.022time [s]

Demodulated signal

Figure L.2: The zero-cross demodulation process.

• for

• a bandpass filter

L.3 Improved zero crossing detection

Another possible way of using zero-cross detection to demodulate a signal is toestimate the instantaneous frequency deviation by dividing the sample frequencywith the wavelength, thus utilizing equation (L.1) to a higher extent than the basiczero cross detection.

L.3.1 Mathematical description

The frequency estimation is based on (L.1), which can be rewritten as equa-tion (L.6).

f∆ ≈ fs

tn − tp− fc (L.6)

where:f∆ is the instantaneous frequency deviation. [Hz]tp is the time of the previous zero-crossing. [samples]tn is the time of the next zero-crossing. [samples]fs is the sampling frequency. [Hz]fc is the carrier frequency. [Hz]

The current frequency deviation is a direct representation of the amplitude of m(t).

89

Page 102: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

L.3. IMPROVED ZERO CROSSING DETECTION

The states at different points of the demodulation algorithms can be seen in fig-ure L.3.

The output of this algorithm can be seen in figure L.3. The message signal is first

0.02 0.0205 0.021 0.0215 0.022

Message signal

0.02 0.0205 0.021 0.0215 0.022

FM−modulated message signal

0.02 0.0205 0.021 0.0215 0.022

Unfiltered MZCDDA demodulated message signal

0.02 0.0205 0.021 0.0215 0.022

Filtered MZCDDA demodulated message signal

time [s]

Figure L.3: Output at different points of the Modified Zero-Cross Detection De-modulation Algorithm.

FM-modulated, then the instantaneous frequency deviation is calculated for eachsample using equation (L.6). The sample value is set to f∆. This way the samplevalues between two upwards zero crossings equals the instantaneous frequency de-viation. The resulting signal is a approxmation of the message signal. DC-blockingthe output will nullify the influence from an unprecice carrier frequency.

L.3.1.1 Improvement of the algorithm

This algorithm can be improvemed by at least two methods:

1. Detecting the zero-crossing at both transitions will increase the resolution inthe time-domain as the measurement points are doubled.

2. By estimating the zero-crossing point, the value of f∆ will be more accurate.

Utilizing method 1 changes equation (L.6) to equation (L.7):

f∆ ≈ fs

2(tn − tp)− fc (L.7)

This is due to the fact that detecting at both transitions results in the calculationof λ/2 of equation (L.1). A method of estimating the zero-crossing point is tocalculate the intersection of a line between the two sample points and zero. Thismethod is illustrated in figure L.4 on the next page, and yields equation (L.8).

∆t =x[n]

x[n]− x[n− 1](L.8)

90

Page 103: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX L. ZERO CROSS DETECTION

x[n− 1]

1/fs

x[n]− x[n− 1]

x[n]

0

∆t

Figure L.4: Closeup of zero-crossing, used to increase the accuracy of f∆.

A plot of the demodulated signal estimating the zero-crossing points can be seenin figure L.5.

0.02 0.0205 0.021 0.0215 0.022

Message signal

0.02 0.0205 0.021 0.0215 0.022

FM−modulated message signal

0.02 0.0205 0.021 0.0215 0.022

Unfiltered MZCDDA demodulated message signal

0.02 0.0205 0.021 0.0215 0.022

Filtered MZCDDA demodulated message signal

time [s]

Figure L.5: Output at different points of the demodulation process using the zero-crossing estimation.

L.3.2 Digitization considerations

A method of detecting zero-crossing in discrete signals, is to compare the sign ofthe sample with the previous sample. As this algorithm estimates where the signalcrosses, the problems with fs should be less severe than with the basic zero crossdetection. Due to the fact that the math for this algorithm is discrete math, digitalimplementation should be trivial.

91

Page 104: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

L.4. CONCLUSION

L.3.3 MATLABTM implementation

The implementation of the algorithms is quite simple, due to the fact that the mainfunction of the algorithm is to detect whether zero has been crossed or not.

L.3.4 C implementation considerations

The MATLABTM implementation is quite close to the way it will be implementedin C, as the only functions that are being used are:

• for

• division

• multiplication

• a bandpass filter

L.4 Conclusion

The zero cross detection and the improved zero cross detection demodulate thesignal, and are trivial to implement in both MATLABTM and C.

92

Page 105: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX M. FIR BANDPASS FILTER

Appendix MFIR bandpass filter

The purpose of this appendix is to make an algorithm that implements a M -orderFIR bandpass filter. The algorithm will be tested in MATLABTM and later imple-mented in C.

M.1 Principle

The FIR filter is designed using windowing. This method is further described in[Oppenheim & Schafer, 1998, page 465 - 477].

The method is to make an ideal filter in the frequency domain, and then trans-late it into the discrete time domain. However this will give an infinite impulseresponse. To compensate for this, a window function is multiplied onto the idealimpulse response.

In this appendix a rectangular window is chosen. This is done for simplicity asthe window amplitude is either 1 or 0. In FIR filter design the order for the filteris denoted M and it determines the length of the window. The type of FIR filterused here utilizes linear phase i.e. constant group delay.

An example of a FIR bandpass filter is shown in figure M.1. The filter has acenter frequency (fc) of 5 kHz and a bandwith of 2 kHz. The order (M) is 20.

M.2 Mathematical description

Type I FIR filter design by windowing utilizes the ideal form of figure M.2 on thenext page. Examining the ideal filter in the frequency domain, the definition ofH(ejω) could be written as a modified equation (7.42) from [Oppenheim & Schafer,1998, p.466]

H(ejω) =

ejω

for − ωc − ωb < ω < −ωc + ωb

forωc − ωb < ω < ωc + ωb

0 Otherwise(M.1)

93

Page 106: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

M.2. MATHEMATICAL DESCRIPTION

102

103

104

−70

−60

−50

−40

−30

−20

−10

0

Frequency [Hz]

Am

plitu

de [d

B]

fc

Figure M.1: 20 order FIR bandpass filter.

|H(ejω)|

BW BW

−ωc −

ωb

−ωc

−ωc +

ωb

ωc −

ωb

ωc

ωc +

ωb

ω

Figure M.2: Ideal bandpass filter.

Corresponding to the discrete-time notation of

h[n] = hd[n] · w[n] (M.2)

with hd[n] as the approximated impulse response of the filter, and with w[n] as thewindowing function

w[n] =

1, for 0 ≤ n ≤ M0, otherwise (M.3)

The product of (M.2) is in the frequency domain equal to the convolution

H(ejω) =12π

∫ π

−π

Hd(ejω) ·W (ejω−φ)dφ (M.4)

Utilizing equation (7.52) with hd[M−n] = hd[n] and (5.146b) from [Oppenheim& Schafer, 1998, p. 472 and p. 297 respectively] with the amplitude function set

94

Page 107: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX M. FIR BANDPASS FILTER

to 1, Hd(ejω can be written as

Hd(ejω) =

e−jω M2

for − ωc − ωb < ω < −ωc + ωbfor ωc − ωb < ω < ωc + ωb

0 Otherwise(M.5)

Transforming Hd(ejω) to the time domain yields (by use of Euler rewriting)

hd[n] =12π

∫ π

−π

Hd(ejω)ejωndω (M.6)

=12π

∫ −ωc+ωb

−ωc−ωb

e−jω M2 ejωndω +

12π

∫ ωc+ωb

ωc−ωb

e−jω M2 ejωndω (M.7)

=1

π(n− M2 )

·[sin

((ωc + ωb)(n− M

2))

. . .

. . . − sin(

(ωc − ωb)(n− M

2))]

(M.8)

Multiplying hd[n] with the window w[n] in the time domain, to achieve thedefinition of h[n], and transforming to the Z-domain yields

H(z) =∞∑

n=−∞hd[n] · w[n] · z−n (M.9)

=M∑

n=0

hd[n] · z−n (M.10)

due to the magnitude of w[n] being 1 in 0 ≤ n ≤ M and zero otherwise. This is anapproximation of the ideal bandpass filter of equation (M.1) and figure M.2 on thefacing page.

Using the basic attribute of Y (z) = H(z) ·X(z) and transforming back to thetime domain, will yield the filter output

y[i] =M∑

n=0

hd[n] · x[i− n] (M.11)

The above can be readily implemented in an algorithm, with the value of M describ-ing the order of the filter. The values of hd[n] are reusable for each n, calculatedfrom the expression in (M.8).

M.3 Digitization considerations

The designed FIR filter is specifically intended for digital implementation, andthereby doesn’t have any particular implementation considerations, except thataccording to [Oppenheim & Schafer, 1998, page 386] at least 14 bits must by usedfor the filter coefficients.

M.4 MATLABTM implementation

The MATLABTM implementation relies on the following information to be supplied:

95

Page 108: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

M.5. C IMPLEMENTATION CONSIDERATIONS

• the sample rate (fs), in Hz.

• the center frequency of the passband (fc), in Hz.

• the passband width (BW ), in Hz.

• the order of the filter (M), must be an even number.

• the data to be processed (data).

The filter algorithm does the following:

• Done once:

– Assign memory for M + 1 coefficients (hd[n]).

– Loop from 0 to M , decide filter coefficients. One exception is n = M2 ,

where L’Hospitals’ rule must be used.

– Determine factor for gain adjustment.

• Done for each data chunk:

– Assign memory for output

– Handle first M samples

– Loop for each sample(i):

∗ Loop for n = 0 to M , summing coefficients hd[n] · x[i− n].∗ Adjust gain∗ Move to output

Note that the first M samples are using samples before t = 0 as zeros. Testedagainst MATLABTM’s internal commands (FIR1), the designed filter produces thesame coefficients as MATLABTM.

M.5 C implementation considerations

The C-implementation on the selected PC platform imposes the consideration ofdatatypes and data length.

The system datatype used for handling soundcard samples is set to integers,while the internal workings of the filter relies on float values. The solution is to usefloat values internally, and export values rounded to integers.

As C contains no built in “length” command, the length of the supplied samplesmust be specified. Furthermore, the data to be processed is supplied in chunks. Thisresults in problems as the filter uses M samples from the past. When crossing theboundary between chunks this must be addressed.

M.6 Conclusion

In this appendix an M order FIR bandpass filter has been implemented. Theorder of the filter can be varied according to the demands of a given situation.However the zeroing of the samples before t = 0 must be handled for the actualC-implementation.

96

Page 109: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

Appendix NQuadrature detection

Quadrature detection is a demodulation technique which builds on the utilizationof a quadrature signal. This appendix will introduce quadrature signals in sectionN.1 and N.2 and proceeds with the different ways these can be used to obtain FMdemodulation, see sections N.3, N.4 and N.5.

N.1 Theory

The first of the following sections will introduce the mathematics behind quadraturesignals. The second will describe how a continous wave modulated signal can berepresented by quadrature signals. The reference for this section is [Haykin, 2001,pages 723-730].

N.1.1 Quadrature representation of bandpass signals

This section will introduce three new terms; the pre-envelope of a signal, the com-plex envelope of a signal and finally the I and Q components of a signal. By thisit is shown how to represent a signal at baseband using complex quantities andavoiding information loss normally occuring with direct downconversion.

N.1.1.1 Pre-envelope

In a communication system the signal that is physically transmitted is a real-valuedbandpass signal, g(t) as shown in figure N.1(a). In handling bandpass signals thepre-envelope of g(t) has shown to be particularly useful, but one should rememberthat the pre-envelope is purely a theoretical function. The pre-envelope of suchsignal is defined as

g+(t) = g(t) + jg(t) (N.1)

where:g+(t) is the pre-envelope of g(t)g(t) is a real-valued signalg(t) is the Hilbert transform of g(t)

97

Page 110: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.1. THEORY

The Hilbert transform shifts the phase of all negative frequencies in a signal by+90o and of all positive frequencies by −90o. The signals g(t) and g(t) are said tobe a Hilbert transform pair. Amplitudes are not affected by the Hilbert transform.To sum up; the pre-envelope of a signal is nothing but the signal itself as the realpart and its Hilbert transform as the imaginary part. The Fourier transform G(f)of g(t) is given by

G(f) = −j · sgn(f)G(f) (N.2)

where sgn(f) is the sign of f . Knowing this, the Fourier transform of the pre-envelope of g(t), G+(f) can be derived:

G+(f) = G(f) + jG(f) (N.3)G+(f) = G(f) + sgn(f)G(f) (N.4)

From this it is found that the pre-envelope has no frequency content for all negativefrequencies, and that the magnitude of the positive frequency content is doubled asshown by figure N.1(b). This proporty will show its importance later.

N.1.1.2 Complex envelope

Now consider a bandpass signal, g(t), centered about the frequency ±fc and limitedto the band fc −W ≤ f ≤ fc + W . This signal contains a baseband signal, andnormally downconverting this to baseband directly would cause sideband overlap,hence information would be lost. The quadrature representaion is complex andavoids this.

The pre-envelope of such signal only contains information in the positive frequen-cies. The pre-envelope of such signal can always be expressed as a baseband signalwith a frequency displacement of fc. The base band signal is called the complexenvelope, g(t).

g+(t) = g(t)︸︷︷︸baseband

exp(j2πfct)︸ ︷︷ ︸freq.shift

(N.5)

where:g+(t) is the pre-envelope of g(t)g(t) is the complex envelope of g(t)

The complex frequency shift is obtained by multiplication of the complex signalexp(j2πfct) conforming with the Fourier transform property:

exp(j2πfc)g(t) G(f − fc) (N.6)

Note about the above formulas that the only difference between the complex en-velope, g(t), and the pre-envelope, g+(t), is that the complex envelope is shiftetto base band while the pre-envelope is still on a carrier. None of the signals havemirrors in the frequency plane. In contrary to direct downconversion, where sideband ovelap usually occurs, the quadrature representaion, which can be considereda form of complex downconversion, does not have this problem; i.e the signals canbe represented by the complex envelope at baseband without loosing information.This is possible because the complex envelope is a complex-valued function, whichwill be addressed further in the next section.

98

Page 111: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

|G(f)|

ffc−fc

2W

(a)

0

|G+(f)|

ffc

(b)

2W

0

|G(f)|

f

(c)

0 W

|G(fc)|

2|G(fc)|

2|G(fc)|

−W

Figure N.1: Illustrating spectrums of a) a received bandpass signal, (b), the pre-envelope of the bandpass signal and (c) the complex envelope of thebandpass signal.

N.1.1.3 I and Q signals

While the pre-envelope g+(t) is bandlimitted to the band fc −W ≤ f ≤ fc + W ,the complex envelope g(t) is limitted to the band −W ≤ 0 ≤ W , and is thereforea lowpass signal. This is illustrated by figure N.1(c). In general, g(t) is a complex-valued lowpass quantity that may be described on rectangular form:

g(t) = I(t) + jQ(t) (N.7)

where:I(t) is the in-phase component of g(t)Q(t) is the quadrature component of g(t)

The lowpass property of I(t) and Q(t) is inherited from g(t). The original bandpasssignal, g(t), can be represented also by means of I(t) and Q(t):

g(t) = Re[g(t) exp(j2πfct)] (N.8)= Re[(I(t) + jQ(t)) · (cos(j2πfct) + j sin(j2πfct))] (N.9)= I(t) cos(j2πfct)−Q(t) sin(j2πfct) (N.10)

To sum up; all information content of g(t) is preserved within the I- and Q-signalssince these are the real and imaginary components of the complex envelope ofg(t). This is a base band representation that avoids sideband overlap, that wouldnormally occur with direct downconversion.

99

Page 112: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.1. THEORY

N.1.2 Quadrature representation of continous-wave modu-lated signals

Until now the bandbass signal g(t) has been treated as arbitrary. This section willfocus on the quadrature representation of signals that are modulated using AM,PM or FM. In these cases the bandpass signal can be expressed generally as

g(t) = a(t) cos(2πfct + φ(t)) (N.11)

where:g(t) is a continuous wave modulated signala(t) is the envelope of g(t)φ(t) is the phase of g(t) [rad]

The I and Q components are derived following the steps presented in the lastsection:

g+(t) = a(t)[cos(2πfct + φ(t)) + j sin(2πfct + φ(t))] (N.12)= a(t) exp(j(2πfct + φ(t))) (N.13)= a(t) exp(jφ(t))︸ ︷︷ ︸

baseband

exp(j2πfct)︸ ︷︷ ︸freq.shift

(N.14)

g(t) = a(t) exp(jφ(t)) (N.15)= a(t) cos(φ(t)) + ja(t) sin(φ(t))) (N.16)

From the above and equation (N.7) it follows that

I(t) = a(t)cos(φ(t)) (N.17)Q(t) = a(t)sin(φ(t)) (N.18)

Note that all the information content is preserved in the complex envelope no matterif it is in terms of I and Q or in envelope and phase. The conversion between thetwo forms can of course be done both ways. Note that in complex envelope, a(t) isnot only the envelope, but the actual amplitude. It can therefore be calculated asthe absolute length of I(t) + jQ(t). The phase of the signal is simply the angle ofthe same complex number:

a(t) =√

I(t)2 + Q(t)2 (N.19)

φ(t) = tan−1

(Q(t)I(t)

)(N.20)

To sum up; The I- and Q-signals are both lowpass signals, and they both containboth ampltitude and phase information. Usually the signals are used to determinethe amplitude and phase of some received signal, i.e. g(t), and in this contextboth I and Q are required to uniquely determine the phase. Determination ofthe instantanous phase of a received signal is the key in quadrature FM detection,which will be described in the following sections.

100

Page 113: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

N.2 IQ generator

In this section the principle for obtaining the I- and Q-signals are described. Re-calling from section N.1 that the I- and Q-signals for an FM signal where a(t) isconstant are defined as

I(t) = A cos(φ(t)) (N.21)Q(t) = A sin(φ(t)) (N.22)

These are the signals that are to be derived from the FM signal.In figure N.2 the principle for making the I- and Q-signals is shown. As seen

Q-signal

I-signalLow Pass

Low pass2sin(! t)2 os(! t)

FM-signal g(t) hI(t)hQ(t)

Figure N.2: A block diagram for extracting the I- and Q-signals

in the figure, the I- and Q-signals are made by multiplying the FM-signal with2cos(ωct) or -2sin(ωct), and afterwards low pass filtering the signal. How this givesthe I- and Q-signals is shown by the following mathematical description.

N.2.1 Mathematical description of the I- and Q-signals

Because the calculations of the I- and Q-signals are almost identical, only a math-ematical description of the I-signal is made. The Q-signal can be calculated byusing the same procedure.

If the FM-signal is given as g(t) then the signal after the mixer is given by

hI(t) = g(t) · 2 cos(ωct) (N.23)

From appendix B.2, it is known that an FM signal can be described as

g(t) = A cos(ωct + φ(t)) (N.24)

Substituting the expression for g(t) into equation N.23 the signal after the mixercan be described as (using Eulers formel)

101

Page 114: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.2. IQ GENERATOR

hI(t) = A cos(ωct + φ(t)) · 2 cos(ωct) (N.25)hI(t) = A cos(φ(t)) + A cos(2ωct + φ(t)) (N.26)

The desired I-signal is the part of the g(t) signal centered around zero. In orderto obtain this signal, the g(t) signal is low pass filtered, which gives the I-signal

I(t) = A cos(φ(t)) (N.27)

This shows that the I- and Q-signal can be derived from the FM signal by usingthe above described method in an ideal situation. Often this will not be the casebecause the carrier frequency will have a frequency offset ωo, and a phase offset φo,with respect to the internal oscillator. This gives the following FM-signal

g(t) = A cos(ωct + ωot + φ(t) + φo) (N.28)

It can be shown that a variation in the carrier frequency gives the following I- andQ-signals

I(t) = A cos(ωot + φ(t)) (N.29)Q(t) = A sin(ωot + φ(t)) (N.30)

This means that a change in the carrier frequency results in a frequency offset ofboth the I- and Q-signals.

Similarly it can be shown that a change in the phase of the signal multipliedwith the FM signal results in the following I- and Q-signals.

I(t) = A cos(φ(t) + φo) (N.31)Q(t) = A sin(φ(t) + φo) (N.32)

This shows that a change in the phase gives a phase offset in both the I- andQ-signals.

How these results influence the demodulation will be described for each of thefollowing demodulation algorithms.

Now that the method for finding the I- and Q-signals is described, an algorithmthat calculates the I- and Q-signals can be made.

N.2.2 Digitalization considerations

Most af the calculations shown above can directly be implemented as a discretetime function. Some considerations must however be made when designing the lowpass filter. This is because different methods can be used in designing a digitalfilter. For further information on filter design see appendix M.

102

Page 115: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

N.2.3 MATLABTM implementation

The MATLABTM implementation is made by following the method described aboveand shown in figure N.2. This means that the carrier frequency of the FM signalneeds to be known, for the algorithm to work.

A digital oscillator needs to be made in order to generate the sine and cosinesignal. In MATLABTM this can easily be made by first constructing a time vector,and then using this to generate the sine and cosine signals.

Evaluation of MATLABTM implementation

The MATLABTM implementation is evaluated using a 9 kHz cosine signal with zerophase as input. Because the phase of the input signal is zero the I- and Q-signalsshould be

I(t) = cos(0) = 1 (N.33)Q(t) = sin(0) = 0 (N.34)

The test shows that the I- and Q-signals give the desired values, and the algorithmis therefore assumed to be working.

N.2.4 C implementation considerations

When implementing the algorithm in C the time vector used to generate the digitaloscillator is not as easy to make as in MATLABTM. The reason for this is thatwhen working in MATLABTM the sound sample has a finite length and thereforealso the time vector has a finite length. When working in C the length of the soundsample is dynamical allocated and the time vector can therefore not be generated inthe same way. A solution to this problem to divide the sound samples into sampleswith a known length, and then demodulate the samples one at a time.

N.3 Arctan demodulator

The arcus tangent method for FM demodulation is propably the mathematicallymost straightfarward method, when the I and Q signals are present.

N.3.1 Principle

The principle is to derive the instantanous phase of the received FM signal by de-riving the angle of the complex number I(t)+jQ(t) as depicted by equation (N.20).From the definition of FM modulation it is known that the time derivative of theinstantanous phase is directly proportional to the message signal, see equation B.16.The principle block diagram is shown in figure N.3.

N.3.2 Mathematical description

The signals at hand are

103

Page 116: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.3. ARCTAN DEMODULATOR

Figure N.3: Block diagram of the arcus tangent demodulation method.

I(t) = A cos(φ(t)) (N.35)Q(t) = A sin(φ(t)) (N.36)

The proof of this method to derive the message signal, m(t), is carried out inthree steps referring to the blocks of figure N.3. For the calculation of h1(t) equation(N.20) is used. For the calculation of h2(t), the time derivative of the phase of anFM signal is used:

φ(t) = 2πkf

∫ t

0

m(τ)dτ (N.37)

φ′(t) = 2πkfm(t) (N.38)

h1(t) = tan−1

(Q(t)I(t)

)= φ(t) (N.39)

h2(t) =d

dt[φ(t)] (N.40)

= 2πkfm(t) (N.41)

h3(t) =1

2πkf· 2πkfm(t) = m(t) (N.42)

In practice a signal received always has a frequency offset, and phase offset,as described in section N.2.1. Carrying out a similar calculation as in the abovesection with the offset frequency ωo and offset phase φo yields:

h1(t) = φ(t) + ωot + φo (N.43)h2(t) = 2πkfm(t) + ωo + 0 (N.44)

h3(t) = m(t) +ωo

2πkf(N.45)

Hence a frequency tolerance will introduce a DC offset in the demodulated mes-sage signal. Since the phase is differentiated, a constant phase offset will have noinfluence on the demodulation.

N.3.3 Digitization considerations

All of the above calculations can be carried out on samples instead of continoustime signals. The only calculation that may introduce approximation errors isthe differentiator, which can not be accurate when operating in discrete time. Adiscrete time differentiator will use the approximation

dx

dt≈ x(nTs)− x((n− 1)Ts)

Ts(N.46)

104

Page 117: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

where:x(t) is a continous time signaln is an integer sample numberTs is the sample time [s]

N.3.4 MATLABTM implementation

The arcus tangent is implemented using the function atan2() which is a four quad-rant arcus tangent. The problem with using its two quadrant counterpart; theregular atan(), is that it only gives output in the range between −π/2 and π/2. Asboth I and Q can take on both positive and negative values, and they are dividedwith each other in order to use the arcus tangent, the two expressions atan(-1/-1)()and atan(1/1)() would of course yield the same result even though they are in op-posite quadrants. The function atan2() can handle this situation, thus producingthe correct output in the full unit circle range between −π/2 and π/2.

The function unwrap() is used to correct jumps in angles that are over π. Thisis a MATLABTM function which will not be available in C. Figure N.4 explainsthe difference between a wrapped and an unwrapped signal, and also presents adifferent approach to work around a wrapped angle. This approach is only relevantis only relevant for eventually implementation in C.

The differentiator is implemented using the approximate derivative function diff().The resulting algorithm is so short that it is pasted here:

sigdem = diff(unwrap(atan2(qb, ib)));

N.3.5 C implementation considerations

Implementation should be straightforward since the function atan2() is present inthe standard C math library. A way to work around the wrapped angle outputfrom the function is presented above. The rest should be trivial as well.

N.4 Baseband delay demodulator

The Baseband delay demodulator is another straightforward method to obtain theinformation signal from the I- and Q-signals.

N.4.1 Principle

The principle is the same as that of the arctan demodulation. Namely to derivethe instantanous phase of the received FM signal by use of the I- and Q-signal.

Figure N.5 shows the principle for the Baseband delay demodulator. In orderto understand precisely how this method generates the information signal from theI- and Q-signal, a mathematical description of the method is made.

N.4.2 Mathematical description of the Baseband delay de-modulator

The signals at hand are the I- and Q-signals discretized

105

Page 118: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.4. BASEBAND DELAY DEMODULATOR

0 200 400 600 800 1000−6

−4

−2

0

2

4

6Wrapped angle

Time in samples

Val

ue

0 200 400 600 800 1000−6

−4

−2

0

2

4

6Unwrapped angle

Time in samples

Val

ue

0 200 400 600 800 1000

−6

−4

−2

0

2

4

6

Diffed wrapped angle

Time in samples

Val

ue

0 200 400 600 800 1000

−6

−4

−2

0

2

4

6

Diffed unwrapped angle

Time in samples

Val

ue

Figure N.4: Illustration of wrapping and difference of angles. The atan2() func-tion return a wrapped angle. Wrapping occurs whenever an angleexceeds −π/2 and π/2. By adding or subtracting multiples of 2π theangle can be restored using a detection criterion such as phase jumpsof over π between two samples. If the correct difference in angle isrequired the usual way around it is to unwrap the angle and calcu-lated the difference from the unwrapped signal. However taking thedifference of a wrapped signal introduces a very known error in onlya few of the samples in that 2π is either added or subtracted from fracorrect result. Whether to add or subtract 2π to obtain the correctresult is a matter about whether the peak is positive or negative.

106

Page 119: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

h5(n)

I-signal

Q-signal

h1(n)h2(n)-

+ h3(n) h4(n)sin1 K

Q[n 1I [n 1

Figure N.5: The principle for the Baseband delay demodulator.

I(n) = A cos(φ(n)) (N.47)Q(n) = A sin(φ(n)) (N.48)

From the I- and Q-signals h1(n) and h2(n) are found.

h1(n) = A cos(φ(n− 1)) ·A sin(φ(n)) (N.49)h2(n) = A sin(φ(n− 1)) ·A cos(φ(n)) (N.50)

By substrating h2 from h1, h3 is achieved.

h3(n) = h1(n)− h2(n) (N.51)h3(n) = A2 sin(φ(n)− φ(n− 1)) (N.52)

It is now possible to find h4 by taking arcsine to h3. If the angle between twosamples a sufficient small, (φ(n)− φ(n− 1)) and sin(..) is approximately the same.The following shows this approximation.

φ(n)− φ(n− 1) = X (N.53)φ′(n) · Ts = X (N.54)

2πkfm(t)Ts = X (N.55)2π · 800048000

≈ 1.05 (N.56)

and

sin(1.05) ≈ 0.87 (N.57)

From this approximation h4 is given as

107

Page 120: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.5. BASEBAND DIFFERENTIATOR DEMODULATOR

h3(n) ≈ A2(φ(n)− φ(n− 1)) (N.58)

The following shows how the message signal is derived by multiplying h3 with aconstant K.

h5(n) =A2(φ(n)− φ(n− 1))

A2 · Ts · 2 · π · kf(N.59)

h5(n) =A2 · φ′(n)

A2 · 2 · π · kf(N.60)

h5(n) =A2 · 2 · π · kf ·m(n)

A2 · 2 · π · kf= m(n) (N.61)

As described in section N.2 the I- and Q-signals can change due to a change inthe carrier frequency or change in the phase.

Carrying out a similar calculation as in the above section with the offset fre-quency and phase yields

h3(n) = A2ωo + A2 · 2 · π · kf ·m(n) (N.62)

This gives h5(n)

h5(n) =A2 · ωo

A2 · 2 · π · kf+ m(n) (N.63)

h5(n) = DC + m(n) (N.64)

This means that a change in the carrier frequency results in a DC offset of themessage signal, and a change in the phase will have no effect on the message signal.

N.4.3 Digitalisation considerations

The method described above can directly be implemented in discrete time. Theonly calculation that can result in an error is the differentiaton as described insection N.3.3.

N.4.4 MATLABTM implementation

In MATLABTM the method described above can directly be implemented by fol-lowing the procedure shown in figure N.5.

N.4.5 C implementation considerations

Implementing the algorithm in C should be no problem.

N.5 Baseband differentiator demodulator

The Baseband differentiator demodulator is yet another way to demodulate the FMsignal by use of the I- and Q-signals.

108

Page 121: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

N.5.1 Principle

The principle for the Baseband differentiator demodulator is like the precedingmethods to obtain the instantaneous phase of the FM signal.

In figure N.6 the principle for the method is shown. As seen in the figure, the

I-signal

Q-signalDiff

Diff

K-

+ h2(t)h1(t)h3(t) h4(t)

Figure N.6: The principle for the Baseband differentiator demodulator.

principle can be expressed mathematical as

m(t) =I ·Q′ − I ′ ·Q

K(N.65)

In order to see how this method gives the information signal m(t), a mathematicaldescription is made.

N.5.2 Mathematical description of the Baseband differentia-tor demodulator

In order to find the two signals h1(t) and h2(t), the differentiated form of the I-and Q-signal needs to be known

I(t) = A cos(φ(t)) (N.66)I ′(t) = −Aφ′(t) · sin(φ(t)) (N.67)Q(t) = A sin(φ(t)) (N.68)Q′(t) = Aφ′(t) · cos(φ(t)) (N.69)

It is now possible to find h1(t) and h2(t)

h1(t) = I ′(t) ·Q(t) (N.70)h1(t) = −A2 · φ′(t) · sin2(φ(t)) (N.71)

and

h2(t) = Q′(t) · I(t) (N.72)h2(t) = A2 · φ′(t) · cos2(φ(t)) (N.73)

109

Page 122: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

N.5. BASEBAND DIFFERENTIATOR DEMODULATOR

It is now possible to find h3(t) by subtracting h1(t) from h2(t). This gives

h3(t) = h2(t)− h1(t) (N.74)

h3(t) = A2φ′(t) ·(cos2(φ) + sin2(φ)

)(N.75)

h3(t) = A2φ′(t) (N.76)

knowing that φ(t) is equal to

φ(t) = 2π · kf

∫m(t)dt (N.77)

Equation N.76 can be rewritten as

h3(t) = A2 · 2π · kf ·m(t) (N.78)

Finaly h4(t) can be derived by multiplying h3(t) with 1A2·2·π·kf

h4(t) =A2 · 2 · π · kf ·m(t)

2 · π · kf ·A2= m(t) (N.79)

The calculations made above are for the ideal case. As described in section N.2.1the I- and Q-signals can change due to a error in the carrier frequency or a errorin the phase of the local oscillator.

Carrying out a similar calculation as in the above section with the offset fre-quency and phase yields

h3(t) = A2ωo + A2 · 2 · π · kf ·m(t) (N.80)

This gives h4(t)

h4(t) =A2 · ωo

A2 · 2 · π · kf+ m(t) (N.81)

h4(t) = DC + m(t) (N.82)

This means that a change in the carrier frequency results in a DC offset of themessage signal, and a change in the phase will have no effect on the message signal.

N.5.3 Digitalisation considerations

All of the calculations described above can also be made in discrete time. The onlycalculation that may introduce an approximation is the differentiation as describedin section N.3.3.

N.5.4 MATLABTM implementation

The method described above can directly be implementated in MATLABTM with-out further considerations.

110

Page 123: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX N. QUADRATURE DETECTION

N.5.5 C implementation considerations

Like the implementations in MATLABTM the implementation in C can be madewithout further considerations.

N.6 Conclusion

The three presented algorithms hase some important characteristics in common.They use baseband quadrature signals to determine the phase or the time deriva-tive of the phase of the received FM signal. Filtering is only used in the generationof the quadrature signals where two FIR lowpass filters of order 20 are used. Thealgorithms themselves only have to look at one sample back in time in order todemodulate.

A frequency offset in the received signal (mistuning) will result in a DC-offset in themessage signal derived. A phase offset will have no influence on the demodulation.

The three algorithms have been tested briefly and the sound output is understand-able.

111

Page 124: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

Appendix OSlope detector

The slope detection is a method of FM-demodulation which converts the receivedFM signal to AM and demodulates with an envelope detector.

O.1 Principle

Any circuit that outputs the time derivative of the input can perform FM to AMconversion. In an FM signal the frequency is low, when the amplitude of themessage signal is low and vice versa. Utilizing the proporty that

d

dtf(t) ↔ sF (s) (O.1)

a differentiation corresponds to a filter having the transfer function H(jω) = jω.The ampltitude plot of this filter is shown in figure O.1. A plot of the signal beforeand after differentiation is shown in figure O.2 on page 114a and O.2 on page 114b.Obviously differentiation does not eliminate the frequencies around the carrier wave.

Differentiating the FM-signal and taking the absolute value produces a DC-offsetand the amplitude varying input signal. This is shown in figure O.2 on page 114c.The DC offset and the frequency contents near the carrier that is still present, isremoved by band pass filtering. The result is shown in figure O.2 on page 114d.The absolute value and low pass filtering corresponds to the envelope of the AMsignal.

O.2 Mathematical description

In the following a mathematical description of the slope detector is made. Theoriginal FM signal, see figure O.2a, is given on the form:

s(t) = Ac · cos(

ωc · t + 2 · π · kf ·∫

m(t) · dt

)(O.2)

112

Page 125: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX O. SLOPE DETECTOR

|H(jω)|

AM-signal

Freq. of FM-signal

ω

ωc

|H(jω)| = ω

Figure O.1: Conversion from FM to AM.

where:s(t) is the incoming FM signal. [V]ωc is the carrier frequency. [rad/s]m(t) is the messages signal. [V]Ac is the carrier amplitude. [rad/V]kf is the frequency sensitivity. [Hz/V]

By means of differention the FM signal, s(t) is transformed into an AM modu-lated FM signal, see figure O.2b. For simplicity 2πkf is subsituted by c in thefollowing and Ac is omitted.

sdiff (t) =d

dt

[cos(ωc · t + c ·

∫m(t) · dt)

](O.3)

sdiff (t) = (ωc + c ·m(t)) · − sin(ωc · t + c ·∫

m(t) · dt) (O.4)

sdiff (t) = (ωc) · − sin(ωc · t + c ·∫

m(t) · dt) + . . .

. . . (c ·m(t)) · − sin(ωc · t +∫

m(t) · dt) (O.5)

Now the absolute value is taken, see figure O.2 c.

abs(sdiff (t)) =

√((ωc) · cos(ωc · t + c ·

∫m(t) · dt)+ . . .

. . . (c ·m(t)) · cos(ωc · t + c ·∫

m(t) · dt))2

(O.6)

abs(sdiff (t)) =

√12·√

ω2c + 2 · cos(2 · (ωc · t + c ·

∫m(t) · dt)) + (c ·m(t))2+ . . .

. . . c ·m(t) · ωc + c ·m(t) · ωc · cos(2 · (ωc · t + c ·∫

m(t) · dt)) (O.7)

113

Page 126: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

O.2. MATHEMATICAL DESCRIPTION

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8

x 10−3

−1

0

1a) Frequency modulated input signal

Time [s]

Am

plitu

de [V

]

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8

x 10−3

−1

0

1x 10

5 b) Differentiated FM−signal

Time [s]

Am

plitu

de [V

]

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8

x 10−3

0

5

x 104 c) Absolute of differentiated FM−signal

Time [s]

Am

plitu

de [V

]

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8

x 10−3

−1

0

1d) 3 kHz input signal

Time [s]

Am

plitu

de [V

]

Figure O.2: Conversion of 10kHz input to FM signal to absolute of AM signal.

As a final step this new signal is bandpass filtered. This approach will onlywork if highest frequency of the wanted signal significantly lower than the carrierfrequncy [Carlson, 1986, pages 259-261], see figure O.2 d. This yields

sdemod = k ·m(t) (O.8)

where:k is a constant. [-]

O.2.1 Balanced frequency discrimination

As a final note on slope detectors, the balanced slope detector is mentioned. Bal-anced frequency discrimination offers an elegant alternative to simply blocking theDC offset. A frequency discriminator basically consists of a slope circuit, an enve-lope detector and a DC-block connected in series. In balanced frequency discrimina-tion the DC-block is omitted, and a parrallel signal route consisting of yet anotherslope circuit, H2 and and envelope detector is added. The setup is shown in figureO.3. The relation between the slope circuits H1 and H2 must fulfill equation (O.9).

|H2(f + fc)| = |H1(−f + fc)| (O.9)

That is - in the range of linearity the sum of the two transferfunctions will beconstant. Furthermore at f = fc, H1 and H2 will be equal in amplitude. Theseproporties are shown in figure O.4a. The two signals at hand are: the envelope ofthe modulated signal passed through H1 and the envelope of the modulated signal

114

Page 127: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX O. SLOPE DETECTOR

Figure O.3: Block diagram of a balanced slope detector.

(a) (b)

fc

|H2(f)| |H1(f)| |H1(f)−H2(f)|

fc −∆f fc + ∆ff f

fc −∆f fc

fc + ∆f

Figure O.4: Amplitude responses of a balanced frequency discriminator.

115

Page 128: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

O.3. DIGITIZATION CONSIDERATIONS

passed through H2. When these two are subtracted the offset amplitude cancels outand a frequency response of figure O.4b is achieved. Note that the resulting slopeis twice as steep as either one of the slopes, H1 or H2. The rule for the applicabilityof this method is the same as for the frequency discriminator.[Haykin, 2001, pages 121-124,725-730]

O.3 Digitization considerations

The digital version of the slope detector has the advantage over the analog coun-terpart, due to the linear frequency response of the slope. However this propertyis nullified if the sampling frequency is not significantly higher than the input fre-quency.

Another positive attribute of the digital signal processing is the ability to pro-duce high-order filters with relative ease.

O.4 MATLABTM implementation

The algorithm is implemented using the built in diff() and abs() functions and theself-supplied FIR-filter of appendix M on page 93.

O.5 C implementation considerations

There are no considerations regarding implementation in C.

O.6 Conclusion

In this appendix a slope FM demodulator has been explained and implementedin MATLAB. The algorithm will be testet and compared to other demodulationalgorithms in appendix K.

116

Page 129: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX P. ACCEPTANCE TEST

Appendix PAcceptance test

According to the requirement specification in chapter 2 on page 3 the system mustmeet the following requirements:

1. Demodulate a FM signal with the specifications in table 2.2 on page 5.

2. A maximum delay of 100 ms throughout the entire system, see section 2.4.

3. A SINAD (SND/ND) ratio over 20 dB, see section 2.4.

P.1 Demodulation

The system must be able to recieve a FM-signal from the radio transmitter anddemodulated it correctly.

P.1.1 Method

The capability to demodulate an FM-modulated signal with the specifications intable 2.2 on page 5 is done as a listening test, where a voice signal is appliedto the radio transmitter. The demodulated signal is evaluated as to whether theoutput of the system is understandible and if there is any unwanted distortion. Thereason for using a listening test is that the radio transmitter, the antennas and thecommunication channel between them are outside the system. Another reason isthat it’s not possible to apply an controlled signal to the radio transmitter, such asa signal from a signal generator. The test set-up is illustrated on figur P.1.

Figure P.1: Illustration of the test set-up used to test the demodulation.

The equipment used in the test can been seen in table P.1 on the followingpage. The computer is equipped with a Intel Celeron cpu running at 1333 MHz

117

Page 130: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

P.2. DELAY

using a stock debian linux kernel (2.6.8-2-686) and the program is compiled withGCC (4.0.2).

Type Model Manufacturer AAU-nrTone generator 2022D Maroni Instruments 33336Tone generator 2022D Maroni Instruments 33337Radio transmitter IC-2100 Icom 32481 & 1205-00Power supply SN16A B&O LBNR 08011Power supply SN16A B&O LBNR 33130Computer S1400-103 Toshiba -

Table P.1: Equipment used in demodulation evaluation.

P.1.2 Results

The system is able to receive and demoulated a frequency modulated signal trans-mitted from the radio. The sound quality is good without audible noise.

P.1.3 Discussion

The requirement of the system is that it sould be able to recieve a signal anddemodulate it. The test shows that the system works correct according to therequirement.

P.2 Delay

The delay throughout the system must not exceed 100 ms.

P.2.1 Method

The delay is measured by connecting one channel of a oscilloscope between theantenna and the downconverter and another channel on the output of the system.The radio tone button is used to generate a FM-modulated signal. When thetone is not transmitted the oscilloscope should measure a low voltage noise signalbefore the downconverter. Upon pressing the tone button the oscilloscope shouldmeasure a higher level FM-modulated signal. The oscilloscope is set a make asingle-shot triggered by the rise in signal level. When the tone button isn’t pressedthe demodulation should produce noise. Upon pressing the button, the tone shouldbe present on the output of the system. The oscilloscope time base is adjusted toshow both the rise in signal level before the downconverter and the change in theoutput from noise to signal. The test set-up is illustrated on figur P.2 on the nextpage.

The equipment used in the test is same as in the previous test plus the equipmentin table P.2 on the facing page.

118

Page 131: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX P. ACCEPTANCE TEST

Figure P.2: Illustration of the test set-up used to meassure the delay in the system.

Type Model Manufacturer AAU-nrOscilloscope 54671A Agilent LVNR 33866

Table P.2: Equipment used in delay evaluation.

P.2.2 Results

The output from the oscilloscope can be seen in figure P.3. The delay is measuredto approximately 400 ms.

P.2.3 Discussion

The requirements for total delay was that it should be lower than 100 ms. As thetotal delay is measured to 400 ms, the delay is 4 times higher then the requirement.Since the system only is a receiver, the requirement only has little significance. Ifthe system should work in a duplex setup the delay requirement is more critical.

P.3 SINAD ratio

The SINAD ratio must be over 20 dB.

P.3.1 Method

This will be tested by applying a modulated -18 dBm 1 kHz tone with a carrierfrequency of 145 MHz and a frequency deviation of 5 kHz to the input of thedownconverter. All data sent to the sound card is saved in a file and the SINAD ratiois calculated using the same method described in ”Test of demodulation algorithm”from appendix K on page 77. By saving the data the distortion in the digital toanalog conversion in sound card isn’t included in the SINAD ratio calculation.

The test set-up is illustrated on figur P.4 on the following page. The equipmentused in the test can been seen in table P.3 on the next page.

P.3.2 Results

The result from the test was a SINAD ratio of 28.0 dB.

119

Page 132: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

P.3. SINAD RATIO

−0.1 0 0.1 0.2 0.3 0.4 0.5−0.8

−0.7

−0.6

−0.5

−0.4

−0.3

−0.2

−0.1

0

0.1

0.2

Time [s]

Am

plitu

de [V

]

Received signalDemodulated signal

Figure P.3: Results of the delay test. The uppermost signal is the signal receivedby the IO system. The signal below is the demodulated output of theIO system. The lowermost signal has its amplitude factored down by5, and offset by −0.5V. The delay of the system is measured from thereception of the transmitted signal to the effectuation on the output(the effectuation is shown by the lack of squelch).

Figure P.4: Illustration of the test set-up used to test the demodulation.

Type Model Manufacturer AAU-nrTone generator 2022D Maroni Instruments 33336Tone generator 2022 Maroni Instruments 08158Tone generator 2022D Maroni Instruments 33337Power supply SN16A B&O LBNR 08011Power supply SN16A B&O LBNR 33130Computer S1400-103 Toshiba -

Table P.3: Equipment used in SINAD test.

120

Page 133: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

APPENDIX P. ACCEPTANCE TEST

P.3.3 Discussion

This result is within the requirements of system. The loss of approximately 10 dBSINAD ratio compared to the MATLABTM simulation is also to be expected, dueto the added noise from the downconversion, AGC, analog to digital conversion andpossible inaccuracies in the carrier and downconversion frequencies.

P.4 Conclusion

The acceptance test has shown that the system works, in regard to the listeningtest and the SINAD ratio. However, the delay is 4 times as high as specified in therequirement specification.

121

Page 134: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/report.pdf · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik Group 506 Andreas Trøllund

LIST OF CORRECTIONS

List of Corrections

FiXme Note: ret titelblad . . . . . . . . . . . . . . . . . . . . . . . . . . . 3

122