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

133
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/051213/report.pdf ·...

Page 1: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik
Page 3: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

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

Pages: 27

Appendices: 19

Finished December 9, 2005

Synopsis:

Insert synopsis here. . . found in mainRe-

port/frontMatter/synopsis.tex

Page 4: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

Foreword

About the structure of the report.. do we thank anybody... anyone??

Page 5: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Contents

I Main report 2

1 Introduction 3

2 Requirement specification 42.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42.2 System interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52.3 Quality factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6

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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104.2 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11

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

6 Demodulation 156.1 Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 156.2 Test results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176.3 Decision . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

7 Acceptance test 217.1 Demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.2 Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 217.3 Signal to distortion ratio . . . . . . . . . . . . . . . . . . . . . . . . . 21

ii

Page 6: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

8 Conclusion 23

II Appendix report 27

A Sound card 28

B Modulation 30

B.1 Amplitude modulation . . . . . . . . . . . . . . . . . . . . . . . . . . 30

B.2 Frequency modulation . . . . . . . . . . . . . . . . . . . . . . . . . . 33

C Downconverter 39

C.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39

C.2 Building blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

C.3 Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41

C.4 Mathematical analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 42

C.5 Dimensioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

C.6 Measurements of downconverter . . . . . . . . . . . . . . . . . . . . . 43

C.7 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

D Input-filter 46

D.1 Filter-specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

D.2 Filter-design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

D.3 Filter-simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51

E Multithreading 53

E.1 General multithreading . . . . . . . . . . . . . . . . . . . . . . . . . 53

E.2 Selection of threading API . . . . . . . . . . . . . . . . . . . . . . . . 54

E.3 GNU Pth general usage . . . . . . . . . . . . . . . . . . . . . . . . . 55

F Advanced Linux Sound Architecture 57

F.1 Data flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57

F.2 Data structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

F.3 Alsa API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

F.4 Control interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

F.5 PCM interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

G IO system 61

G.1 Analysis and design . . . . . . . . . . . . . . . . . . . . . . . . . . . 62

G.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65

H Sallen and Key filter 69

H.1 Low pass Sallen and Key filter realization . . . . . . . . . . . . . . . 69

H.2 High pass Sallen and Key filter realization . . . . . . . . . . . . . . . 71

I Automatic Gain Control 73

I.1 Theory of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

I.2 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73

Page 7: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

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 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83K.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85K.5 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

L Zero cross Detection 87L.1 Basic zero cross detection . . . . . . . . . . . . . . . . . . . . . . . . 87L.2 Zero cross detection with frequency estimation . . . . . . . . . . . . 89L.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

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

N Quadrature detection 97N.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97N.2 IQ generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100N.3 Arctan demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 103N.4 Baseband delay demodulator . . . . . . . . . . . . . . . . . . . . . . 105N.5 Baseband differentiator demodulator . . . . . . . . . . . . . . . . . . 107N.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109

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

P Acceptance test 116P.1 Demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 116P.2 Delay . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117P.3 SND/ND ratio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119P.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120

Page 8: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

List of Tables

2.1 Definitions of the system requirements . . . . . . . . . . . . . . . . . 52.2 Specification of the transmission . . . . . . . . . . . . . . . . . . . . 52.3 Input specification of the system . . . . . . . . . . . . . . . . . . . . 52.4 Output specification of the system . . . . . . . . . . . . . . . . . . . 5

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

Corporation] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13

6.1 Result of the listening test . . . . . . . . . . . . . . . . . . . . . . . . 196.2 Result of the complexity test . . . . . . . . . . . . . . . . . . . . . . 20

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

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

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

Corporation] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

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

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

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

J.1 Equipment used in test. . . . . . . . . . . . . . . . . . . . . . . . . . 75

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

v

Page 9: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

K.2 Result of the complexity test. (*) Uses functions with unknownedcomplexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

P.1 Equipment used in demodulation evaluation. . . . . . . . . . . . . . 117P.2 Equipment used in delay evaluation. . . . . . . . . . . . . . . . . . . 117P.3 Equipment used in SND/ND test. . . . . . . . . . . . . . . . . . . . 120

Page 10: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

List of Figures

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

3.1 Function diagram of radio transmitter . . . . . . . . . . . . . . . . . 7

3.2 Frequency overview of a FM-modulated signal. . . . . . . . . . . . . 8

3.3 Function diagram of radio receiver . . . . . . . . . . . . . . . . . . . 8

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

5.1 Blockdiagram of the downconverter . . . . . . . . . . . . . . . . . . . 13

6.1 Signal-noise ratio of pure sines . . . . . . . . . . . . . . . . . . . . . 18

6.2 Signal-noise ratio with induced noise . . . . . . . . . . . . . . . . . . 19

6.3 Frequency spectrum of each demodulation algorithm . . . . . . . . . 20

7.1 Results of the delay test . . . . . . . . . . . . . . . . . . . . . . . . . 22

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

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

B.3 Amplitude modulation using two different carrier frequencies. . . . . 32

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

B.5 Besselfunktion of 0 to 3 orders as a funtion of β . . . . . . . . . . . . 37

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

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

C.1 Displacement of frequency spectrum. . . . . . . . . . . . . . . . . . . 39

C.2 Mirrors as a result of product modulation. . . . . . . . . . . . . . . . 40

C.3 Symbol of a 3-terminal mixer. . . . . . . . . . . . . . . . . . . . . . . 41

C.4 Block diagram of a possible downconverter solution. . . . . . . . . . 41

C.5 Test setup for downconverter. . . . . . . . . . . . . . . . . . . . . . . 44

D.1 4. order band pass Sallen and Key filter . . . . . . . . . . . . . . . . 51

D.2 Simulation of the bandpass filter. . . . . . . . . . . . . . . . . . . . . 51

vii

Page 11: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

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

F.1 Structure of the interleaved and non-interlaaved buffer structure usedin ALSA. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

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

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 signal to distortion test. . . . . . . . . . . . . . 78K.2 Signal to distortion block diagram. . . . . . . . . . . . . . . . . . . . 78K.3 1000 order hamming window FIR frequency responce. . . . . . . . . 79K.4 Implemention of the signal to noise test, where noise has been added

before demodulating. . . . . . . . . . . . . . . . . . . . . . . . . . . . 80K.5 Implemention of the DFT analysis test. . . . . . . . . . . . . . . . . 80K.6 FFT analysis of 1 kHz sine tone . . . . . . . . . . . . . . . . . . . . . 82K.7 Comparison of signal to distortion ratio. . . . . . . . . . . . . . . . . 83K.8 Signal to distortion ratio with induced noise. . . . . . . . . . . . . . 84K.9 DFT plot of a 1 kHz demodulated test signal. . . . . . . . . . . . . . 84

L.1 Block diagram Zero-crossing Detection Demodulation Algorithm. . . 87L.2 The zero-cross demodulation process. . . . . . . . . . . . . . . . . . . 88L.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. . . . . . . . . . . . . . . . . . . . . . . . . . 92

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 making the I- and Q-signals . . . . . . . . . . . 101N.3 Block diagram of the arcus tangent demodulation method. . . . . . . 103N.4 The principle for the Baseband delay demodulator. . . . . . . . . . . 105N.5 The principle for the Baseband differentiator demodulator. . . . . . 108

O.1 Conversion from FM to AM. . . . . . . . . . . . . . . . . . . . . . . 112O.2 Conversion from input to FM to AM . . . . . . . . . . . . . . . . . . 113

Page 12: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

O.3 Block diagram of a balanced slope detector. . . . . . . . . . . . . . . 114O.4 Amplitude responses of a balanced frequency discriminator. . . . . . 114

P.1 Illustration of the test set-up used to test the demodulation. . . . . . 116P.2 Illustration of the test set-up used to meassure the delay in the system.118P.3 Output af the delay test . . . . . . . . . . . . . . . . . . . . . . . . . 118P.4 SND/ND ratio calculation principle. . . . . . . . . . . . . . . . . . . 119P.5 Illustration of the test set-up used to test the demodulation. . . . . . 119

Page 13: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

FiXme: jtkr04: fjern dato maerker fra toppen af haedere (er paa begge sider)!

1

Page 14: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Part I

Main report

2

Page 15: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 1. INTRODUCTION

Chapter 1Introduction

BRUG ORDET: “INITIAL PROBLEM”!!!! (nemlig) something

FM modulation is used in a wide range of radio applications, but this projectfocuses on amateur radio signals, which has the advantage of low bandwidth andthat a transmitter is available to the group for testing puposes. The frequency bandused for testing is 144.0 - 146.0 MHz which is allocated for amateur radio. Thebandwidth of amateur radio signals in the range 50 to 146 Mhz must not exceed 16kHz [IT- og Telestyrelsen, page 14]. However, similar techniques as those describedin this report can be applied to

3

Page 16: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Chapter 2Requirement specification

2.1 General description

2.1.1 System description

The system is a PC-based radio receiver, which has two external interfaces; anantenna, and a soundcard. The goal of the system is to demodulate an FM signaland play it out of the soundcard of the PC. See figure 2.1 for a overview of thesystem.

Figure 2.1: System overview

2.1.2 Limitations of the system

Due to the fact that the system is only to function in a labatory setting, the auto-matic gain control only has to function correctly in the lab, where the transmitteris within 5 metres of the receiver.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,page 392].

2.1.3 Further plans for the system

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

2.1.4 User profile

The users are primarily the developers of the system.

4

Page 17: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 2. REQUIREMENT SPECIFICATION

htbp

Name DescriptionSND/ND ratio (Signal + Noise + Distortion)/(Noise + Distortion), ratio

describing the quality of the sound transferERP Effective Radiated Power, index

describing the power of the transmitted signal (i.e. dBmERP)

Table 2.1: Definitions of the system requirements

2.1.5 Definitions

2.2 System interface

2.2.1 Input

The input is specified to the signal that received by the antenna. The transmissionhas the following specifications: With this setup, the input signal that is received

Frequency range of message signal 300-3000HzDistance from receiver ≤ 5 mTransmission power 23 dBERP

Carrier Frequency 145MHzMax bandwidth 16 kHz

Table 2.2: Specification of the transmission

by the antenna has been measured to the following (see appendix J):

Carrier Frequency 145MHzMax bandwidth 16 kHzSignal magnitude -33 dBm

Table 2.3: Input specification of the system

2.2.2 Output

The output is specified to:

Frequency range 300 - 3000 HzStereo/Mono MonoBitresolution 16 bit

Table 2.4: Output specification of the system

2.2.3 Hardware interface

The hardware interface consists of an antenna and a soundcard. The antennareceives a signal transmitted by a transmitter in the lab, and the soundcard is

5

Page 18: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

2.3. QUALITY FACTORS December 9, 2005

connected to a loudspeaker. The input is connected via a BNC plug, the output ofthe soundcard is a minijack female plug.

2.2.4 User interface

There are no requirements for the user interface.

2.3 Quality factors

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

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

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

6

Page 19: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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 toanother 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 hasa different carrier frequency (fig. 3.2). Due to the requirements of sound qualityfor commercial radiostations, they are allowed to have a bandwidth of 150 kHz.The radio amateurs are only allowed to have a bandwidth of 16kHz, due to the factthat they do not need a high sound quality, as they only transmit speech. [IT- ogTelestyrelsen, page 14]

7

Page 20: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

3.2. DATA ACQUISITION December 9, 2005

Figure 3.2: Frequency overview of a FM-modulated signal.

The purpose of a radio receiver (fig. 3.3) is to receive the transmitted signal,and transform it to its original form.

Figure 3.3: Function diagram of radio receiver

3.2 Data acquisition

The aim of the project is to sample a radio signal and let a computer handle thedemodulation. The concerns about sampling sums up to a) the sample frequencyand b) the frequency range of the AD converter. Sampling high frequencies requiresa high sampling frequency. However it is possible to lower the frequency of aband limited radio signal by analog downconverting, before the signal is sampled.Knowing that the computer to be used is a regular PC this yields two options,which are described in the following.

3.2.1 High frequency sampling

Some of the fastest I/O extension cards for PCs samples at around 200 MHz[www.ni.com], which would be sufficient for direct sampling of most broadcast radiosignals at Nyquist. The solution is expensive compared to analog receiving. Fur-thermore it it only possible for applications which operate with carrier frequenciesbelow approximately 100 MHz.

3.2.2 Analog downconversion and low frequency sampling

Downconversion is the process of ’moving’ a band limited signal to lower part of thefrequency spectrum. Since radio signala are always band limited analog downcon-version is possible without loosing signal. The downconverter hardware is simpleand cheap, and a low frequency signal allows the use of much cheaper I/O cardsfor sampling.

A very common I/O card is a standard PC sound card as described in appendix A.The sound card is designed for both input and output of audio signal which rangesfrom 20 Hz to 20 kHz. The sound card can be used to sample other signals than

8

Page 21: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 3. ANALYSIS

audio, in this case an amateur radio signal as the one described in the previoussection. The bandwith of the radio signal (16 kHz) is lower than the bandwidth ofan humanly audible audio signal (20-20000 Hz), so if the radio signal can be down-converted to fit into the audio 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, andfurthermore it utilizes hardware already present in most computers. Some chal-lenges can be predicted in the demodulation of the signal; a) Non-linear phase ofthe soundcard may distort the FM signal in an unknown way and b) the demod-ulation may more difficult or require more computing power, since the modulatedsignal will be in the audible range.

3.3 Software demodulation

The demodulation software is considered an application running on a PC operat-ing system among other applications. The challenge in this lies in handling thefact that program flow is controlled more by the operating system and less by theprogrammer. The system will be interrupted many times each second by other PCperipherals i.e. mouse or USB. While this is happening the demodulation softwaremust continue to receive the bit stream from the I/O card, process them, and playthe message signal in real time, with some delay.

Linux has been chosen as platform because it preferred and known by the groupmembers. FiXme: Find p grunde til at vi kan lide linu

Linux offers direct access to peripheral hardware, but to support multiple soundcards with the same software, the interface between the demodulation softwareand the soundcard will be ALSA, which is the standard sound API for linux. Seeappendix F for more info 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 specifi-cation. This particular signal can be sampled using an AC’97 compliant PC soundcard as described in appendix A if it is first downconverted to the audible range offrequencies. An analogue downconverter therefore has to be designed. The demod-ulation will be done by a program running on a linux desktop operating system,maybe among other programs. The program will interface with the ALSA soundAPI for all communication with the sound card. The software must operate in realtime, which means that it must process data as they come, and continously outputprocessed data, using the same sound card.

9

Page 22: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

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

• Antialiasing-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

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 in

10

Page 23: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 4. SYSTEM DESCRIPTION

frequency, 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Chapter 5Chronological signal processing

FiXme Note: jtkr04: add reference from here to each section in the appendixes(and change that bloody title) In this chapter the signal way through the systemis described. This is done with reference to figure 4.1 on page 10 which shows ageneral block diagram of the system.

The system is described in the following order:

• Downconverter

• Input-filter

• Automatic Gain Control (AGC)

• Capture sound card

• Demodulation algorithm

• Playback sound card

5.1 Downconverter

The purpose of the downconverter is to downconvert the received FM signal toa frequency more suitable for the rest of the system.The received signal has thespecifications shown in table 5.1

Parameter Value Units

Received signal fc 144 MHzReceived signal fBW 16 kHz

Table 5.1: Specification of input to downconverter

In order to sample the received signal in the soundcard the signal is downcon-vertet from 144 MHz to 9 kHz. This is done as shown in figure 5.1.

12

Page 25: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005CHAPTER 5. CHRONOLOGICAL SIGNAL PROCESSING

Figure 5.1: Blockdiagram of the downconverter

The downconversion is done in two steps as shown in the figure. In order todownconvert the signal to 9 kHz the two local oscillator is chosen as

fLO,1 = 75MHz (5.1)

fLO,2 = 69.991.000Hz (5.2)

This results in the output signal described in table 5.2

Parameter Value Units

Output signal fc 9 kHzOutput signal fBW 16 kHz

Table 5.2: Downconverter output specificatons

5.2 Input-filter

The purpose of the input-filter is to match the signal from the downconverter tothe soundcard. This is done by comparing the signal from the downconverter tothe specifications of the soundcard. The signal from the downconverter is describedin tabel 5.2. Comparing this with the specificatinons for the soundcard shown intable 5.3, it is shown that some of the signals will be interpret as noise. This isbecause the soundcard filter has a analog frequency responce from 20 Hz - 20 kHz.

Min Max Units

Analog 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]

It is therefor chosen to filter frequencies under 1 kHz and over 17 kHz. Thisis done with a 4th order Butterworth band pass filter realized as a Sallen and keyfilter.

5.3 Automatic Gain Control

The received radio signal has an amplitude level depending on the reception condi-tions. To correct the received signal, an Automatic Gain Control (AGC henceforth)

13

Page 26: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

5.4. CAPTURE SOUND CARD December 9, 2005

is inserted.This circuit places its output voltage level as close as possible to a predefined

level of 100mV, thereby matching the requirements of the soundcard with micro-phone boost. See table A.2 on page 28 for sound card requirements.

The circuit uses the SL6270C chip and is designed 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 from1kHz to 17 kHz. This is sampled with a sampling frequency of 48000Hz by theinput soundcard, thereby conforming to the Nyquist theorem.

The precision of the sampling is set to 15 bits signed integers, thereby assumingvalues of ±215 = 32768, with a value of 32768 as the full scale input of table A.2 onpage 28. The act of sampling and delivering data to the demodulation is handledby the IO system of chapter G on page 61. See this for further information aboutdata parsing. See chapter F on page 57 for information about the choosen ALSAsound API.

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 next page. The discription ispostponed due FiXme Note: cste04: ... goer noget... skriv hvorfor vi udsaetterdet .

5.6 Playback sound card

The demodulated output is parsed to the output soundcard for playback. Thisis done using the ALSA API of chapter F on page 57, the resolution of the D/Aconverter in the soundcard is 16bits, according to FiXme Note: ghoe04: find sourcethat describes amount of output bits (AC97?).

14

Page 27: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 6. DEMODULATION

Chapter 6Demodulation

The goal of the project is to do a demodulation of an arbitrary FM signal. To dothe demodulation, a specific algorithm must be selected. Several algorithms havebeen tested in the project and this chapter explores the results.

The chapter will start with a short description of the different algorithms, pro-ceed with the test results (see chapter K.3 on page 83 for test description andresults) and finally decide which algorithm to implement.

The examined algorithms are

• Zero crossing detection:

– Basic zero crossing detection

– Improved zero crossing detection

• Slope detection:

– Single slope detection

• Quadrature detection:

– Arctan demodulation

– Baseband delay demodulation

– Baseband differentiaton demodulation

which will be explained in the next section.

6.1 Algorithms

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

15

Page 28: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

6.1. ALGORITHMS December 9, 2005

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 thebasic 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.

See section K.5 on page 86 for further information.

6.1.2 Improved zero crossing detection

yThe zero cross detection with frequency estimation algorithm is a 1st order inter-polation to estimate the current frequency of the modulated signal. This is doneby dividing the samplerate with the time between the zero crossings.

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

6.1.3 Single Slope detection

The slope detection algorithm works by converting the supplied FM signal to anamplitude modulated signal, thus revealing the envelope of the modulating signal(the source). This is done by differentiating the FM-signal, resulting in the am-plitude modulated version of the FM-signal, for which the envelope of the sourcesignal can be extracted by taking the absolute value of each sample, and bandpassfiltering the result.

See appendix O on page 111 for further information.

6.1.4 Arctan quadrature demodulation

The principle for the arctan quadrature demodulation algorithm, is to demodulatethe FM signal using quadrature signals. This is done by deriving the instantanousphase of the FM signal by deriving the angle of the complex number I(t)+jQ(t).From the instantanous phase the information signal is found, by noting from thedefinition of the FM modulation, that the derivative of the instantanous phase isdirectly proportional to the information signal.

The arctan quadrature demodulation algorithm deriveds the angle between theI- and Q-signal by that the I- and Q-signals are defined as

I(t) = A cos(φ(t)) (6.1)

Q(t) = A sin(φ(t)) (6.2)

From this the angle between the I- and Q-signal can be found by

φ(t) = tan−1

(

Q(t)

I(t)

)

(6.3)

Now the information signal can be found as the derivative of the phase.

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

16

Page 29: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 6. DEMODULATION

6.1.5 Baseband delay quadrature demodulation

The principle for the baseband delay quadrature demodulation algorithm is ap-proximately the same as for the arctan quadrature demodulation algorithm. Thedifference between the to methodes is the way the derivative of the instantanousphase is obtaind from the I- and Q-signals.

The baseband delay quadrature demodulation algorithm derive the derivativeof the instanttanous phase by first delaying the I- and Q-signals one sample andmultipling it with the other. This means that the delayed I-signal is multiplyedwith the Q-signal and the delayed Q-signal is multiplyed with the I-signal. Nowthe derivative of the instantanous phase can be found by substrating the delayedQ-signal multiplyed with the I-signal from the delayed I-signal multiplyed withthe Q-signal. This gives the following expression for finding the derivative of theinstantanous phase

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

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

6.1.6 Baseband differentiation demodulation

The principle for the baseband differentiation demodulation algorithm is approxi-mately the same as for the arctan quadrature demodulation algorithm. The differ-ence between the to methodes is the way the derivative of the instantanous phaseis obtaind from the I- and Q-signals.

The baseband differentiation demodulation algorithm derives the derivative ofthe instantanous phase by differentiating the I- and Q-signals and multiplying itwith the other signal. This means that the differentiatet I-signal is multiplyedwith the Q-signal and the differentiatet Q-signal is multiplyed with the I-signal.Now the differentiatet I-signal multiplyed with the Q-signal is substrated fromthe differentiatet Q-signal multiplyed with the I-signal. This gives the followingexpression

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

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

6.2 Test results

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

• Signal-noise ratio

• Signal-noise ratio with induuced noise

• Visual inspection of DFT output

• Listening test

17

Page 30: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

6.2. TEST RESULTS December 9, 2005

• Complexity comparisons

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

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

6.2.1 Signal-noise ration

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

103

10

20

30

40

50

60

70

80

f [Hz]

S/N

[dB

]

Signal−noise ratio

MatlabZero−CrossZero−Cross2SlopeQuadQuadAtanQuadDiff

Figure 6.1: Signal-noise ratio of pure sines

The algorithms perform differently over the tested frequency spectrum as shownin the figure. However the arctan quadrature demodulation algorithm has the bestsignal-noise ration over the entirer frequency spectrum.

6.2.2 Signal-noise ratio with induced noise

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

The algotithms perform differently over the tested frequency spectrum as shownin the figure. However the arctan quadrature demodulation algorithm has the bests/n ration over the entirer frequency spectrum.

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 som of the algorithms generates 2nd and 3rd order harmonic frequencies.

6.2.4 Listening test

A listening test is made, in order to test which algorithm is most understandable.The result is shown in table 6.1.

18

Page 31: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 6. DEMODULATION

103

5

10

15

20

25

30

35

40

45

f [Hz]

S/N

[dB

]

Signal−noise ratio

MatlabZero−CrossZero−Cross2SlopeQuadQuadAtanQuadDiff

Figure 6.2: Signal-noise ratio of modulated 1kHz tone, with induced noise

Algorithm Male Female

Quad 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. Higher is better.

As seen the arctan quadrature demodulation algorithm is most understandablewhen demodulating a female, and the Baseband delay quadrature demodulationalgorithm is most understandable when a male 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 result is shown in table 6.2.

As seen in the table the Single Slope detection algorithm is the least complexalgorithm, and the Baseband differentiation demodulation algorithm is the mostcomplex.

6.3 Decision

The arctan quadrature demodulation algorithm and the baseband delay quadraturedemodulation algorithm scored best in the listening test. These ware also the mostcomplex algorithms, whereas the Single Slope detection algorithm is the least com-plex algorithm. The arctan quadrature demodulation algorithm has the bedst s/n

19

Page 32: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

6.3. DECISION December 9, 2005

102

103

104

0

0.1

0.2ZeroCross 1

102

103

104

0

0.1

0.2ZeroCross 2

102

103

104

0

0.1

0.2Slope Detection

102

103

104

0

0.1

0.2Quad

102

103

104

0

0.1

0.2QuadAtan

102

103

104

0

0.1

0.2QuadDiff

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

Algorithm Complexity

Single 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).

with and without noise. It is therefor chosen to implement the arctan quadraturedemodulation algorithm.

20

Page 33: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 7. ACCEPTANCE TEST

Chapter 7Acceptance test

The acceptance test has been conducted according to the specifications in ap-pendix P on page 116. This is done to test compliance with the requirementspecification of chapter 2 on page 4.

The results of the acceptance test will here be exhibited and evaluated.The three tests involved are

• Demodulation of speech test

• Delay test

• Signal to distortion ratio

7.1 Demodulation

The results of the demodulation tests shows that the system is able to demodulatespeech. The demodulated speech is clearly understandable.

7.2 Delay

The delay through the system was measured to approximately 400ms, as shown infigure 7.1 on the next page. This is violation of the requirement specification by aa factor of 10.

7.3 Signal to distortion ratio

A bit weird, but around 17dB....

21

Page 34: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

7.3. SIGNAL TO DISTORTION RATIO December 9, 2005

−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 the IO system.The lowermost signal has its amplitude factored down by 5, and offset by −0.5V.The delay of the system is measured from the reception of the transmitted signalto the effectuation on the output (the effectuation is shown by the lack of squelch).FiXme Note: jtkr04: find better description of this

22

Page 35: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 CHAPTER 8. CONCLUSION

Chapter 8Conclusion

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

This problem is solved by downconverting the bandwidth limited signal from 145MHzto a carrier frequency of 9 kHz by the use of mixers. This leaves a downconvertedsignal that lies in the range of 1 to 17 kHz, which can be sampled using a stan-dard AC’97 compliant sound card. Before the sampling, the FM signal is bandpassfiltered and amplitude adjusted to fit the specifications of the sound card.

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 demdulation algorithms have been evaluated by MATLABTM im-plementation, regarding SINAD (SIgnal, Noise And Distortion) , noise resistance,output quality (listening test) and programming complexity. Based on this thearcus tangent quadrature demodulation algorithm have been chosen for final im-plementation.

The chosen demodulation algorithm excels in output quality, distortion ratioand especially resistance to noise and carrier deviation. This concurs with preelim-inary theory studies, since these shows that the carrier amplitude, to which noiseis added, cancels out.

The end result is a PC based FM demodulator, capable of receiving a 145MHz FMsignal and replaying the output via a sound card. This is done with a measuredSINAD ratio of 28.0 dB and a latency of 400ms, producing clearly understandablespeech.

The latency violates the requirement specification by a factor of 10. This is dueto latency in the buffer system, induced by requirements by the sound card. Thiscan be remedied by a different structure of the buffer system. The SINAD andoutput quality meets the specified requirements.

23

Page 36: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

About further improvements, utilizations and what should be changed if we wereto use it in another situation (bandwidth change, carrier change... etc)

What we have learned, ALSA, LINUX, c, FM demodulation, multithreading, mat-lab simulation, signal processing.... (add your own entries here).

24

Page 37: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 BIBLIOGRAPHY

Bibliography

ALSA (2005).Advanced Linux Sound Architecture(Advanced Linux Sound Architecture,2005),URL http://www.alsa-project.

org.

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.

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. The CDalso contains the source code and thedocumentiation in html.

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.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).

25

Page 38: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

BIBLIOGRAPHY December 9, 2005

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.

26

Page 39: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Part II

Appendix report

27

Page 40: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Appendix ASound card

Sampling a signal using using a PC sound card is only possible if the sound cardsmeets certain specification set by the properties of the input signal. The inputsignal may also have to be adapted to meet the input specification of the soundcard. The purpose of this appendix is to examine the specification of a general PCsound card. Audio Codec ’97 is a royalty-free sound card standard developed byIntel Corporation. The specification defines the architecture and digital interfaceof a sound card including analog performance characteristics of the input signal.In order to sample the input signals there are a few key parameters the 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 is listed asin table A.1. [Intel Corporation]

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

Other parameters that have to be taken into consideration when sampling usingan AC’97 sound card is listed in table A.2 AC’97 defines the sampling resolution

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

28

Page 41: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX A. SOUND CARD

as full-duplex 16 bit.

29

Page 42: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

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 baseband signal, where the term baseband is used to designate theband of frequencies representing the original signal.

Often it is necessary to shift the baseband frequencies to a frequency rangemore suitable for transmission, which is done by modulation. Modulation is amethod where a carrier frequency is changed in accordance to a modulation signal.As carrier frequency a sinusoidal wave is often used, in which case the modula-tion becomes a continuous-wave modulation process. The modulation signal is thebaseband signal, and the result of the modulation is referred to as the modulatedsignal.

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 m(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(m) = Ac cos(ωct) (B.1)

(B.2)

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

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

30

Page 43: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX B. MODULATION

0 2 4 6 8 10 12−1

0

1

t [s]

Am

plitu

deCarrier wave

0 2 4 6 8 10 12−1

0

1

t[s]

Am

plitu

de

Modulation signal

0 2 4 6 8 10 12−2

0

2

Am

plitu

de

t[s]

Amplitude modulated signal

0 2 4 6 8 10 12−1

0

1

Am

plitu

de

t[s]

Frequency modulated signal

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

Where ka is a constant called the amplitude sensitivity. In equation B.3 it is clearthat the value of kam(t) determines the amplitude of the modulated signal. The

0 2 4 6 8 10 12−2

0

2

Am

plitu

de

t[s]

Amplitude modulated signal Ka = 0.5

0 2 4 6 8 10 12−2

0

2

Am

plitu

de

t[s]

Amplitude modulated signal Ka = 1

0 2 4 6 8 10 12−5

0

5

Am

plitu

de

t[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

value of kam(t) must therefore be chosen suitable in order to avoid over modulation

31

Page 44: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

B.1. AMPLITUDE MODULATION December 9, 2005

and phase reversal. Figure B.2 illustrate at AM signal with three different valuesof ka and

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

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

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

An other criteria for the modulation to be successful is

fc >> W (B.6)

where W is the highest frequency component of the baseband signal m(t). If thiscriteria is not fulfilled it will not be possible to visualize an envelope. The criteriais illustrated in Figure B.3, where the graphs on the left illustrate the AM usinga carrier frequency 20 times as fast as the baseband signal, resulting in a clearenvelope of the baseband, as in the bottom left graph. To the right a carrierfrequency only twice as fast as the baseband signal is used, and the basebandsignal can hardly be recognized in the AM signal as in the bottom right graph.

0 2 4 6 8 10 12

−0.5

0

0.5

1

t [s]

Am

plitu

de

Carrier wave (20 ω/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

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.3 is rewritten, and m(t) is replaced by a sinusoidal wave.

32

Page 45: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX B. MODULATION

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

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

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

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.9)

Acka

j4

(

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

(B.10)

Acka

j4

(

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

(B.11)

Acka

2

(

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

(B.12)

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

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

Figure (a) shows that the three frequencies exist 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 is leftas shown in figure B.4 (b). Figure (b) shows that the side frequencies (ωc + ωm)and (ωc −ωm) is placed on each side of the carrier frequency with a distance of fm

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.13)

then the instantaneous frequency is defined by

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

fi(t) = fc + ∆f cos(ωmt) (B.15)

33

Page 46: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

B.2. FREQUENCY MODULATION December 9, 2005

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 4000

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5x 10

4 (a)

frequency (Hz)

S(f

)

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

Where

∆f = kfAm (B.16)

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 proportionalwith the amplitude of the modulation signal, and independent of the frequency ofthe modulation signal. To get a expression for how much the frequency changesover a periode from 0 to t equation B.15 is integrated.

Θi(t) = 2π

∫ t

0

fi(τ)dτ (B.17)

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

∫ t

0

m(τ)dτ (B.18)

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.19)

The ration of the frequency deviation ∆f = kf · Am, to the modulation frequencyis called the modulation index which is given as

β =∆f

fm(B.20)

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

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

34

Page 47: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX B. MODULATION

From equation B.21 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.22)

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.22 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.22 the following expression for s(t)can be achieve

s(t) = Re[

Acejωct+jβ sin(ωmt)

]

(B.23)

s(t) = Re[

s(t)ejωct]

(B.24)

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

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

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.26)

where the complex fourier coefficient cn is defined by

cn =1

T

∫ T

2

−T

2

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

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

cn =Ac

∫ π

−π

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

cn =Ac

∫ π

−π

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

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

cn =Ac

∫ π

−π

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

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

Jn(β) =1

∫ π

−π

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

35

Page 48: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

B.2. FREQUENCY MODULATION December 9, 2005

This gives a new expression for cn

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

Substituting equation B.32 in equation B.26

s(t) = Ac

∞∑

n=−∞

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

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

s(t) = Ac · Re[

∞∑

n=−∞

Jn(β)ej(ωc+nωm)t]

(B.34)

By remembering that

Re[

ej(ωc+nωm)t]

= cos[

(ωc + nωm)t]

(B.35)

equation B.34 can be rewritten to

s(t) = Ac

∞∑

n=−∞

Jn(β) · cos[

(ωc + nωm)t]

(B.36)

Fourier transform of equation B.36 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.37)

A plot of the Jn(β) is shown in Figure B.5. The first 4 orders are plotted withβ values from 0 to 10, however when modulation an base band signal a fixed β isused. Figure B.6 show the first 25 orders of the besselfunction with β = 1 5 15.The Figure clearly shows that the bandwidth needed when frequency modulatinga fixed single tone base band signal (fm = constant) increase when β is increased.The needed bandwidth can be estimated by inspection of the amplitude of each ofthe delta functions in equation B.37. If a amplitude of a delta function (or sidefrequency) is e.g. less then 1% of the maximum amplitude is said not to holdimportant information about the original signal, the amount of significant sidefrequencies can be calculated. The amplitude of the side frequencies is scaled by|Jn(β)|. Thus all significant frequencies have |Jn(β)| > 0.01. Figure B.7 on page 38shows the numbers of side frequencies with β values from 0.1 to 15.

36

Page 49: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX B. MODULATION

0 5 10 15−0.6

−0.4

−0.2

0

0.2

0.4

0.6

0.8

1

1.2

β

J nβ

0 order1st order2nd order3rd order

Figure B.5: Besselfunktion of 0 to 3 orders as a funtion of β

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

0

0.5

1

n

J n(1)

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

−0.2

0

0.2

0.4

n

J n(5)

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

−0.2

0

0.2

0.4

n

J n(15)

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

37

Page 50: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

B.2. FREQUENCY MODULATION December 9, 2005

0 5 10 150

5

10

15

20

25

30

35

40

β

num

(Jn(β

) >

0.0

1)

Significant side frequencies

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

38

Page 51: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX C. DOWNCONVERTER

Appendix CDownconverter

A modulated radio signal that is received through an antenna, sr(t), has two im-portant caracteristics; a carrier frequency fc and a signal bandwidth fBW. Thebandwidth is centered around the carrier frequency as illustrated in figure C.1. Inorder to restore the message signal from the modulated signal, it is conveinientto 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 to downconversion is to displace a smallspectrum FM signal so that the signal can be sampled using an AC97 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 widththe bandwidth 16 kHz, into the valid band of input frequencies of the sound cardwhich is ≈ 19.2 kHz. In the design it is assumed that the received radio channeldoes not have any neighbouring channels.

39

Page 52: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

C.2. BUILDING BLOCKS December 9, 2005

Parameter Value Units

Received signal fc 144 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 with fLO. The amplitude ofthe translated signal will be (Ac/2)sr(t). Because the phase of the mixed signalreverses whenever the received signal sr(t) crosses zero, the new spectrum has amirror image around the frequency fLO. In practice this means that whenever asignal is mixed in order to translate it in frequency, two spectras are created -each with the same bandwidth but with different carrier frequencies; the one isthe received signal shifted downwards and the other is the received signal shiftedupwards in frequency. This is sketched in figure C.2 and shown mathemathicallyin 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.

40

Page 53: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX C. DOWNCONVERTER

A mixer has 3 terminals; RF (Radio Frequency), LO (Local Oscillator) and IF (In-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. To

41

Page 54: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

C.4. MATHEMATICAL ANALYSIS December 9, 2005

interface correctly with the sound card described in appendix A, the filter shouldbe followed by an automatic gain control (AGC).

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:

Ac cos[

ωc · t + β sin(ωct)]

(C.3)

At any give time the signal can be described as:

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

This signal is then multiplied with a cosine in a circuit know as a product mixerthis yields:

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

By means of Euler this is:

1

2A1A2 · (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. After the filter only the difference signal will be left, as the filterwill attenuate the sum signal. Next the new signal is again mixed with a cosine atfrequency ω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 with equation (C.4) this yields:

Ac · A2 · A3

4· cos

[

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

(C.13)

42

Page 55: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX C. DOWNCONVERTER

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 regarding to the needed frequency ranges. The types used are mentioned intable 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.

As the filter following the first mixer the component mentioned in table C.3 isused. Since the attenuation in the stop band is not specified by the manufacturerit might not be sufficient.

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.

To filter the output from the second mixer a bandpassfilter is needed. As centerfrequency 9 kHz is chosen because it is the carrier frequency of the downconvertedsignal. The bandwidth should be 16 kHz and at the nyquist frequency, 24 kHz,the amplitude should be damped 40 dB. The design of the filter is described inappendix D.

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.

In the test the filter mentioned in table C.4 is used in stead of the analog filterdescribed in appendix D. The filters has an attenuation of less than 1 dB in thepass band and more than 40 dB in the stop band.

43

Page 56: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

C.6. MEASUREMENTS OF DOWNCONVERTER December 9, 2005

Manufacturer Model No. Type Passband Stop band Units

Mini-Circuits SLP-1.9 LP DC - 1.9 4.7 - 200 MHz

Table C.4: Specifications of lowpass filter.

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-nr

SG1 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.

44

Page 57: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX C. DOWNCONVERTER

C.6.2 Results

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

Carrier frequency Output frequency Output level Time base Input attenuator

144.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 · log( 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 · log( 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( X

10 ) · 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.

45

Page 58: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Appendix DInput-filter

Before converting the analog signal from the downconverter to a digital signal inthe soundcard of the computer, an antialiasing filter is needed. Implemented in thesound card is an antialisering filter. In this appendix the requirements for the filteris listet, and afterwards thise are compared with the specifications for the soundcard filter. If the sound card filter does not meet the requirements an external filteris made.

D.1 Filter-specifications

In this section the specifications for the filter are listed and afterwards comparedwith the specifications for the soundcard filter.

In appendix C and C.6 the signal from the downconverter is described andverified. From these appendices the signal is known to have the specificationsshown in table D.1.

Frequency

fBW 16 kHzfcenter 9 kHzfmin 1 kHzfmax 17 kHz

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

Because the soundcard samples with 48 kHz [Intel Corporation] the antialiasingfilter needs to attenuate all frequencies above 24 kHz to avoid aliasing. Similarly itis necessary to filter out frequencies below 1 kHz, because these frequencies do notcontain information and will only be interpret as noise.

How much the filter needs to damp frequencies over 24 kHz is determined byhow much the signal to noise ration (SNR) is needed in the system. It is thereforechosen that the filter must attenuate 40 dB at 24 kHz.

Implemented in the soundcard of the computer is an antialiasing filter whichhas the specifications shown in table D.2.

46

Page 59: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX D. INPUT-FILTER

Min Max Units

Analog frequency response 20 20000 HzTransition band 19200 28800 HzStop band rejection -74 - dB

Table D.2: Specifications for the antialiasering filter in the soundcard. [IntelCorporation]

Because the standard for the soundcard [Intel Corporation] does not specifywhich filter is used, it is not possible to determine if the filter in the soundcard meetsthe requirement of 40 dB attenuation at 24 kHz, only that the filter attenuates 74dB at 28.8 kHz.

By the comperison it is clear that the sound card filter does not meet the re-quirements and an external filter is therefore necessary. The external filter mustattenuate frequencies under 1 kHz because the soundcard filter has an analog fre-quency response down to 20 Hz. It is therefore chosen to build a band pass filter,with cut-off frequencies at 1 kHz and 17 kHz according to table D.1.

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.

• Denormailze 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 is given as

47

Page 60: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

D.2. FILTER-DESIGN December 9, 2005

ωn =1√

mnRC(D.2)

1

Q= (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 = R103

R101[·]

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

Choosing m sow that

m ≤ 1

4Q2(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 =

√1

1.414= 0.707 (D.7)

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

m ≤ 1

4 · 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)

48

Page 61: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX D. INPUT-FILTER

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)

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)

1

Q=

m + 1√mn

(D.22)

where:m = C103

C101[·]

n = R104

R102[·]

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

49

Page 62: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

D.2. FILTER-DESIGN December 9, 2005

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)

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 filter gives the band pass filter shown infigure D.1.

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.

50

Page 63: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX D. INPUT-FILTER

C104R104C103Vin VoutR102 C102

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

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

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 8 · 104 Hz.

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.

102

103

104

105

−40

−35

−30

−25

−20

−15

−10

−5

Frequency response of input filter

dB

Frequency

Figure D.2: Simulation of the bandpass filter.

This shows that the filter design works as desired. The final filter test will be

51

Page 64: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

D.3. FILTER-SIMULATION December 9, 2005

made as a part of the system test.

52

Page 65: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX E. MULTITHREADING

Appendix EMultithreading

This chapter generally describes the concept of multithreading, and later introducesthe ”standard” posix threading library, and the library used in this project: theGNU Pth library.

E.1 General multithreading

Multithreading gives the programmer the possibility of splitting program executioninto multiple ”threads”, or multiple sub-programs. One sub-program (henceforththread) could handle polling of input. The main program could continue executing,while the polling-thread wakes up periodically and polls the input source. Thisgives a better code structure, and possibly a better utilisation than conventionalapproaches to polling via while-loops and the likes.

E.1.1 Multithreading pros

One attribute of multithreading is the possibility of parallel running tasks. Es-pecially with the advent of multicore processors, which are able to supply “true”parallelism. Logically, a processor can only do one calculation at a time, whichcauses the case of “pseudo-parallelism”, wherein a single processor switches threadaccording to its orders. But only one thread is actually running at a single time.With multiple processors it is actually possible to run several tasks at once. But aprogram must be written with multithreading in mind, if it is to take advantage ofmultiple processors.

Multithreading grants the programmer improved control of which task is run when,and for how long. This is important in realtime applications, where the “realtimetask” can be granted more or less cpu-cycles, at the cost of degrading performanceof other tasks in the program (the user interface, for instance).

E.1.2 Multithreading cons

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

53

Page 66: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

E.2. SELECTION OF THREADING API December 9, 2005

1. Preemptivity

2. Data access

Preemptivity is the mechanism the processor uses to switch thread. Generallythere is two types, voluntarily switching (non-preemptive) and forced switching(preemptive). In preemptive mode, a scheduler controls the amount of cpu-cyclesgranted a thread, and when the thread has used its cpu cycles, it is stopped andanother thread is resumed. 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 a yieldfunction, which causes the scheduler to assume control and then decides whichthread to activate next. This gives more control to the programmer, which 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 harddiske 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, is the Posix threadsand GNU Pth. Posix threads is the inbuilt thread mechanism in linux, and inter-faces directly with the kernel. The GNU Pth is a ”lightweight” threading librarywhich does userspace threading control. In short, the Posix threads uses the kernelfor for thread switching and Pth uses its own scheduler.

This imposes a significant difference between the libraries, namely the Posixlibrary being preemptive and the Pth library being non-preemptive.

The choosen 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 easing the task of management and implementation. Being non-preemptiveand userspace controlled, the GNU Pth library cannot benefit from multiple pro-cessors. This is drawback, but not of great importance to this project, as multipro-cessor machines is still uncommon in the pool of household PCs. Another drawback

54

Page 67: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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. Homepage and manual for GNU Pth can be found at [Engelschall,2005].

The documentation and ease of use is the main reasons for the choice of GNUPth.

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 lies in the GNU Pth inbuilt scheduler. The mech-anism is shown in figure E.1. The ready-queue contains threads that wishes to usethe cpu. Each thread has a priority, with the highest priority being picked first.The picked thread is placed in the running queue, and all the remaining threads inthe ready queue has 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 asingle queue, 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.

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

55

Page 68: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

E.3. GNU PTH GENERAL USAGE December 9, 2005

from another thread.The new and dead queues are used for newly created threads, and threads which

are 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 mutex works like a lock, before a thread enters a critical section in an programit acquires the lock. A critical section is a part of the program that must only beaccessed by one thread at a time. The thread now own the lock and can enterthe critical section. Any other threads trying to access the critical section will beunsuccessful, because they can not acquire the lock. These threads are suspendedand placed in a queue before the lock.

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 lock isimportant to ensure fast execution of the code and to avoid deadlocks. Criticalsection that have long execution time should be locked before section with lowerexecution time or more heavily loaded sections.

Imagine the process of writing a file to a printer. If the mutex is first put onthe file and when trying to put a mutex on the printer, someone else is using theprinter. It’s not possible to print before the owner unlocks the printer. This resultin the file being lock until the printer is unlocked, which may be a long time dueto the slow nature of printing. FiXme: Find a better example.

Deadlocks can occur if e.g. thread A locks section A and then thread B lockssection B. Thread A now want to lock section B, but cant beacuse thread B ownsthe lock, thus thread A is suspended. Thread B now wants to lock section A, butcant because thread A owns the lock, thus thread B is suspended. The result isthat both threads waits upon each other to unlock the sections and the threadsare in deadlock. The solution for this problem is to decide on the order in whichthe sections are locked. Had both thread A and B tried to lock section A first,then thread B would be suspended trying to lock section A and the deadlock wouldnever have occurred.

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 is used as a means of synchronize program execution. Threads can beinstructed to wait or emit a specific event. Events can take many forms, the oneused 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005APPENDIX F. ADVANCED LINUX SOUND ARCHITECTURE

Appendix FAdvanced Linux Sound

Architecture

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 loosing data. When a analogoutput signal is needed from the computer, the sampled data must be converted toa analog signal.

A continuous analog output signal requires a constant stream of data, if thesound card do not receive this data the output will fail or at least pauses will beadded 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].

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 send to thesound card (output). During output ALSA will tranfer data from the output bufferto the sound card, and during input ALSA will tranfer data from the sound cardto the input buffer. ALSA have implemented three different ways of controlling thedata flow between a user application and these buffers.

F.1.1 Standard I/O transfers

A transfer method based on the UNIX read() and write() functions. Attempts toread or write a specified amount of bytes from a file descriptor (often a buffer) intothe input or output buffer. If successful the number of transfered bytes is returned.

57

Page 70: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

F.2. DATA STRUCTURE December 9, 2005

If zero is returned the file descriptor have reached End Of File. If there is notenough space in the buffer to transfer all the specified data, the buffer will be filledand the bytes actually transfered will be returned. There are two different modesin which the function can be used; blocked and non-blocked. In blocked mode theread() or write() function halts until there are enough data or space in the input oroutput buffer buffer to complete the call with the specified amount of byte transfers.Using non-blocking the functions wouldn’t halt, but return -EAGAIN error code.

F.1.2 Event waiting routines

A transfer method based on the UNIX poll() and select() functions. The methodwaits for a event in the input or output buffer (change of status). When the inputor output buffer buffer is ready for data transfer a standard I/O transfer is used totransfer data to or from the buffer. The poll() and select() blocks when it waits fora event.

F.1.3 Asynchronous notification

A transfer method based on the UNIX signal() function. During capture or playbackthe input or output buffer is either being filled with data or drained from data,once the input or output buffer have reached a threshold level the sound card willgenerate an interrupt. The interrupt is serviced with a user programmable callbackfunction, which insures data is moved to or from 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

Interleaved

First frame

Second sample

Channel 2

Higher byte Lower byteLower byte

Figure F.1: Structure of the interleaved and non-interlaaved buffer structure usedin ALSA.

The figure illustrate a two channel signal sampled with a bit resolution of 16bit (2 bytes). The samples at a given sample time for all the channels are calleda frame. Using non-interleaved each channel is stored in a separated buffer, in

58

Page 71: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005APPENDIX F. ADVANCED LINUX SOUND ARCHITECTURE

interleaved the samples are mixed together in a single buffer. A period containmultiple samples. ALSA supports are wide range of different sampling formats.

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 groups afterwhich 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. Timing and protocols of the MIDI interface onthe sound card has to be controlled manually.

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

• Mixer interface: Select 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 whichdeals with hardware and the other group deals with software settings. The twogroups are configured in the same way. A configuration space is allocated in memoryto hold any settings. After all the wanted 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 list allthe hardware settings that are used in this project.

Software settings are configured using snd pcm sw params set <Parameter>().This project only use start threshold(), which starts the playback or capture whena threshold level of data is reached in the buffer.

F.5 PCM interface

As with the control interface the PCM interface can roughly be divided into twogroups, one group the manage the stream of data to or from the sound card and

59

Page 72: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

F.5. PCM INTERFACE December 9, 2005

<Parameter> value

access() 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.

another group used to obtain status on the stream. As mentioned earlier ALSAsupport three different ways of controlling the flow of data (stream) between theuser application and the sound card, which differs on the method used to detectwhen to transfer data. The actual transfer is done in same way, using an API callspecifying what and how much data to transfer. The API call snd pcm readi() isused to read data from the input buffer and snd pcm writei() is used to write datato the output buffer. Other API calls to manage the stream are e.g. stop, start orpause which, as the name implies, stop, start or pause the playback or capture. Thisproject uses the data transfer calls and the start call snd pcm start(). The secondgroup contain calls that e.g. returns available frames for transfer, the position ofthe 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX G. IO SYSTEM

Appendix GIO system

To facilitate the FM-demodulation algorithm, a software system for managing thesoundcard input- and output is constructed. The purpose of this software is thusto continuously record audio from the soundcard, 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 previous step)

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

5. Find and describe functions (listing of functions/methods found in previousstep)

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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

G.1. ANALYSIS AND DESIGN December 9, 2005

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 algorithm isdefined 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 considering 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 regards 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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 to 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: Usecases for IO system.

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 the next page.

63

Page 76: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

G.1. ANALYSIS AND DESIGN December 9, 2005

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 usecase

Name Activity Grouping

fifoGetData() 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

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 soundcard buffer toFIFO1. 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”.

64

Page 77: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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 usecase

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 with associatedcomponent diagram in figure G.5 on the following page.

Functions Group Description

fifoGetData(), 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 IO system

G.2 Implementation

The implementation description is based on figure G.6 on page 67. 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.

65

Page 78: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

G.2. IMPLEMENTATION December 9, 2005

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 IO system package.

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.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. The

66

Page 79: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX G. IO SYSTEM

Processdata

Setupinput

Setupoutput

FIFO1 FIFO2

inThread ouThread

prT

hrea

d

inC

alle

d

ouC

alle

d

alsa

Get

Dat

a

alsa

PutD

ata

main

main

start

exit

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

functions 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

Parameters for hardware access and capture/playback are set in structure thread-Params in the main() function, by means of the configThreadParams() from thread-Params.h/c, and from manual manipulation of the structure. A threadParamsstruct is passed by reference to each input and output thread, which then can relyon 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.

67

Page 80: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

G.2. IMPLEMENTATION December 9, 2005

G.2.4 FIFO queue

The used FIFO queues are implemented like at standard first-in first-out queue,with the additional use of mutex’es. See section E.3.2 on page 56 for further refer-ence about mutexes. All 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 datais available. The external application will thus ”halt” until data is placed in theFIFO-queue.

68

Page 81: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX H. SALLEN AND KEY FILTER

Appendix HSallen and Key filter

In this appendix a method for filter implemantation using a Sallen and Key filteris described. This is done in order to use the realization method of the Sallen andKey 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)=

KR1R3C2C4

s2 + s( 1R3C4

+ 1R1C2

+ 1R3C2

− KR3C4

) + 1R1R3C2C4

(H.1)

where:K is the gain factor [gg]

Comparing equation H.1 with the general form of the second order low pass fil-ter

69

Page 82: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

H.1. LOW PASS SALLEN AND KEY FILTER REALIZATIONDecember 9, 2005

V2(s)

V1(s)=

H0ω2n

s2 + (ωn

Q )s + ω2n

(H.2)

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)

1

Q=

R3C4

R1C2+

R1C4

R3C2+ (1 − K) ·

R1C2

R3C4(H.4)

H0 = K (H.5)

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

In order to have a gain of 0 dB in the filter, K is defined to be 1. The parametersn 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)=

1mnR2C2

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)

1

Q= (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 ≤ 1

4Q2(H.9)

70

Page 83: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX H. SALLEN AND KEY FILTER

Then n can be calculated from

n =( 1

2mQ2− 1

)

± 1

2mQ2

1 − 4mQ2 (H.10)

This equation provides two values of n. The values are often reciprocal and bothvalues can therefore be used.

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)=

s2K

s2 + s( 1R2C1

+ 1R4C3

+ 1R4C1

− KR2C1

) + 1R2R4C1C3

(H.11)

where:K is the gain factor [gg]

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

V2(s)

V1(s)=

H0s2

s2 + ωn

Q s + ω2n

(H.12)

the following equations can be obtained

ωn =1√

R2R4C1C3

(H.13)

1

Q=

R4C3

R2C1+

R2C1

R4C1+

R2C3

R4C1− K

R4C3

R2C1(H.14)

H0 = K (H.15)

Similar to the low pass function, some definitions must be made in order to find aunique solution. Defining K = 1, to have a gain of 0 dB, and two parameters n

71

Page 84: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

H.2. HIGH PASS SALLEN AND KEY FILTER REALIZATIONDecember 9, 2005

and m to be

m =C3

C1

n =R4

R2

(H.16)

and

C = C1

R = R2

With these difinitions 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)

1

Q=

m + 1√mn

(H.19)

In order to simplify the design formulas m is saidto 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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 do to its dynamic limiting nature.

I.1 Theory of operation

A 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 Approx. 100 mV over a 50 dBinput range. The chip require only a few external components, these will determinethe attack and decay time for the AGC. Internally there are two amplifires, aninput amp and an output amp. The output amp feeds the signal to a detectioncircuit which produces a DC voltages that controls the gain of the input stage.

To be able to adjust input level of the AGC circuit an opamp is added to theinput of the VOGAD. The configuration is the inverting amplifier, because thenthe 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

I.2. DESIGN December 9, 2005

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 is chosen to 470 nF and 470 pF. This is done so that the fre-quency range is passe with a minimum of phase distortion.

Since there are no demands to the response time of the AGC circuit the appli-cation note is followed witch regards to the values of the response time dependentcomponents.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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005APPENDIX 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 of the transmitter should be 200 mW.

J.1 Method

The test setup is shown i figure J.1.

Figure J.1: Test setup for signal strength measurement.

Symbol Type Model Manufacturer AAU-nr

TX1 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.

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.

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.

75

Page 88: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

J.2. RESULTS December 9, 2005

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 that the total voltage loss through the converter isapprox. 6 dB the input voltage is 1.4 - 8.5 mV. This is equal to and average of -33dBm.

J.3 Conclusion

The test shows that the input level is approx. -33 dBm which the level used in thetest of the converter.

76

Page 89: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX K. TEST OF ALGORITHM

Appendix KTest of demodulation algorithm

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

1. Evaluation of the signal to distortion ratio between 300 Hz and 3 kHz in 500logarithmic steps.

2. Signal to distortion ratio ratio with induced noise.

3. DFT analysis of a 1 kHz demodulated signal.

4. Listening test.

5. Complexity of the demodulation algorithm.

The signal to noise ratio test, the robustness of the algorithm and the DFTanalysis test will be implemented as automated tests in a MATLABTM script file.

K.1 Principle

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

K.1.1 Signal to distortion ratio

The signal to distortion ratio is a measure of the signal strength relative to thenoise, defined as

S/ND = 20 · log10

(

VS

VN

)

(K.1)

where:S/ND is the signal to noise ratio. [dB]VS is the RMS value of the signal amplitude with noise. [V]VN is the RMS value of the noise. [V]

77

Page 90: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

K.1. PRINCIPLE December 9, 2005

A set of test signals are created MATLABTM with frequencies from 300 Hz to3 kHz in 500 logarithmic steps. The 500 test signals are frequency modulated usingthe MATLABTM command fmmod(), with a frequency deviation of 5 kHz. Themodulated test signals are then demodulated using the demodulation algorithmunder test. The signal to distortion ratio are then calculated for each of the 500test signal and the ratio are plotted in MATLABTM. Figure K.1 illustrate how thetest is implemented in MATLABTM.

Figure K.1: Implemention of the signal to distortion test.

The demodulated signal will contain some distortion from the modulation anddemodulation process. Figure K.2 illustrate a way to calculate the signal to signalto distortion 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 is obtained (S). The SND and S signalis subtracted and the distortion signal is obtained (ND). The RMS of the S andND are calculated. The signal to distortion ratio is then calculated using equation(K.1). Since the distortion introduced by the modulation algorithm in MATLABTM

is the same for all the tests, it’s possible to evaluate the distortion introduced bythe demodulation algorithms.

The only nontrivial part in the calculation of the signal to distortion ratio isthe filter. The passband must be small and the attenuation outside the passbandmust be high in order to separate the signal from the distortion. Some distortionin frequencies near the signal frequency may be left in the filtered signal, whichmay cause a higher signal to distortion ratio. The effect of this will be minimizedusing a high order filter and a small bassband. If the bandpass filter doesn’t haveunity gain in the passband the signal will be calculated wrong. It’s also importantthat the filtered signal isn’t phase shifted, when substracting it from the unfilteredsignal.

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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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 choosen as a compromise between width of the mainlobe and the peak amplitude of the side lobes. The order of the filter is choosento be 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 thesignal to distortion evaluation of the 1 kHz test signal.

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−1000

−500

0

500

Normalized frequency [x pi rad/sample]

Pha

se [d

egre

es]

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1−150

−100

−50

0

Normalized frequency [x pi rad/sample]

Mag

nitu

de [d

B]

Figure K.3: 1000 order hamming window FIR frequency responce.

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

K.1.2 Signal to distortion ratio with induced noise

The robustness of the demodulation algorithms is tested by adding noise to themodulated signal and then calculating the signal to noise ratio of the demodulatedsignal, as in the previous test. Figure K.4 on the next page illustrate how the testis implemented in MATLABTM.

The noise is generated using the MATLABTM command randn(), which generaterandom numbers with mean zero and variance and deviation of one. Using therandom generator a noise signal is generated with the same length as the testsignal. The noise signal is filtered in a 4th order bufferworth filter made with

79

Page 92: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

K.1. PRINCIPLE December 9, 2005

Figure K.4: Implemention of the signal to noise test, where noise has been addedbefore demodulating.

the MATLABTM command butter(). The filter match the input filter designed inappendix D on page 46. The noise signal is scaled to be -26 dB (-26 dB ≈ 6%)maximum amplitude compared to the maximum amplitude of the modulated signal.The percentage level of added noise 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 knN (K.2)

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

80

Page 93: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX K. TEST OF ALGORITHM

A window g[n] is applied to x[n] in the time domain, the resulting discrete sig-nal can be calculated

v[n] = x[n] · g[n] (K.3)

There are many different types of windows, the rectangular window can be describedas follows

g[n] =

(

1, 0 ≥ n ≥ L

0, else

)

(K.4)

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

The best frequency resolution is achieved by using a large window. The DFTwill be implemented using the fft(x,N)() command in MATLABTM, this is a speedoptimized version of the DFT. Passing the entire signal x[n] to the fft() functionis the equivalent 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.

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, track 4, 5] and bandpassed filtered with cut-off frequencies of 300 Hz and3000 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 orginal sound clip on the same audiosystem (computer,software player, sound card and headphones). Thereafter the sound clips is sortedafter what sounds best. The test persons are not allowed to know which algorithmis which. 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 members of the group.

K.2 Verification of test algorithms

The signal to distortion evaluation algorithm is tested by utilizing it on:

81

Page 94: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

K.2. VERIFICATION OF TEST ALGORITHMS December 9, 2005

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

2. A pure sine wave with a frequency of 2000 Hz where the expected frequencyis 1000 Hz. The result should be a low signal/noise ratio.

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 0 dB.

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 signal to distortion ratio test can be seen in table K.2.0.1

Test 1 635.5 dBTest 2 -493.6 dBTest 3 -0.091 dB

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

100

101

102

103

104

0

500

1000

1500

2000

2500

Frequency [Hz]

Am

plitu

de

Frequency spectrum

Figure K.6: FFT analysis of 1 kHz sine tone

K.2.0.2 Discussion

The result from the signal distortion ratio is the same as the expected. The DFTis as expected, a large frequency component at 1 kHz and some windowing effects.

82

Page 95: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX K. TEST OF ALGORITHM

K.3 Results

The described test methods are applied to the matlab implemented demodulationsalgorithms.

K.3.1 Signal to noise

The signal to noise ratio is calculated for all the demodulation algorithms. Fig-ure K.7 shows the result of the calculations. Over the tested frequency range the

103

10

20

30

40

50

60

70

80

f [Hz]

S/N

[dB

]

Signal−noise ratio

MatlabZero−CrossZero−Cross2SlopeQuadQuadAtanQuadDiff

Figure K.7: Comparison of signal to distortion ratio.

algorithms preform differently. The demodulation done by MATLABTM is the bestbelow 1 kHz, above 1 kHz the QuadDelay algorithm is the best. The QuadDelay,QuadAtan and QuadDiff generates some 3rd order harmonic frequencies, which isattenuated for frequencies above 1 kHz in the bandpass filter. The attenuation ofthe 3rd order harmonic frequencies clearly shows as an improved S/N ratio above 1kHz. The low frequency roll-off is due to a high-pass filter with a cut-off frequencyof 300 Hz.

K.3.2 Signal to distortion ratio with induced noise

The signal to distortion ratio is calculated, this time with added noise to the mod-ulated signal. The resulting signal to noise ratio can be seen on figure K.8 on thefollowing page. The QuadAtan algorithm is more robust than the other algorithms,as it’s signal to distortion ratio only decrease a little with the added noise. TheQuadAtan algorithm gives the best ratio over the entire frequency range.

K.3.3 DFT analysis

The result of the DFT analysis can be seen on figure K.9 on the next page. The

83

Page 96: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

K.3. RESULTS December 9, 2005

103

5

10

15

20

25

30

35

40

45

f [Hz]

S/N

[dB

]Signal−noise ratio

MatlabZero−CrossZero−Cross2SlopeQuadQuadAtanQuadDiff

Figure K.8: Signal to distortion ratio with induced noise.

102

103

104

0

0.1

0.2ZeroCross 1

102

103

104

0

0.1

0.2ZeroCross 2

102

103

104

0

0.1

0.2Slope Detection

102

103

104

0

0.1

0.2Quad

102

103

104

0

0.1

0.2QuadAtan

102

103

104

0

0.1

0.2QuadDiff

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

plot is scaled to a maximum amplitude of one, but only values from (0 − 0.2) isplotted. 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 detectionalgorithm.

84

Page 97: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX K. TEST OF ALGORITHM

K.3.4 Listening test

The result of the listening test can be seen in table K.1. The listening test waspreformed 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. The slope detection

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

Table K.2: Result of the complexity test. (*) Uses functions with unknownedcomplexity

and the zero-cross is the least complex to implement and uses no functions withunknowned complexity such as cos, tan etc. The improved zero-crossing is morecomplex to implement. The most complex to implement is the Quad demodulationsalgorithms. The Quad Atan uses an atan function and the MATLABTM unwrap()both set to a complexity of 1.

K.4 Conclusion

The Quad Atan demodulation algorithm have the best signal to noise ratio overthe entire frequency range both with and without induced noise to the modulatedsignal. The Quad Atan have a much better signal to distortion ratio when noise ininduced than the Quad Delay algorithm. The Quad Atan and Quad Delay scoredbest in the listening test. The Quad Atan have been chosen over the Quad Delay,because it offers a much better signal to distortion when noise is induced. Thedisadvantage of using the Quad Atan is that it’s the most complex to implement.

85

Page 98: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

K.5. PRINCIPLE December 9, 2005

K.5 Principle

86

Page 99: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX L. ZERO CROSS DETECTION

Appendix LZero cross Detection

The baseband signal is contained in the frequency of the FM modulated signal, soany amplitude information can be removed without loosing any information aboutthe baseband signal. The zero cross detection demodulation algorithm [Carlson,1986, p. 262-263] utilizes the 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 a constant.

L.1 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 an zero-crossing occurs.The generated pulses are then passed though a low pass filter and finally the signalis DC-blocked.

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

87

Page 100: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

L.1. BASIC ZERO CROSS DETECTION December 9, 2005

L.1.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. The output of thepulse generator is a pulse train v(t). If the pulse train is viewed over a short periodT seconds, 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 maxium amplitude of 1.

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

1

T

∫ 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 illustrates the zero-cross demodulation process.

0.02 0.0205 0.021 0.0215 0.022−1

0

1Base band signal

0.02 0.0205 0.021 0.0215 0.022

−0.50

0.51

Modulated signal

0.02 0.0205 0.021 0.0215 0.0220

0.5

1

Zero−cross detection

0.02 0.0205 0.021 0.0215 0.0220

0.5

1

Pulse generator

0.02 0.0205 0.021 0.0215 0.022−0.05

00.05

time [s]

Demodulated signal

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

88

Page 101: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX L. ZERO CROSS DETECTION

L.1.2 Digitization considerations

A method of detecting zero-crossing in discrete signals, is to compare the sign ofthe sample with sign of the previous sample. The problem with detecting thezero-crossing in an 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 is replaced by a bandpass filter, which has the effect of integration, butalso removes any low-frequency noise.

L.1.3 MATLABTM implementation

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

L.1.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

• a bandpass filter

L.2 Zero cross detection with frequency estima-tion

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.2.1 Mathematic 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).The states at different points of the demodualtion algorithms can be seen in fig-ure L.3 on the following page.

89

Page 102: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

L.2. ZERO CROSS DETECTION WITH FREQUENCY ESTIMATIONDecember 9, 2005

0.02 0.0205 0.021 0.0215 0.022−1

−0.5

0

0.5

1Message signal

0.02 0.0205 0.021 0.0215 0.022

−0.5

0

0.5

1FM−modulated message signal

0.02 0.0205 0.021 0.0215 0.022

−0.5

0

0.5

1Unfiltered MZCDDA demodulated message signal

0.02 0.0205 0.021 0.0215 0.022

−0.5

0

0.5

1Filtered MZCDDA demodulated message signal

time [s]

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

The output of this algorithm can be seen in figure L.3. The message signalsis first FM-modulated, then the instantaneous frequency deviation is calculatedfor each sample using equation (L.6). The sample value is set to f∆. This waythe sample values between two upwards zero crossings equals the instantaneousfrequency deviation. The resulting signal is a approxmation of the message signal.DC-blocking the output will nullify the influence from a unprecice carrier frequency.

L.2.1.1 Improvement of the algorithm

Using equation (L.6) yields some advantages. This algorithm can be improvementby 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 transition result 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 facing 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/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 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 on the next page.

L.2.2 Digitization considerations

A method of detecting zero-crossing in discreet 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.

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:

• for

• division

• multiplication

• a bandpass filter

91

Page 104: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

L.3. CONCLUSION December 9, 2005

0.02 0.0205 0.021 0.0215 0.022−1

−0.5

0

0.5

1Message signal

0.02 0.0205 0.021 0.0215 0.022

−0.5

0

0.5

1FM−modulated message signal

0.02 0.0205 0.021 0.0215 0.022

−0.5

0

0.5

1Unfiltered MZCDDA demodulated message signal

0.02 0.0205 0.021 0.0215 0.022−1

−0.5

0

0.5

1Filtered MZCDDA demodulated message signal

time [s]

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

L.3 Conclusion

The zero cross detection and the zero cross detection with frequency estimation candemodulate the signal, and are trivial to implement in both MATLABTM and C.

92

Page 105: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX M. M-ORDER FIR BANDPASS FILTER

Appendix MM-order FIR bandpass filter

The purpose of this appendix is to make an algorithm that implements a M FIRbandpass filter. The algorithm will be made in MATLABTM and later implementedin C.

M.1 Principle

The FIR filter in this appendix is designed using windowing. The method is tomake an ideal filter in the frequency domain, and then translate it into the discretetime domain. However this will give an infinite impulsresponse. To compensatefor this a window function is multiplied onto the ideal impulseresponse. In this ap-pendix a rectangular window is chosen. This is done for simplicity as the windowamplitude is either 1 or 0 depending on the order of the filter. In FIR design theorder for the filer is denoted M and it determines the length of the window. Thetype of FIR used here utilizes linear phase i.e. constant group delay.

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

FiXme Note: ncmh04: add placement of fc to figure, noted by jtkr04 .

M.2 Mathematical description

Type I FIR-filter design by windowing utilizes the ideal form of figure M.2 on thefollowing 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)

Corresponding to the discrete-time notation of

h[n] = hd[n] · w[n] (M.2)

93

Page 106: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

M.2. MATHEMATICAL DESCRIPTION December 9, 2005

102

103

104

−70

−60

−50

−40

−30

−20

−10

0

Frequency [Hz]

Am

plitu

de [d

B]

Figure M.1: 20 order FIR bandpass filter

f

|H(ejω)|

BW BW

fc−fc

Figure M.2: Ideal bandpass filter

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ω) =1

∫ π

−π

Hd(ejω) · W (ejω−φ)dφ (M.4)

Utilising 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 setto 1, the equation of

Hd(ejω) =

e−jω M

2

for − ωc − ωb < ω < −ωc + ωbforωc − ωb < ω < ωc + ωb

0 Otherwise(M.5)

can be written.

94

Page 107: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX M. M-ORDER FIR BANDPASS FILTER

Transforming Hd(ejω) to the time domain yields (by use of euler rewriting)

hd[n] =1

∫ π

−π

Hd(ejω)ejωndω (M.6)

=1

−ωc+ωb

−ωc−ωb

e−jω M

2 ejωndω +1

∫ ωc+ωb

ωc−ωb

e−jω M

2 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 thepreceding 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 doesen’t have any particular implementation considerations. Except thataccording to [Oppenheim & Schafer, 1998, page 386] at least 14 bit must by use forfiler coefficients.

M.4 MATLABTMimplementation

The MATLAB implementation relies on the following information to be supplied:

• the sample rate (fs), in Hz.

• the center frequency of the passband (fc), in Hz.

• the passband width (BW ), in Hz.

95

Page 108: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

M.5. C IMPLEMENTATION CONSIDERATIONS December 9, 2005

• 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

Please note that the first M samples are using samples before t = 0 as zeros.Tested against MATLABs internal commands (FIR1), the designed filter producesthe same coefficients as MATLAB.

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 filter workings relies on float values. The solution is to use floatvalues internally, and export values rounded to integers.

As c contain no built in “length” command, the length of the supplied samplesmust be specified. Furthermore, the data to be processed is supplied in chunks.This results in problems as the filter uses M samples from the past. When crossingthe boundary between chunks this must be addressed.

M.6 Conclusion

In this appendix an M order FIR bandpass filter have been implimented. The orderof the filter can be varied according to the demands of a given situation. Howeverthe zeroing the samples before t = 0 must handled for implementation.

96

Page 109: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

Appendix NQuadrature detection

Quadrature detection is a popular demodulation technique, which builds on theutlilization of a quadrature signal. This appendix will introduce quadrature signalsand proceed with the different ways these can be used to obtain FM demodulation.

N.1 Theory

The first of the following sections will introduce the mathematics behind quadraturesignals. The second will use the representation presented on a continous wavemodulated signal as will be the case for the purposes of the project. The referencefor this section is [Haykin, 2001, pages 723-730].

N.1.1 Quadrature representation of bandpass signals

In a communication system the signal that is physically transmitted are usually areal-valued bandpass signal, g(t) as shown in figure N.1(a). In handling bandpasssignals the pre-envelope of g(t) has shown to be particularly usefull, but one shouldremember that the pre-envelope is purely a theoretical function. The pre-envelopeof such signal 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)

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) is saidto be a Hilbert transform pair. Amplitudes are not affected at all by the Hilberttransform. The Fourier transform G(f) of g(t) is given by

G(f) = −j · sgn(f)G(f) (N.2)

97

Page 110: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.1. THEORY December 9, 2005

Knowing this the Fourier transform of the pre-envelope of g(t), G+(f) can bederived:

G+(f) = G(f) + sgn(f)G(f) (N.3)

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). Now consider a bandpass signal, g(t), centered about thefrequency ±fc and limitted to the band fc − W ≤ f ≤ fc + W . The pre-envelopeof such signal can be expressed as

g+(t) = g(t) exp(j2πfct) (N.4)

where:g+(t) is the pre-envelope of g(t)g(t) is the complex envelope of g(t)

The multiplication of the complex signal exp(j2πfct) can be considered as a com-plex frequency shift, which has the following Fourier transform property:

exp(j2πfc)g(t) G(f − fc) (N.5)

Hence the pre-envelope g+(t) is bandlimitted to the band fc−W ≤ f ≤ fc+W ,it follows that the complex envelope g(t) is limitted to the band −W ≤ 0 ≤ W ,and is therefore a lowpass signal. This is illustrated by figure N.1(c). In general,g(t) is a complex-valued lowpass quantity that may be described as

g(t) = I(t) + jQ(t) (N.6)

where:I(t) is the in-phase component of g(t)Q(t) is the quadrature component of g(t)

The above is the rectangular form of writing the complex envelope, later the polarform is introduced. The lowpass property of I(t) and Q(t) is inherited from g(t).The original bandpass signal, g(t), can be represented also by means of I(t) andQ(t):

g(t) = Re[g(t) exp(j2πfct)] (N.7)

= Re[(I(t) + jQ(t)) · (cos(j2πfct) + j sin(j2πfct))] (N.8)

= I(t) cos(j2πfct) − Q(t) sin(j2πfct) (N.9)

Note that all information content of g(t) is preserved within the I- and Q-signals.

N.1.2 Quadrature representation of continous-wave modu-lated signals

Untill now the bandbass signal g(t) has been treated as arbitrary. This section willfocus on the quadrature representation of signals that are modulated using eitherAM, PM or FM. In these cases the bandpass signal can be expressed as

g(t) = a(t) cos(2πfct + φ(t)) (N.10)

98

Page 111: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

|G(f)|

f

|G(fc)|

fc−fc

2W

(a)

|G+(f)|

ffc

|G(f)|

f

(c)

(b)

2W

2|G(fc)|

2|G(fc)|

0

0

0 W−W

Figure N.1: Illustrating spectrums of a) a received bandpass signal, (b), thepre-envelope of the bandpass signal and (c) the complex envelope of the bandpasssignal.

99

Page 112: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.2. IQ GENERATOR December 9, 2005

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 complex envelope of g(t) is written in polar form and the rectangular form(I and Q) is derived:

g(t) = a(t) exp(jφ(t)) (N.11)

= a(t) cos(φ(t)) + ja(t) sin(φ(t))) (N.12)

From the above and equation (N.6) it follows that

I(t) = a(t)cos(φ(t)) (N.13)

Q(t) = a(t)sin(φ(t)) (N.14)

Note that all 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 betweenthe two forms can course be done bothways. Note that when used in the complexenvelope a(t) is not only the envelope, but the actual amplitude. It can thereforebe calculated as the absolute length of I(t) + jQ(t). The phase of the signal issimply the angle of the same complex number:

a(t) =√

I(t)2 + Q(t)2 (N.15)

φ(t) = tan−1

(

Q(t)

I(t)

)

(N.16)

To summarize; The I- and Q-signals are both lowpass signals, and they both containboth ampltitude and phase information. Usually the signals are used to determineamplitude and phase of some received signal, i.e. g(t), and in this context both Iand Q are required to uniquely determine phase. Determination of the instantanousphase of a received signal is the key stone in quadrature FM detection, which willbe described in the following sections.

N.2 IQ generator

In this section the principle for obtaining the I- and Q-signals is described. Re-calling from section N.1 that the I- and Q-signals for an FM siganl where a(t) isconstant is defined as

I(t) = A cos(φ(t)) (N.17)

Q(t) = A sin(φ(t)) (N.18)

These are the signals that is to be derived from the FM signal.In figure N.2 the principle for making the I- and Q-signals is shown. As seen in

the figure, the I- and Q-signals is made by multiplying the FM-signal with 2cos(ωct)or -2sin(ωct), and afterwards low pass filtering the signal. How this gives the I-and Q-signals is shown by the following mathematical description.

100

Page 113: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

Q-signal

I-signal

FM-signal

Low Pass

Low pass2sin(! t)2 os(! t)

Figure N.2: A block diagram for making the I- and Q-signals

N.2.1 Mathematical description of the I- and Q-signals

Because the calculations of the I- and Q-signals is 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

h(t) = g(t) · 2 cos(ωct) (N.19)

From appendix B.2, it is known that an FM signal can be described as

g(t) = A cos(ωct + φ(t)) (N.20)

Substituting the expression for g(t) into equation N.19 the signal after the mixercan be described as

h(t) = A cos(ωct + φ(t)) · 2 cos(ωct) (N.21)

h(t) = A cos(φ(t)) + A cos(2ωct + φ(t)) (N.22)

(N.23)

The desired I-signal is the part of the g(t) signal centret around zero. In orderto obtain this signal, the g(t) signal is low pass filter, which gives the I-signal

I(t) = A cos(φ(t)) (N.24)

This shows that the I- and Q-signal can be derived from the FM signal by usingthe above described methode in an ideal situation. Often this will not be the casebecause the carrier frequency will often have a frequency offset ωo, and a phaseoffset φo, with respect to the internal oscillator. This gives the following FM-signal

101

Page 114: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.2. IQ GENERATOR December 9, 2005

g(t) = A cos(ωct + ωot + φ(t) + φo) (N.25)

It can be shown that a variation in the carrier frequency gives the following I- andQ-signals

I(t) = A cos(ωot + φ(t)) (N.26)

Q(t) = A sin(ωot + φ(t)) (N.27)

This means that a change in the carrier frequency results in a frequency offset ofboth the I- and Q-signals.

Similar it can be shown that a change in the phase of the signal multiplyed withthe FM signal results in the following I- and Q-signals.

I(t) = A cos(φ(t) + φo) (N.28)

Q(t) = A sin(φ(t) + φo) (N.29)

This shows that a change in the phase gives a phase offset in both the I- andQ-signals.

Now that the methode for finding the I- and Q-signals is described, an algorithmthat calculates the I- and Q-signals can be made.

N.2.2 Digitalisation considerations

Most af the calculations shown above can directly be implemented as a discreettime function. Some considerations must however be made when designing the lowpass filter. This is because different methodes can be used in design a digital filter.For further information on filter design se appendix M.

N.2.3 MATLAB implementation

The MATLAB implementation is made by follows the method described above andshown in figure N.2. This means that the carrier frequency of the FM signal needsto be known, for the algorithm to work.

A digital oscillator needs to be made in order to generate the sine and cosinesignal. In MATLAB this can easily be made by first constructing a time vector,and then using this to generate the sine and cosine signals.

Evaluation of MATLAB implementation

The MATLAB implementation is evaluatet 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.30)

Q(t) = sin(0) = 0 (N.31)

The test shows that the I- and Q-signals gives the desired values, and the algorithmis therefor assumed working.

102

Page 115: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

N.2.4 C implementation considerations

When implementing the algorithm in C the time vector used to generate the digitaloscillator is not as easy be make as in MATLAB. The reason for this is that whenworking in MATLAB the sound sample has a final length and therefor also the timevector has a final length. When working in C the length of the sound sample isnot known and the time vector can therefor not be generated in the same way. Asolution to this problem is dividing the sound samples into samples with a knownlength, and then demodulating the samples one at the 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.16).From the definition of FM modulation it is known that the time derivative of theinstantanous phase is directly proportional to the message signal. The principleblock diagram is shown in figure N.3.

Figure N.3: Block diagram of the arcus tangent demodulation method.

N.3.2 Mathematical description

The signals at hand are

I(t) = A cos(φ(t)) (N.32)

Q(t) = A sin(φ(t)) (N.33)

The proof of this method is carried out in three steps referring to the blocksabove. For the calculation of h1(t) equation (N.16) is used. For calculation of h2(t),the time derivative of the phase of an FM signal is used:

103

Page 116: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.3. ARCTAN DEMODULATOR December 9, 2005

φ(t) = 2πkf

∫ t

0

m(τ)dτ (N.34)

φ′(t) = 2πkfm(t) (N.35)

h1(t) = tan−1

(

Q(t)

I(t)

)

= φ(t) (N.36)

h2(t) =d

dt[φ(t)] (N.37)

= 2πkfm(t) (N.38)

h3(t) =1

2πkf· 2πkfm(t) = m(t) (N.39)

where m(t) is the message signal.In practice a signal received has always a frequency offset, and phase offset, as

described in section N.2.1.Carrying out a similar calculation as in the above section with the offset fre-

quencies and phase yields

h1(t) = φ(t) + ωot + φo (N.40)

h2(t) = 2πkfm(t) + ωo + 0 (N.41)

h3(t) = m(t) +ωo

2πkf(N.42)

Hence a frequency tolerance will introduce a DC offset in the demodulated messagesignal. Since the phase is differentiated, a phase offset will have no influence on thedemodulation.

N.3.3 Digitization considerations

All of the above calculations can be carried out on samples in stead of continoustime signals. The only calculation that may introduce approximation errors isthe differentiator, which can not be accurate when operating in discrete time. Adiscreet time differentiator will use the approximation

dx

dt≈ x(nTs) − x((n − 1)Ts)

Ts(N.43)

where:x(t) is a continous time signaln is an integer sample numberTs is the sample time [s]

N.3.4 MATLABTMimplementation

The arcus tangent is implemented using the function atan2 which is a four quad-rant arcus tangent. The problem with using the regular atan is that it only givesoutput in the range between −π/2 and π/2. As both I and Q can take on bothpositive and negative values, and they are divided with each other in order to usethe arcus tangent, the two expressions atan(-1/-1) and atan(1/1) would of couse

104

Page 117: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

yield the same result even though they are in opposite quadrants. The functionatan2 can handle this situation.

The function unwrap is used to correct jumps in angles that are over π. Thesejumps or discontinuities occur when calculating angles using atan2 since the out-put is always in the range between −π and π (one ’turn’), however the real signalphase increases with times and therefore takes ’more than one turn’. FiXme: notthe best explanation

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 straightfarward since the function atan2 is present inthe standard C math library. The rest should be trivial as well.

N.4 Baseband delay demodulator

The Baseband delay demodulator is an other 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.4 shows the principle for the Baseband delay demodulator. In orderZ1Z1

h5(n)

I-signal

Q-signal

h1(n)h2(n)-

+ h3(n) h4(n)sin1 K

Figure N.4: The principle for the Baseband delay demodulator.

to understand precisely how this method generates the information signal from theI- and Q-signal, an mathematical description of the method is made.

105

Page 118: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.4. BASEBAND DELAY DEMODULATOR December 9, 2005

N.4.2 Mathematical description of the Baseband delay de-modulator

The signals at hand are the I- and Q-signals discretized

I(n) = A cos(φ(n)) (N.44)

Q(n) = A sin(φ(n)) (N.45)

From the I- and Q-signals h1(n) and h2(n) is found.

h1(n) = A cos(φ(n − 1)) · A sin(φ(n)) (N.46)

h2(n) = A sin(φ(n − 1)) · A cos(φ(n)) (N.47)

By substrating h2 from h1, h3 is achieved.

h3(n) = h1(n) − h2(n) (N.48)

h3(n) = A2 sin(φ(n) − φ(n − 1)) (N.49)

h3(n) ≈ A2(φ(n) − φ(n − 1)) (N.50)

The last equation of the above is an approximation that holds for (φ(n)−φ(n−1) < π/4. The following shows how the message signal is derived:

h4(n) =A2(φ(n) − φ(n − 1))

A2 · Ts · 2 · π · kf(N.51)

h4(n) =A2 · φ′(n)

A2 · 2 · π · Kf(N.52)

h4(n) =A2 · 2 · π · kf · m(n)

A2 · 2 · π · kf= m(n) (N.53)

The approximation made to eliminate the sin(..) sets a demand to the samplefrequency. In the calculation it is used that the maximum frequency deviation is5000 Hz.

φ(n) − φ(n − 1) < π/4 (N.54)

φ′(n) · Ts < π/4 (N.55)

2πkfm(t)Ts < π/4 (N.56)

2π · 5000

fs< π/4 (N.57)

fs < 40000 Hz (N.58)

This demand is met by the used sample frequency of 48000 Hz.

As described in section N.2.1 the I- and Q-signals can change do to change inthe carrier frequency or change in the phase.

106

Page 119: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

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.59)

This gives h5(n)

h4(n) =A2 · ωo

A2 · 2 · π · kf+ m(n) (N.60)

h4(n) = DC + m(n) (N.61)

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 now effect of on the messagesignal.

N.4.3 Digitalisation considerations

The methode described above can directly be implementet in discreet time. Theonly calculation that can result in an erro is the differentiaton as described in sectionN.3.3.

N.4.4 MATLAB implementation

In MATLAB the methode described above can directly be implemented by followingthe procedure shown in figure N.4.

N.4.5 C implementation considerations

Implementing the algorithm in C should be now problem because the sin−1 ispresent in the standard C math library.

N.5 Baseband differentiator demodulator

The Baseband differentiator demodulator is yet a other way to demodulate the FMsignal by use of the I- and Q-signals.

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.5 the principle for the methode is shown. As seen in the figure, theprinciple can be expressed mathematical as

m(t) =I · Q′ − I ′ · Q

K(N.62)

In order to se how this method gives the information signal m(t), a mathematicaldescribtion is made.

107

Page 120: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.5. BASEBAND DIFFERENTIATOR DEMODULATORDecember 9, 2005

I-signal

Q-signalDiff

Diff

K-

+ h2(t)h1(t)h3(t) h4(t)

Figure N.5: The principle for the Baseband differentiator demodulator.

N.5.2 Mathematical describtion of the Baseband differentia-tor demodulator

In order to find the two signals h1(t) and h2(t), the differentiated of the I- andQ-signal needs to be known

I(t) = A cos(φ(t)) (N.63)

I ′(t) = −Aφ′(t) · sin(φ(t)) (N.64)

Q(t) = A sin(φ(t)) (N.65)

Q′(t) = Aφ′(t) · cos(φ(t)) (N.66)

It is now possible to find h1(t) and h2(t)

h1(t) = I ′(t) · Q(t) (N.67)

h1(t) = −A2 · φ′(t) · sin2(φ(t)) (N.68)

and

h2(t) = Q′(t) · I(t) (N.69)

h2(t) = A2 · φ′(t) · cos2(φ(t)) (N.70)

It is now possible to find h3(t) by subtracting h1(t) from h2(t). This gives

h3(t) = h2(t) − h1(t) (N.71)

h3(t) = A2φ′(t) ·(

cos2(φ) + sin2(φ))

(N.72)

h3(t) = A2φ′(t) (N.73)

knowing that φ(t) is equal to

φ(t) = kFM

m(t)dt (N.74)

108

Page 121: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX N. QUADRATURE DETECTION

Equation N.73 can be rewritten to

h3(t) = A2 · 2 · π · kf · m(t) (N.75)

Finaly h4(t) can be derived by dividing h3(t) with 1A2

·2·π·kf

h4(t) =A2 · 2 · π · kf · m(t)

2 · π · kf · A2= m(t) (N.76)

The calculations made above is for the ideal case. As described in section N.2.1 theI- and Q-signals can change do to change in the carrier frequency or change in thephase 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.77)

This gives h4(t)

h4(t) =A2 · ωo

A2 · 2 · π · kf+ m(t) (N.78)

h4(t) = DC + m(t) (N.79)

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 now effect of on the messagesignal.

N.5.3 Digitalisation considerations

All of the calculation described above can also be made in discreet time. The onlycalculation that may introduce an approximation is the differantiation as describedin section N.3.3.

N.5.4 MATLAB implementation

The method described above can directly be implementatet in MATLAB withoutfurther considerations.

N.5.5 C implementation considerations

Like the implementations in MATLAB the implementation in C can be made with-out further considerations.

N.6 Conclusion

The three presented algorithms has 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 generation

109

Page 122: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

N.6. CONCLUSION December 9, 2005

of the quadrature signals, and the filters nescessary is of order 8. The algorithmsthemselves only have to look one sample back in time in order to demodulate.

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.Is this right?

The three algorithms have been tested briefly and the sound output is understand-able.

110

Page 123: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX O. SLOPE DETECTOR

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 113a and O.2 on page 113b.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 113c.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 113d.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)

111

Page 124: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

O.2. MATHEMATICAL DESCRIPTION December 9, 2005

|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)) =

1

2·√

ω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)

112

Page 125: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX O. SLOPE DETECTOR

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

113

Page 126: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

O.2. MATHEMATICAL DESCRIPTION December 9, 2005

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.

114

Page 127: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX O. SLOPE DETECTOR

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.

115

Page 128: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005

Appendix PAcceptance test

According to the requirement specification in chapter 2 on page 4 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 40 ms throughout the entire system.

3. A SND/ND ratio over 20 dB.

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 next page.

116

Page 129: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX P. ACCEPTANCE TEST

Type Model Manufacturer AAU-nr

Tone generator 2022D Maroni Instruments 33336Tone generator 2022D Maroni Instruments 33337Radio transmitter - - 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 anddemodulated it. The test shows that the system works correct according to therequirement.

P.2 Delay

The delay throughout the system must not exceed 40 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 radios 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 a sigle-shot triggered by the rise in signal level. When the tone button isn’t pressed thedemodulation should produce noise. Upon pressing the button, the tone should bepresent on the output of the system. The oscilloscope time base is adjusted to showboth the rise in signal level before the downconverter and the change in the outputfrom noise to signal. The test set-up is illustrated on figur P.2 on the followingpage.

The equipment used in the test is same as in the previous test plus the equitmentin table P.2.

Type Model Manufacturer AAU-nr

Oscilloscope 54671A Agilent LVNR 33866

Table P.2: Equipment used in delay evaluation.

117

Page 130: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

P.2. DELAY December 9, 2005

Figure P.2: Illustration of the test set-up used to meassure the delay in the system.

P.2.2 Results

The output from the oscilloscope can be seen in figure P.4. The delay is measuredto approximately 400 ms.

−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 the IO system.The lowermost signal has its amplitude factored down by 5, and offset by −0.5V.The delay of the system is measured from the reception of the transmitted signalto the effectuation on the output (the effectuation is shown by the lack of squelch).

P.2.3 Discussion

The requirements for total delay was that it should be lower than 40 ms. As thetotal delay is measured to 400 ms, this requirement has an error of 1000 %. Sincethe system only is a receiver, this requirement only has little significance.

118

Page 131: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 APPENDIX P. ACCEPTANCE TEST

P.3 SND/ND ratio

The SND/ND ratio must be over 20 dB.

P.3.1 Method

This will be tested by applying a modulated 1 kHz tone with a carrier frequency of145 MHz to the input of the downconverter. The output is recorded from the de-modulator and submitted to the filter from the Signal to Noise Test from appendixK. This signal is substracted from the output, thus creating a signal that onlycontains the noise and the distortion. These signals are then inserted in equation(P.1).

SND/ND =Signal + Noise + Distortion

Noise + Distortion(P.1)

Figure P.4: SND/ND ratio calculation principle.

The test set-up is illustrated on figur P.5.

Figure P.5: Illustration of the test set-up used to test the demodulation.

The equipment used 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 SND/ND ratio of 28.02 dB.

P.3.3 Discussion

This result is within the requirements of system. The loss of approximately 10 dBSND/ND compared to the MATLABTM simulation is also to be expected, due tothe added noise from the downconversion, AGC and analog to digital conversion.

119

Page 132: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

P.4. CONCLUSION December 9, 2005

Type Model Manufacturer AAU-nr

Tone 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 SND/ND test.

P.4 Conclusion

The acceptance test has shown that the system works, in regard to the listeningtest and the SND/ND ratio. However, the delay is 1000 % higher than specified inthe requirement specification.

120

Page 133: PC FM-radio receiver - Aalborg Universitetkom.aau.dk/group/05gr506/051213/report.pdf · 2005-12-09 · PC FM-radio receiver 5th semester project, AAU, Elektronik og elektroteknik

December 9, 2005 LIST OF CORRECTIONS

List of Corrections

FiXme: jtkr04: fjern dato maerker fra toppen af haedere (er paa beggesider)! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1

FiXme: Find p grunde til at vi kan lide linu . . . . . . . . . . . . . . . . . 9FiXme Note: jtkr04: add reference from here to each section in the ap-

pendixes (and change that bloody title) . . . . . . . . . . . . . . . . 12FiXme Note: cste04: ... goer noget... skriv hvorfor vi udsaetter det . . . . 14FiXme Note: ghoe04: find source that describes amount of output bits

(AC97?) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14FiXme Note: jtkr04: find better description of this . . . . . . . . . . . . . 22FiXme: Find a better example . . . . . . . . . . . . . . . . . . . . . . . . . 56FiXme Note: ncmh04: add placement of fc to figure, noted by jtkr04 . . . 93FiXme: not the best explanation . . . . . . . . . . . . . . . . . . . . . . . 105

121