kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · elektronik og elektroteknik fredrik bajers...

102
FM radio receiver P5 projekt, AAU, Elektronik og elektroteknik Gruppe 415 Carsten Jes Toft Kristensen Gustav Kingo Onkel Boye NC

Upload: others

Post on 19-Mar-2020

2 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

FM radio receiver

P5 projekt, AAU,Elektronik og elektroteknik

Gruppe 415Carsten

Jes Toft KristensenGustavKingo

Onkel BoyeNC

Page 2: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime
Page 3: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

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:CarstenJes Toft KristensenGustavKingoOnkel BoyeNC

Supervisor:Persefonis

Copies: 9

Pages: 14

Appendices: 19

Finished November 25, 2005

Synopsis:

Insert synopsis here. . . found in mainRe-

port/frontMatter/synopsis.tex

Page 4: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Contents

A Requirement specification 14A.1 General description . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

A.1.1 System description . . . . . . . . . . . . . . . . . . . . . . . . 14A.1.2 Limitations of the system . . . . . . . . . . . . . . . . . . . . 14A.1.3 Further plans for the system . . . . . . . . . . . . . . . . . . 14A.1.4 User profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14A.1.5 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

A.2 System interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15A.2.1 Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15A.2.2 Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15A.2.3 Hardware interface . . . . . . . . . . . . . . . . . . . . . . . . 15A.2.4 User Interface . . . . . . . . . . . . . . . . . . . . . . . . . . . 15

A.3 Quality factors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16A.4 Acceptance test specification . . . . . . . . . . . . . . . . . . . . . . 16

A.4.1 Test: Total delay . . . . . . . . . . . . . . . . . . . . . . . . . 16A.4.2 Test: Distortion . . . . . . . . . . . . . . . . . . . . . . . . . 16A.4.3 Test: SND/ND ratio . . . . . . . . . . . . . . . . . . . . . . . 16A.4.4 Test: UI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16

B Preanalysis 17B.1 Radio signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17B.2 Chosing a radiosignal to receive . . . . . . . . . . . . . . . . . . . . . 18B.3 Data acquisition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19

B.3.1 High frequency sampling . . . . . . . . . . . . . . . . . . . . . 19B.3.2 Analog downconversion and low frequency sampling . . . . . 19

B.4 Software demodulation . . . . . . . . . . . . . . . . . . . . . . . . . . 19B.5 System design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20

C Sound card 21

D Modulation 23D.1 Amplitude modulation . . . . . . . . . . . . . . . . . . . . . . . . . . 23D.2 Frequency modulation . . . . . . . . . . . . . . . . . . . . . . . . . . 26

4

Page 5: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

E Downconverter 32E.1 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32E.2 Building blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33

E.2.1 Mixer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33E.2.1.1 Filter . . . . . . . . . . . . . . . . . . . . . . . . . . 34

E.3 Block diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34E.4 Mathematical analysis . . . . . . . . . . . . . . . . . . . . . . . . . . 35E.5 Dimensioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36E.6 Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37E.7 Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38

F Sampling 40F.1 From continuous to discrete . . . . . . . . . . . . . . . . . . . . . . . 40F.2 Frequency attributes . . . . . . . . . . . . . . . . . . . . . . . . . . . 40

G Measurements of downconverter 45G.1 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45G.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46G.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47

H Antialiasing-filter 48H.1 Filter-specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48H.2 Filter-design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50

H.2.1 LP-filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50H.2.2 HP-filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52H.2.3 BP-filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53

H.3 Filter-simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54H.4 Filter-test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

I Multithreading 55I.1 General multithreading . . . . . . . . . . . . . . . . . . . . . . . . . 55

I.1.1 Multithreading pros . . . . . . . . . . . . . . . . . . . . . . . 55I.1.2 Multithreading cons . . . . . . . . . . . . . . . . . . . . . . . 55

I.2 Selection of threading API . . . . . . . . . . . . . . . . . . . . . . . . 56I.3 GNU Pth general usage . . . . . . . . . . . . . . . . . . . . . . . . . 57

I.3.1 Thread control . . . . . . . . . . . . . . . . . . . . . . . . . . 57I.3.2 Mutexes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58I.3.3 Events and message queues . . . . . . . . . . . . . . . . . . . 58

J Advanced Linux Sound Architecture 59J.1 Data flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59

J.1.1 Standard I/O transfers . . . . . . . . . . . . . . . . . . . . . . 59J.1.2 Event waiting routines . . . . . . . . . . . . . . . . . . . . . . 60J.1.3 Asynchronous notification . . . . . . . . . . . . . . . . . . . . 60

J.2 Data structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60J.3 Alsa API . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61J.4 Controle interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61J.5 PCM interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61

Page 6: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

K IO system 63K.1 Analysis and design . . . . . . . . . . . . . . . . . . . . . . . . . . . 64

K.1.1 Deployment analysis . . . . . . . . . . . . . . . . . . . . . . . 64K.1.2 Define user interactions . . . . . . . . . . . . . . . . . . . . . 64K.1.3 Find use-cases . . . . . . . . . . . . . . . . . . . . . . . . . . 65K.1.4 Describe use-cases . . . . . . . . . . . . . . . . . . . . . . . . 65K.1.5 Find and describe functions . . . . . . . . . . . . . . . . . . . 65K.1.6 Classify activities into stereotype objects . . . . . . . . . . . 66

K.2 Implementation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67K.2.1 Init functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 68K.2.2 Thread activities . . . . . . . . . . . . . . . . . . . . . . . . . 68K.2.3 Argument passing . . . . . . . . . . . . . . . . . . . . . . . . 69K.2.4 FIFO queue . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70

L Butterworth approximation 71L.1 Properties of |N(jω)|2 . . . . . . . . . . . . . . . . . . . . . . . . . . 71L.2 Maximally flat magnitude function . . . . . . . . . . . . . . . . . . . 72L.3 Butterworth function . . . . . . . . . . . . . . . . . . . . . . . . . . . 72L.4 Pole location of the Butterworth function . . . . . . . . . . . . . . . 73

M Sallen and Key filter 74M.1 Low pass Sallen and Key filter realization . . . . . . . . . . . . . . . 74M.2 High pass Sallen and Key filter realization . . . . . . . . . . . . . . . 76

N FM demodulation 78N.1 Frequency discrimination . . . . . . . . . . . . . . . . . . . . . . . . 79

N.1.1 Slope detection . . . . . . . . . . . . . . . . . . . . . . . . . . 80N.1.2 Balanced frequency discrimination . . . . . . . . . . . . . . . 80

N.2 Phase shift discrimination . . . . . . . . . . . . . . . . . . . . . . . . 81

O Automatic Gain Control 85O.1 Theory of operation . . . . . . . . . . . . . . . . . . . . . . . . . . . 85O.2 Design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85

P Measurements of signal strength 87P.1 Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87P.2 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88P.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 88

Q Test of algorithm 89Q.1 Theory/Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89

Q.1.1 Signal to Noise ratio . . . . . . . . . . . . . . . . . . . . . . . 89Q.1.2 DFT analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 91Q.1.3 Complexity . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Q.1.4 Listening test . . . . . . . . . . . . . . . . . . . . . . . . . . . 92

Q.2 Verification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92Q.2.1 Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93

Page 7: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

R Demod: ZC detection 94R.1 Theory/principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94R.2 Mathematic description . . . . . . . . . . . . . . . . . . . . . . . . . 94R.3 Digitalisation considerations . . . . . . . . . . . . . . . . . . . . . . . 95R.4 MATLAB implementation/simulation . . . . . . . . . . . . . . . . . 95R.5 Evaluation/simulation of MATLAB implemented algorithm. Ac-

cording to approved test-specification. . . . . . . . . . . . . . . . . . 95R.6 C implementation considerations . . . . . . . . . . . . . . . . . . . . 95R.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95

S M-order FIR bandpass filter 96S.1 Principle . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96S.2 Mathematical description . . . . . . . . . . . . . . . . . . . . . . . . 96S.3 Digitalisation considerations . . . . . . . . . . . . . . . . . . . . . . . 98S.4 MATLAB implementation . . . . . . . . . . . . . . . . . . . . . . . . 98S.5 Evaluation of implementation . . . . . . . . . . . . . . . . . . . . . . 99S.6 C implementation considerations . . . . . . . . . . . . . . . . . . . . 99S.7 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100

T Quadrature detection 101T.1 Theory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101T.2 IQ generator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101T.3 Arctan demodulator . . . . . . . . . . . . . . . . . . . . . . . . . . . 101T.4 Differentiating 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101T.5 Differentiator 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101T.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101

Page 8: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

List of Tables

B.1 Allocation of some radio bands. . . . . . . . . . . . . . . . . . . . . . 18

C.1 Frequency response of an AC’97 compliant sound card . . . . . . . . 21C.2 Input parameters of an AC’97 compliant sound card . . . . . . . . . 21

E.1 Specifications of input and output of the downconverter. . . . . . . . 33E.2 Specifications of mixers. . . . . . . . . . . . . . . . . . . . . . . . . . 36E.3 Specifications of bandpass filter. . . . . . . . . . . . . . . . . . . . . . 37E.4 Simulation parameters that vary from default. . . . . . . . . . . . . . 37

G.1 Specifications of lowpass filter. . . . . . . . . . . . . . . . . . . . . . 45G.2 Equipment used in test. . . . . . . . . . . . . . . . . . . . . . . . . . 45G.3 Result of test. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

H.1 Specifications for the signal from the downconverder. . . . . . . . . . 48H.2 Specifications for the antialiasering filter in the soundcard. [Intel

Corporation] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

J.1 Hardware settings passed to the sound card . . . . . . . . . . . . . . 62

K.1 Summary of IO system functions . . . . . . . . . . . . . . . . . . . . 66K.2 Grouping of functions for the input- output-system . . . . . . . . . . 67

O.1 Components used in the AGC circuit . . . . . . . . . . . . . . . . . . 86

P.1 Equipment used in test. . . . . . . . . . . . . . . . . . . . . . . . . . 87

8

Page 9: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

List of Figures

A.1 System overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14

B.1 Function diagram of radio transmitter . . . . . . . . . . . . . . . . . 17B.2 Frequency overview of a FM-modulated signal. . . . . . . . . . . . . 18B.3 Function diagram of radio receiver . . . . . . . . . . . . . . . . . . . 18

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

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

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

frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27D.5 Besselfunktion of 0 to 3 orders as a funtion of β . . . . . . . . . . . . 29D.6 First 25 orders of the besselfunction with 3 fixed β values . . . . . . 30D.7 Numbers of significant side frequencies (|Jn(β)| > 0.01) . . . . . . . 31

E.1 Displacement of frequency spectrum. . . . . . . . . . . . . . . . . . . 32E.2 Mirrors as a result of product modulation. . . . . . . . . . . . . . . . 34E.3 Symbol of a 3-terminal mixer. . . . . . . . . . . . . . . . . . . . . . . 34E.4 Block diagram of a possible downconverter solution. . . . . . . . . . 35E.5 Simulink model block diagram of downconverter. . . . . . . . . . . . 38E.6 Waveforms of simulation (a) after the first mixing, (b) after the sec-

ond mixing and (c) the resulting output. . . . . . . . . . . . . . . . . 39

F.1 Principal sampling block . . . . . . . . . . . . . . . . . . . . . . . . . 40F.2 Time- and discrete-domain representation of signals . . . . . . . . . 43F.3 Frequency spectrum of sampled signal . . . . . . . . . . . . . . . . . 44F.4 Superimposed frequency picture . . . . . . . . . . . . . . . . . . . . . 44

G.1 Test setup for downconverter. . . . . . . . . . . . . . . . . . . . . . . 46

H.1 Attenuation in the transition band for the filter implementet in thesoundcard. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49

H.2 4. order band pass Sallen and Key filter . . . . . . . . . . . . . . . . 53H.3 Simulation of the bandpass filter . . . . . . . . . . . . . . . . . . . . 54

9

Page 10: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

I.1 GNU Pth scheduler mechanism . . . . . . . . . . . . . . . . . . . . . 57

J.1 Structure of the interleaved and non-interlaaved buffer structure usedin ALSA . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60

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

M.1 Low pass Sallen and Key filter . . . . . . . . . . . . . . . . . . . . . 74M.2 High pass Sallen and Key filter . . . . . . . . . . . . . . . . . . . . . 76

N.1 Amplitude response of an ideal slope circuit. . . . . . . . . . . . . . . 80N.2 Block diagram of a balanced slope detector. . . . . . . . . . . . . . . 81N.3 Amplitude responses of a balanced frequency discriminator. . . . . . 81N.4 Ideeal phase response of a linear phase shift network. . . . . . . . . . 82N.5 Block diagram of quadrature detector. . . . . . . . . . . . . . . . . . 82

O.1 Schematic of AGC . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86

P.1 Test setup for signal strength measurement. . . . . . . . . . . . . . . 87

Q.1 Implemention of the signal to noise test. . . . . . . . . . . . . . . . . 90Q.2 Signal to noise block diagram. . . . . . . . . . . . . . . . . . . . . . . 90Q.3 1000 order FIR frequency responce . . . . . . . . . . . . . . . . . . . 91Q.4 Implemention of the DFT analysis test. . . . . . . . . . . . . . . . . 91Q.5 FFT analysis of 1 kHz sine tone . . . . . . . . . . . . . . . . . . . . . 93

R.1 Block diagram Zero-crossing Detection Demodulation Algorithm. Fig-ure 7.3-9 in [Carlson, 1986, p. 262] . . . . . . . . . . . . . . . . . . . 94

S.1 20 order FIR bandpass filter . . . . . . . . . . . . . . . . . . . . . . . 97S.2 Ideal bandpass filter . . . . . . . . . . . . . . . . . . . . . . . . . . . 97

Page 11: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Insert text here. . .

11

Page 12: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

BIBLIOGRAPHY

Bibliography

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

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.

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.

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

12

Page 13: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

BIBLIOGRAPHY

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

Standish, Thomas A. (1995).Data Structures, Algorithms & Soft-ware Principles in C.ISBN 0-201-59118-9(Addison-Wesley Publishing Com-pany, Inc., 1995).

13

Page 14: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix ARequirement specification

A.1 General description

A.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 A.1 for a overview of thesystem.

Figure A.1: System overview

A.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].

A.1.3 Further plans for the system

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

A.1.4 User profile

The users are primarily the developers of the system.

14

Page 15: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX A. REQUIREMENT SPECIFICATION

A.1.5 Definitions

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 a transmitter (i.e. dBmERP)

A.2 System interface

A.2.1 Input

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

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

Carrier Frequency 145MHzBandwidth 16 kHz

With this setup, the input signal that is received by the antenna has been measuredto the following (see appendix P):

Carrier Frequency 145MHzBandwidth 16 kHzSignal magnitude -33 dBm

A.2.2 Output

The output is specified to:

Frequency range 300 - 3000 HzStereo/Mono MonoBitresolution 16 bit

A.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 isconnected to a loudspeaker. The input is connected via a BNC plug, the output ofthe soundcard is a minijack female plug.

A.2.4 User Interface

The User Interface (UI) is to be as simple as possible, perhaps purely in textmode.The following function has to be maintainable via the UI:

• Quit the program

15

Page 16: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

A.3. QUALITY FACTORS

A.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. The distortion must be smaller than 10 % [Christensen, 1999, page 394]

3. SND/ND ratio has to be smaller than 20 dB to comply with the ETSI stan-dard [ETSI, page 35].

A.4 Acceptance test specification

The test specification is a black-box test specification.

A.4.1 Test for demands for the total delay (Section A.3: De-mand 1)

This will be tested by sending a pulse tone (i.e. a clap) through the system, andmeasure the time delay with a oscilloscope.

A.4.2 Test for demands for distortion (Section A.3: Demand2)

This will be tested by applying a sine wave to the input, and then measuring howmuch the output is distorted.

A.4.3 Test for demands for SND/ND ratio (Section A.3: De-mand 3)

This will be tested by using the ETSI test specification in [ETSI, section 8.1.2]

A.4.4 Test for demands for UI (Section A.2.4)

This will be tested visually.

16

Page 17: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX B. PREANALYSIS

Appendix BPreanalysis

The requirement for functionality, quality and external interfaces is specified in thelast chapter. This chapter aims to discuss the possibility of a solution to the prob-lem. In the end of this chapter a solution is chosen and the overall system designis 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.

B.1 Radio signals

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

Figure B.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 appendixD. This enables transmission of more than one signal at a time, as each signalhas a different carrier frequency (fig. B.2). Due to the requirements of soundquality for commercial radiostations, they require a bandwidth of 150kHz. Theradio amateurs only require 16kHz, due to the fact that they do not need a highsound quality, as they only transmit speech. [Christensen, 1999] FiXme Note: find

17

Page 18: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

B.2. CHOSING A RADIOSIGNAL TO RECEIVE

sidetal i HF-teknik, eller en anden kilde

Figure B.2: Frequency overview of a FM-modulated signal.

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

Figure B.3: Function diagram of radio receiver

B.2 Chosing a radiosignal to receive

There are three concerns when it comes to receiving a radio signal; a) the frequencyrange of the carrier, b) the bandwidth of the signal and c) the type of modulation.Governments of the world decide which frequency ranges that are allocated forthe different puposes. A table containing these allocations from 25 contries ismaintained at the website www.efis.dk. Some of the allocations are shown in tableB.1.

Frequency band Allocation Application47.0 - 50.0 MHz BROADCASTING TV analogue87.5 - 108.0 MHz BROADCASTING FM sound analogue144.0 - 146.0 MHz AMATEUR Amateur radio469.5 - 469.95 MHz MOBILE Paging401.0 - 402.0 MHz SPACE OPERATION ... Sondes

Table B.1: Allocation of some radio bands.

For each application there exsists conventions or rules about the bandwidth ofa trasmission in the band. For radio broadcast the bandwidth must not exceed 150kHz, but 200 kHz is reserved for each transmission. For amateur radio the band-width must not exceed 10 kHz, but 16 khz is reserved for each transmission. [kilde?].

This project aims on FM demodulation and based on which application has thesmallest bandwidth amateur radio is chosen. Another reason to choose amateurradio is that the group is able to send test signals using an amateur radio. Thiswould be illegal for any non-amateur band.

18

Page 19: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX B. PREANALYSIS

B.3 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 re-quieres a high sample 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 is described in the following.

B.3.1 High frequency sampling

Some of the fastest I/O extension cards for PCs samples with around 200 MHz[www.ni.com], which would be sufficient for direct sampling of most broadcast ra-dio signals at Nyquist. The solution is expensive compared to analog receiving.Furthermore it it only possible for applications which operates with carrier fre-quencies below approximately 100 MHz.

B.3.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 C.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 thanaudio, in this case an amateur radio signal as the one described in the previoussection. The bandwith of the radio signal is lower than the bandwidth of an audiosignal, so if the radio signal can be downconverted to fit into the audio range of fre-quencies, sampling should be possible. One problem with using a sound card couldbe that it is not designed for phase linearity, because the human ear is generallynot sensitive to phase in audio [kilde???].

The sound card solution is considered the best method to use in the project, andfurthermore it utilizes hardware allready present in most computers. Some chal-lenges can be predicted in the demodulation of the signal; a) Non-linear phase of thesoundcard may distort the FM signal in an unknown way and b) the demodulationmay more difficult or require more computing power since the carrier frequencywill be approximately only 3 kHz away from the highest frequency of the messagesignal.

B.4 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 the

19

Page 20: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

B.5. SYSTEM DESIGN

programmer. 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. Anything else ???

Linux offers direct access to peripheral hardware, but to support multiple soundcards with the same software, the interface between the demodulation software andthe soundcard will be ALSA, which is the standard sound API for linux.

B.5 System design

Based on the descisions above a possible problem solution is presented in the fol-lowing:

The signal to receive is ameteur 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 C if it is first downconverted to the audio 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.

20

Page 21: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX C. SOUND CARD

Appendix CSound 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 C.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 C.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 C.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 Capasitance - 7.5 - pF

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

21

Page 22: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

as full-duplex 16 bit.

22

Page 23: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX D. MODULATION

Appendix DModulation

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 D.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].

D.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) (D.1)(D.2)

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

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

23

Page 24: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

D.1. AMPLITUDE MODULATION

2 4 6 8 10 12t [s]

Carrier wave

2 4 6 8 10 12t[s]

Modulation signal

2 4 6 8 10 12t[s]

Amplitude modulated signal

2 4 6 8 10 12t[s]

Frequency modulated signal

Figure D.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 D.3 it is clearthat the value of kam(t) determines the amplitude of the modulated signal. The

2 4 6 8 10 12t[s]

Amplitude modulated signal Ka = 0.5

2 4 6 8 10 12t[s]

Amplitude modulated signal Ka = 1

2 4 6 8 10 12t[s]

Amplitude modulated signal Ka = 2

Figure D.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

24

Page 25: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX D. MODULATION

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

m(t) = sin(1 · t) (D.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. (D.5)

An other criteria for the modulation to be successful is

fc >> W (D.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 D.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.

2 4 6 8 10 12t [s]

Carrier wave (20 ω/s)

2 4 6 8 10 12t[s]

Modulation signal (1 ω/s)

2 4 6 8 10 12t[s]

Amplitude modulated signal

0 2 4 6 8 10 12

−0.5

0

0.5

1

t [s]

Am

plitu

de

Carrier wave (2 ω/s)

0 2 4 6 8 10 12

−0.5

0

0.5

t[s]

Am

plitu

de

Modulation signal (1 ω/s)

0 2 4 6 8 10 12

−1

0

1

Am

plitu

de

t[s]

Amplitude modulated signal

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

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

25

Page 26: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

D.2. FREQUENCY MODULATION

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

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

Acka cos(ωct) sin(ωmt). (D.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

)(D.9)

Acka

j4

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

)(D.10)

Acka

j4

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

)(D.11)

Acka

2

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

)(D.12)

Equation D.12 shows that the frequencies contained in the product is (ωc + ωm)and (−ωc + ωm). Figure D.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 D.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

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

then the instantaneous frequency is defined by

fi(t) = fc + kfAm cos(ωmt) (D.14)fi(t) = fc + ∆f cos(ωmt) (D.15)

26

Page 27: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX D. MODULATION

185 190 195 200 205 2100

0.5

1

1.5

2

2.5

3

3.5

4

4.5

5x 10

4 (b)

frequency (Hz)

S(f

)

−400 −200 0 200 400

x 104 (a)

frequency (Hz)

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

Where

∆f = kfAm (D.16)

The unit ∆f is the frequency deviation, representing the frequency variation fromthe carrier frequency. The characteristic for FM is that ∆f is proportional withthe amplitude of the modulation signal, and independent of the frequency of themodulation signal. To get a expression for how much the frequency changes over aperiode from 0 to t equation D.15 is integrated.

Θi(t) = 2π

∫ t

0

fi(τ)dτ (D.17)

Θi(t) = 2πfct +∆f

fmsin(ωmt) (D.18)

The ration of the frequency deviation ∆f , to the modulation frequency is calledthe modulation index which is given as

β =∆f

fm(D.19)

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

Θi(t) = ωct + β sin(ωmt) (D.20)

From equation D.20 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)

](D.21)

27

Page 28: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

D.2. FREQUENCY MODULATION

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

s(t) = Re[Ace

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

(D.22)

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

](D.23)

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

s(t) = Acejβ sin(ωmt) (D.24)

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 (D.25)

where the complex fourier coefficient cn is defined by

cn =1T

∫ T2

−T2

s(t)e−jωmntdt (D.26)

Inserting the value of s(t) from equation D.24 into equation D.26

cn =Ac

∫ π

−π

ejβ sin(ωnt) · e−jωntdt (D.27)

cn =Ac

∫ π

−π

ejβ sin(ωnt)−jωntdt (D.28)

Defining a new variable x = ωmt and inserting it in equation D.28 gives

cn =Ac

∫ π

−π

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

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

Jn(β) =12π

∫ π

−π

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

This gives a new expression for cn

cn = Ac · Jn(β) (D.31)

28

Page 29: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX D. MODULATION

Substituting equation D.31 in equation D.25

s(t) = Ac

∞∑n=−∞

Jn(β)ejωmnt (D.32)

Now substituting the new expression for s(t) back into equation D.23 gives

s(t) = Ac ·Re[ ∞∑

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

](D.33)

By remembering that

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

]= cos

[(ωc + nωm)t

](D.34)

equation D.33 can be rewritten to

s(t) = Ac

∞∑n=−∞

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

](D.35)

Fourier transform of equation D.35 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)

](D.36)

A plot of the Jn(β) is shown in Figure D.5. The first 4 orders are plotted with

5 10 15

β

0 order1st order2nd order3rd order

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

β values from 0 to 10, however when modulation an base band signal a fixed β is

29

Page 30: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

D.2. FREQUENCY MODULATION

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

n

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

n

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

n

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

used. Figure D.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 eachof the delta functions in equation D.36. If a amplitude of a delta function (orside frequency) 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 D.7 on thenext page shows the numbers of side frequencies with β values from 0.1 to 15.

30

Page 31: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX D. MODULATION

5 10 15β

Significant side frequencies

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

31

Page 32: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix EDownconverter

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 E.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 figureE.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]

Figure E.1: Displacement of frequency spectrum.

E.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 C, which yields the specifications mentioned intable E.1. The received signal will be the one described in appendix B.2, hencethe carry frequency is approximately known and so is the bandwidth of the signal.A quick calculation yields that it should be possible to fit the received signal intothe valid band of input frequencies of the sound card, see equation (E.1). In thedesign it is assumed that the received radio channel does not have any neighbourghchannels.

32

Page 33: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX E. DOWNCONVERTER

ftextrmBW,rec = 16kHz (E.1)ftextrmBW,val = 19.2− 0.02kHz (E.2)ftextrmBW,rec < ftextrmBW,val (E.3)

whereftextrmBW,rec is the bandwidth of the received signalftextrmBW,val is the valid bandwidth of the soundcard input signal

Parameter Value Units

Received signal fc 144 MHzReceived signal fBW 16 kHzDownconverted signal fmin 20 HzDownconverted signal fmax 19.2 kHz

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

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

E.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 of thetranslated signal will be Acsr(t). Because the phase of the mixed signal reverseswhenever the received signal sr(t) crosses zero, the new spectrum has a mirrorimage around the frequency fLO. In practice this means that whenever a signal ismixed in order to translate it in frequency, two spectras are created - each withthe same bandwith but with different carrier frequencies; the one is the receivedsignal shifted downwards and the other is the received signal shifted upwards infrequency. This is explained in appendix FiXme: Ref til Jes’s afsnit om samplingand also sketched in figure E.2 and shown mathemathically in section E.4. [Haykin,2001, pages 94-95,103-104]

f1 = fc − fLO (E.4)f2 = fc + fLO (E.5)

Refering to figure E.2, it is possible to chose fLO so that the spectrum near −f1

overlaps with the spectrum near f1. This is called sideband overlap and compli-cates the situation significantly. This is also why it is not trivial to build zero IFreceivers, i.e. converting directly to baseband. [Laskar et al., 2004, pages 32-44]

33

Page 34: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

E.3. BLOCK DIAGRAM

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

Mixers are available as premanufactured building blocks for various frequencyranges. A mixer has 3 terminals; RF (Radio Frequency), LO (Local Oscillator) andIF (Intermediate Frequency). The block diagram symbol of a mixer is shown infigure E.3.

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

E.2.1.1 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.

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

34

Page 35: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX E. DOWNCONVERTER

In this project the aim is to keep as much of the processing as possible inthe digital domain, and therefore it is desireable to capture the received signalas unprocessed as possible, hence simplifying the downconverter. One solution isshown in the block diagram of figure E.4.

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

Between the antenna and the first mixer some amplification will be nescessary(RF AMP), however the strength of the received signal is not known FiXme: atthis point .

The downconversion is done in two steps using two mixers. At the output ofeach mixer a filter is applied for mirror selectivity. To interface correctly with thesound card described in chapter C, the filter should contain an adjustable gain

E.4 Mathematical analysis

The purpose of the downconverter is to translate the frequencies of the RF signal,in into baseband signals. Which can be sampled by an soundcard. The input signalto the downconverter will be in the form as shown in appendix D:

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

](E.6)

At any give time the signal can be described as:

A1 · cos(ω1 · t) (E.7)

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) (E.8)

By means of Euler this is:

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

2· (ej·t·ω2 + e−j·t·ω2) ⇔(E.9)

A1 ·A2

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

]⇔(E.10)

A1 ·A2

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

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

)]⇔(E.11)

A1 ·A2

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

](E.12)

35

Page 36: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

E.5. DIMENSIONING

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

The result of this mixing is:

A1 ·A2 ·A3

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

](E.14)

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

A1 ·A2 ·A3

4· cos

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

](E.15)

Remembering that the input signal was substituted with equation (E.7) thisyields:

Ac ·A2 ·A3

4· cos

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

](E.16)

E.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 (E.17)fLO,2 = 145 · 106 − 75 · 106 − 9 · 93 = 69.991.000 Hz (E.18)

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 G. The mixers arechosen regarding to the needed frequency ranges. The types used are mentioned intable E.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 E.2: Specifications of mixers.

As the filter following the first mixer the component mentioned in table E.3 isused. Since the attenuation in the stop band is not specified by the manufacturer

36

Page 37: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX E. DOWNCONVERTER

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

Table E.3: Specifications of bandpass filter.

it might not be sufficient.

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

E.6 Simulation

The downconverter is simulated using Simulink. The reason for this is to examinethe waveforms at different points in the downconverter to improve the understand-ing. The model will not be accurate according to the downconverter that is built,because several parameters are left out and because the responses of the filters usedin the physical implementation are not known in detail. In the simulation only themixing process is taken into account, no gain considerations.

The downconverter can be modelled as shown in figure E.5. The mixers aremodelled using a product block. A Chebychew 1 bandpassfilter is selected, havingan order of 3, a passband between 424.115 · 106 rad/sec and 455.531 · 106 rad/secand a passband ripple of max. 0.5 dB. For the second filter a Bessel lowpass filteris selcted, having an order of 9 and a critical frequenzy of 376.99 · 106 rad/sec. Thesignal generators SG1, LO1 and LO2 all produce sine waves with amplitudes of 1and frequencies of 145 MHz, 75 MHz and 69.991 MHz respectively. The simulationparameters are shown in table E.4.

Tab Parameter ValueSolver Stop time 2e-4Solver Type Fixed-step Dormand-PrinceSolver Fixed step size 0.2e-9Workspace I/O Limit data points... UncheckWorkspace I/O Decimation 1Solver Stop time 0.0002

Table E.4: Simulation parameters that vary from default.

The required sample frequency of the simulation is calculated as

fs > 2 · (145 · 106 + 75 · 106) (E.19)> 440 MHz (E.20)

37

Page 38: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

E.7. TEST

Figure E.5: Simulink model block diagram of downconverter.

due to the fact that the highest frequency is the input frequency of 145 MHzshifted 75 MHz upwards. Converted to a maximum sampling time of 2.2727 · 10−9

s, the requirement is shown to be met by a factor of ≈10, comparing with table E.4.

The waveforms the simulation is shown in figure E.6. Figure (a) shows thewaveforms of the signal on both sides of the bandpass filter. FiXme: fejl i legend+ forkert sprog The dotted line shows the mixed but unfiltered signal. The curvesare not smooth due to the sampling frequency, however this does not effect thecalculation. The solid line shows the filtered signal. If the filtered signal was shownin a longer time period it would represent a sine wave, which is the input signalshifted downwards. This signal is mixed again, and the results of this is shown infigure (b). Again the waveforms show that the filtering eliminate the high frequencycomponents and leave the downconverted signal, the solid waveform. In plot (c)the same waveform is shown in a longer time period, revealing a sine wave with afrequency of 9 kHz as expected.

E.7 Test

The test described in appendix G 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.

38

Page 39: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX E. DOWNCONVERTER

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

x 10−8

−0.5

0

0.5

1(a)

time (s)

S(t

)

Før BPEfter BP

0 0.5 1 1.5 2 2.5 3 3.5 4

x 10−8

−0.4

−0.2

0

0.2

0.4(b)

time (s)

S(t

)

Før LPEfter LP

0 0.2 0.4 0.6 0.8 1 1.2 1.4 1.6 1.8 2

x 10−6

−0.4

−0.2

0

0.2

0.4(c)

time (s)

S(t

)

Efter LP

Figure E.6: Waveforms of simulation (a) after the first mixing, (b) after the secondmixing and (c) the resulting output.

39

Page 40: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix FSampling

The goal of signal sampling, from the continious domain to the discrete domain, isto produce a data representation suitable for use in computers.

This chapter will introduce the concept of sampling, and its unwanted propertyof frequency aliasing. The chapter uses theory from [Oppenheim & Schafer, 1998,Section 4].

F.1 From continuous to discrete

The discrete data representation of the continuous signal is attained, by multiplyingthe input signal (xc(t)) with Diracs deltafunction (δ(t− nT )) at specific intervals.With n as all natural numbers and T = 1

fswith fs as the sampling frequency. The

process is shown in figure F.1.

Figure F.1: Principal sampling block. Showing input xc(t) multiplied with δ(t−nT ), producing the output x[n].

As δ(t− nT ) is 1 at t− nT = 0 and otherwise 0, the attained signal is:

x[n] = xc(t− nT ) (F.1)

Figure F.2 on page 43 shows the process in more steps.

F.2 Frequency attributes

Examining the preceeding process with the fourier transform, shows that “signalmirrors” are produced in the frequency domain. This occurs because a multipli-

40

Page 41: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX F. SAMPLING

cation in time equals a convolution in frequency. This will be shown in the following.

The “sampling signal” (δ(t− nT )) can be represented as

s(t) =∞∑

n=−∞δ(t− nT ) (F.2)

with attributes

fs =1T

[Hz] Ωs =2 · πT

[rads

]

Using the multiplication as shown in figure F.1 on the facing page produces thefollowing

xs(t) = xc(t) · s(t) (F.3)

xs(t) =∞∑

n=−∞xc(t) · δ(t− nT ) (F.4)

xs(t) =∞∑

n=−∞xc(nT ) · δ(t− nT ) (F.5)

Using the fourier transfor on (F.3) produces

Xs(jΩ) = Xc(jΩ) ∗ S(jΩ) (F.6)

Using the convolution theorem

f(t) ∗ g(t) =∫ t

0

f(τ)g(t− τ)dτ (F.7)

and the fourier transform

F [f(t)] = F (jω) =∫ ∞

−∞f(t) · e−jωtdt (F.8)

produces ()

Xs(jΩ) =1T

∞∑

k=−∞Xc(jΩ− k · Ωs) (F.9)

It is seen that Ω is a continuous variable, while Ωs determines the offset from theoriginal function because of the multitude of k’s. This is shown in figure F.3 onpage 44

If we examine figure F.4 on page 44 it is easily seen that if Ωs < 2 · Ωbw thesignals will overlap. This is called aliasing. To avoid aliasing, one must sample atat speed faster than twice the bandwidth of the input signal. This is called theNyquist frequency

Ωnyquist > 2 · Ωbw (F.10)

41

Page 42: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

F.2. FREQUENCY ATTRIBUTES

Still missing from this chapter:

• Show nyquist, explain

• Add explanation of the step at () (and remove the cicle)

• Redraw graphs to proper scale

• first figure needs overhaul.. delta etc. . .

42

Page 43: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX F. SAMPLING

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

0 0.2 0.4 0.6 0.8 1

Val

ue

Time

a)

Input signal

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

0 0.2 0.4 0.6 0.8 1

Val

ue

Time

b)

Input signalSampling signal

0

0.2

0.4

0.6

0.8

1

1.2

1.4

1.6

0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1

Val

ue

Time

c)

Sampled signal

Figure F.2: a) The continous input signal b) Continous input signal multipliedwith sampling function c) Discrete time result

43

Page 44: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

F.2. FREQUENCY ATTRIBUTES

Ωs Ωs

Xs(jΩ)

Ω

k = 1 k = 0 k = −1

Figure F.3: Frequency spectrum of sampled signal. The displacement by Ωs isshown for each k.

Xs(jΩ)

k = 1 k = 0

Ω

Ωs

Ωbw

Figure F.4: Superimposed frequency picture

44

Page 45: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX G. MEASUREMENTS OF DOWNCONVERTER

Appendix GMeasurements 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 G.1 is used in stead of the analog filterdescribed in appendix H. The filters has an attenuation of less than 1 dB in thepass band and more than 40 dB in the stop band.

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

Table G.1: Specifications of lowpass filter.

G.1 Method

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

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

Table G.2: Equipment used in test.

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

45

Page 46: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

G.2. RESULTS

Figure G.1: Test setup for downconverter.

f1 = fRF − 0.5 · fBW = 145 · 106 − 0.5 · 16 · 103 = 144.992.000 Hz (G.1)f2 = fRF = 145 MHz (G.2)f3 = fRF + 0.5 · fBW = 145 · 106 + 0.5 · 16 · 103 = 145.008.000 Hz (G.3)

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.

G.2 Results

The results of the test is shown in table G.3.

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

Table G.3: Result of test.

The total voltage loss through the converter can be calculated as

VLoss = 20 · log( Vin

Vout

)[dB] (G.4)

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

46

Page 47: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX G. MEASUREMENTS OF DOWNCONVERTER

X = 10 · log( Pin

10−3

)[dBm] (G.5)

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

Solving for the input power yields

Pin = 10( X10 ) · 10−3 [W] (G.6)

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

VLoss = 6.46 [dB] (G.7)

G.3 Conclusion

The test verifies that the downconverter is able to translate the RF signals to a lowIF of 9 kHz. The conversion loss of 6.46 dB might vary with different input levelsdue to the non linear nature of the mixers. However it has not be possible to verifythis, as the oscilloscope is not able to measure voltages lower that the one used inthe test.

47

Page 48: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix HAntialiasing-filter

Before converting the analog signal from the downconverter to a digital signal in thesoundcard of the computer, an antialiasing filter is needed, se appendix F. Differentkind of filters can be used for the antialiasing filter, depending on the requirementsof the filter. In this appendix the specifications for the filter will be listet and fromthe specifications the filter will be designed.

H.1 Filter-specifications

In this section the specifications for the filter is listet. This is done by compareingthe signal from the downconverter with the specifications for the soundcard filter.

In appendix E and G the signal from the downconverter is described and verified.From these appendixes the signal is known to have the specifications shown in tableH.1

FrequencyfBW 16 kHzfcenter 9 kHzfmin 1 kHzfmax 17 kHz

Table H.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, se appendixF. Similar it is necessary to filter out frekqencies below 1 kHz, because thesefrequencies do not contain information and will only be conceived as noise.

How much the filter needs to damp frequencies over 24 kHz is determined byhow much 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 H.2.

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 meets

48

Page 49: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX H. ANTIALIASING-FILTER

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

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

the requirement of 40 dB attenuation at 24 kHz, only that the filter attenuates 74dB at 28.8 kHz.

By making the assumption that the filter has a constant logarithmic attenuationin the transition band from 19.2 kHz to 28.8 kHz, and 0 dB attenuation in the passband. With these assumptions a graph for the attenuation can be made as shownin figure H.1.

1.5 2 2.5 3

x 104

−100

−80

−60

−40

−20

0

20

40

Frequency (Hz)

Dam

ping

(dB

)

Damping in the transition band for the soundcard filter

Figure H.1: Attenuation in the transition band for the filter implementet in thesoundcard.

As seen in figure H.1, the filter in the soundcard can be expectet to attenuatearound 38 dB at 24 kHz. The requirement of 40 dB attenuation is therefore nearlymaintained by the filter in the soundcard. However it is still necessary to atten-uate frequencies under 1 kHz because the soundcard filter has a analog frequencyresponse down to 20 Hz. It is therefore chosen to buildt a band pass filter, whichcut-off frequencies at 1 kHz and 17 kHz according to table H.1.

Because the signal from the downconverter is frequency modulated, it is neces-sary for the filter to have linear phase. This can be achieved by either making afilter with linear phase or making a filter with unlinear phase and afterwards passthe signal through a delay equalizer.

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

49

Page 50: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

H.2. FILTER-DESIGN

H.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 a band pass filter. The filters will be realized with a Sallen andKey filter with 0 dB attenuation in the passband.

Each of the filters are designed after the following procedure

• Find the transfer function normalized to 1 rad/s.

• Find the values for the components.

• Denormailze the component values to get the desired cut-off frequency.

H.2.1 LP-filter

From appendix L the poles of a 2. order Butterworth function can be found to be

P = −0.70711± j0.70711 (H.1)

From the poles the normalized transfer function N(s) of the 2. order Butterworthfunction with DC-attenuation of 0 dB can be found as

N(s) =1

s2 + 1.414s + 1(H.2)

From appendix M the design formulas for a low pass 2. order Sallen and Key filteris given as

ωn =1√

mnRC(H.3)

1Q

= (n + 1)√

m

n(H.4)

where:m = C4

C2[·]

n = R3R1

[·]R = R1 [Ω]C = C2 [F]

Choosing m sow that

m ≤ 14Q2

(H.5)

then n can be found as

n =( 1

2mQ2− 1

)± 1

2mQ2

√1− 4mQ2. (H.6)

50

Page 51: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX H. ANTIALIASING-FILTER

From equation H.2 Q can be found as

Q =√

11.414

= 0.707 (H.7)

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

m ≤ 14 · 0.7072

(H.8)

m ≤ 0.5 (H.9)

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

n =( 1

2 · 0.3 · 0.7072− 1

)± 1

2 · 0.3 · 0.7072

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

n = 5 ∧ −0.25 (H.11)

Choosing n to be 5, it is possible to find the value of RC in equation H.4

1 =1√

0.3 · 5RC(H.12)

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

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

R =0.8

0.001≈ 750 [Ω] (H.14)

From the definition of m and n C4 and R3 can now be found

C4 = C · 0.3 = 0.0003 [F] (H.15)

and

R3 = R · 5 = 3750 [Ω] (H.16)

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

C2denorm =C2

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

C4denorm =C4

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

51

Page 52: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

H.2. FILTER-DESIGN

H.2.2 HP-filter

In this section the high pass transfer function will be found, by transforming the lowpass transfer function. When the transfer function is found the design procedurewill be the same as for the low pass filter.

From section H.2.1 the 2. order Butterworth function for a low pass filter isknown to be

NLP(s) =1

s2 + 1.414s + 1(H.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(H.20)

Now the filter can be designed using the design fornulars from M

ωn =1√

mnRC(H.21)

1Q

=m + 1√

mn(H.22)

where:m = C3

C1[·]

n = R4R2

[·]R = R2 [Ω]C = C1 [F]

Setting m to 1 gives

ωn =1√

nRC(H.23)

Q =√

n

2(H.24)

In section H.2.1 Q was found to be 0.707, which gives a n of

0.707 =√

n

2(H.25)

n ≈ 2 (H.26)

knowing n, it is now possible to find the value of the product RC

1 =1√

2RC(H.27)

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

52

Page 53: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX H. ANTIALIASING-FILTER

Choosing C to 6 · 10−4 F gives

R =0.707

6 · 10−4(H.29)

R = 1178 [Ω] (H.30)

Now C3 and R4 can be found from definition of m and n

C3 = C · 1 (H.31)C3 = 6 · 10−4 [F] (H.32)

and

R4 = R · 2 (H.33)R4 = 2357 [Ω] (H.34)

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

C3denorm =C3

2 · π · 1000≈ 100 · 10−9 [F] (H.35)

C1denorm =C1

2 · π · 1000≈ 100 · 10−9 [F] (H.36)

Now that both the low pass- and high pass filter is designed it is possible tocombine the filters in order to make the band pass filter.

H.2.3 BP-filter

Combining the low pass- and high pass filter gives the band pass filter of figure H.2.

$R_4$

$V_in$$C_1$ $C_2$

$R_1$

$R_3$

$R_2$

$R_5$

$C_4$

$R_7$ $R_8$

$R_6$$C_3$

$V_out$

Figure H.2: 4. order band pass Sallen and Key filter

Now a band pass filter which meets the specifications listet in section H.1 isdesigned. Before constructing the filter a simulation is made.

53

Page 54: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

H.3. FILTER-SIMULATION

H.3 Filter-simulation

In this section the bandpass filter is testet. This is done using a simulation program(LT-spice). The simulation is maked in the frequency spectrum from 1 kHz to 8·104

Hz.The result of the simulation is shown in figure H.3. In the figure it can be seen

that 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

0

Frequency

dB

Figure H.3: Simulation of the bandpass filter

H.4 Filter-test

54

Page 55: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX I. MULTITHREADING

Appendix IMultithreading

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.

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

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

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

55

Page 56: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

I.2. SELECTION OF THREADING API

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 I.3.2 for moreinformation about events.

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

56

Page 57: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX I. 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.

I.3 GNU Pth general usage

This section will briefly cover the commands used.

I.3.1 Thread control

The basics of the thread control lies in the GNU Pth inbuilt scheduler. The mech-anism is shown in figure I.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 I.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 I.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

57

Page 58: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

I.3. GNU PTH GENERAL USAGE

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

are to be removed from the program.

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

I.3.3 Events and message queues

message queue, events

58

Page 59: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX J. ADVANCED LINUX SOUND ARCHITECTURE

Appendix JAdvanced Linux SoundArchitecture

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

As it is explained in appendix F on page 40 an analog input signal must besampled before it can be used in an computer. The sampling of the analog signalis done in the sound card, and this produces data which must be handled by thecomputer. If the data is not handled properly one sample may be overwritten bythe next sample thus loosing data. When a analog output signal is need from thecomputer, the sampled data must be converted to a analog signal. Digital to analogconversion is also done in the sound card. An continuously analog outpur signalrequires a constant stream of data, if the sound card do not receive this data theoutput will fail or at least pauses will be added in the sound. The ALSA APIprovides options to control the data flow to and from the sound card as well asoptions to configure the sound card. The appendix is based on [ALSA]

J.1 Data flow

During configuration of the sound card two ring buffers are created. These buffeseither 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 tranfere 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.

J.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.If zero is returned the file descriptor have reached End Of File. If there is not

59

Page 60: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

J.2. DATA STRUCTURE

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

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

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

J.2 Data structure

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

Channel 1

Higher byte

First sample

Third sampleFirst sample

Second sample Fourth sample

Channel 1

Channel 2 Lower byteHigher byteLower byteHigher byte

Lower byteLower byteHigher byte Higher byte

First frame Second frame

Non interleaved

InterleavedFirst frame

Second sample

Channel 2

Higher byte Lower byteLower byte

Figure J.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, ininterleaved the samples are mixed together in a single buffer. A period containmultiple samples. ALSA supports are wide range of different sampling formats.

60

Page 61: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX J. ADVANCED LINUX SOUND ARCHITECTURE

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

• Controle interface: Configuring the sound card e.g setting sampling rate.Reading 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 have 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.

J.4 Controle 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 J.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 when athreshold level of data is reached in the buffer.

J.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 andanother 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 detect

61

Page 62: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

J.5. PCM INTERFACE

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

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

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

62

Page 63: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX K. IO SYSTEM

Appendix KIO 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 record audio from the soundcard, provide it to the algorithm for demodulationand finally play it in the speakers of the PC. FiXme Note: jtkr: add block-diagramdescribing interfaces (skaeringsflader) with the rest of the world. This should usethe ”general” block-diagram supplied in the main report. (that is why it isn’t fixedyet..)

This chapter describes the design and implementation of this system, which willbe referred to as the IO system. Before reading this chapter, it is recommended toread chapter J on page 59 about ALSA (Advanced Linux Sound Architecture) andchapter I on page 55 about general threading and the used library, GNU Pth.

The used design method is mainly geared towards object oriented design, and usesUML (Universal Modelling Language) notation. The IO system will be writtenin the procedural programming language C (basicly not object oriented), but thedesign method still applies in a shortened form. See [Borch, 2005] for further infor-mation regarding the design method.

The following steps will be used in the design:

1. Deployment analysis, 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.

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

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

Where each step leads from one abstraction level to one just below it. The resultwill be a definition of used functions and a grouping of these. This is later used inthe implementation of the software.

63

Page 64: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

K.1. ANALYSIS AND DESIGN

K.1 Analysis and design

The main goal of the IO system is to take the input from the soundcard (FM signal),provide it for processing (our supplied algorithm) and play the processed FM signalin the speakers. The soundcards capture and playback and the algorithm is definedas actors, with the IO system as a transport channel between these.

K.1.1 Deployment analysis

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

Capture Playback

Algorithm

ALSA ALSA

FIFO1 FIFO2

IOSYSTEM<<PC>>

Figure K.1: Deployment diagram for IO system.

K.1.2 Define user interactions

The three actors of figure K.1 are capture, playback and algorithm.The capture and playback actors are modelling the capture and playback mecha-

nisms of the soundcard. These have an amount of data that can be kept in buffers,and the capability to signal when their buffer is almost full (capture) or almostempty (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 for 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.

64

Page 65: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX K. IO SYSTEM

K.1.3 Find use-cases

The user interactions can be broken down into two use-cases, shown in figure K.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 K.2: Usecases for IO system.

K.1.4 Describe use-cases

The in-depth description of each use-case happens with the use of activity diagrams,shown in figure K.3 on the following page and figure K.4 on page 67. Both diagramsshow the activities grouped into their respective domains, when a domain can beclearly defined (FIFO and ALSA).

The ”buffer filled” use-case shown in figure K.3 initiates 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.

K.1.5 Find and describe functions

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

65

Page 66: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

K.1. ANALYSIS AND DESIGN

Wait for message

Capture buffer full

<<Message>>

Read data from soundcard

Put data to FIFO1

Get data from FIFO1

Fifo

Alsa

Figure K.3: Activity diagram for buffer filled usecase

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

Table K.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 chapter I on page 55 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”.

K.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 parameters

66

Page 67: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX K. IO SYSTEM

Put data to FIFO2

Get data from FIFO2Wait for message

Playback buffer empty

<<Message>>

Write to buffer

FIFO

ALSA

Figure K.4: Activity diagram for data ready usecase

and program information are assigned to their own domain. Each domain is as-signed to a header and a source file. The result is shown in table K.2 with associatedcomponent diagram in figure K.5 on the next page.

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

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

Table K.2: Grouping of functions for IO system

K.2 Implementation

The implementation description will be based on figure K.6 on page 69. Thissection will describe the general implementation considerations and mention theused functions. For further insight into the code, see [group 506, 2005] whichcontains all the code for the project, in a documented web page. FiXme Note: jtkr:Add reference to html-doxygen-thingy on the CD, add this in the bibtex reference!(Both should be wisible in the bibliography

The source code for the IO system can be found at FiXme Note: jtkr: Addreference to code on appendix CD .

67

Page 68: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

K.2. IMPLEMENTATION

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 K.5: Component diagram for IO system. No inter dependencies showninside IO system package.

K.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 thread.

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.

K.2.2 Thread activities

All 3 threads run concurrently, as shown in figure K.6. The activity waitForMsg() isnot implemented as a single function, but rather a cooperation between the capture-and playback threads, and a callback function from the ALSA library. As explainedin section K.1.2 the capture- and playback actors can signal whenever their buffersare nearing their limits. This signal consists of executing a callback function, whichis named inCalled() for the capture thread, and ouCalled() for the playback thread.

The threads will lie suspended until the associated function is executed. Thefunctions ouCalled() and inCalled() sends a message to the associated thread,

68

Page 69: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX K. 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 K.6: Flowchart of the 3 threads of the IO system. Each thread is runconcurrently and indefinetely, with the main thread suspended (not running).

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 I.3.3 on page 58 for further information about message queues.

This mechanism is shown as the loop in figure K.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 it in FIFO2.

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

69

Page 70: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

K.2. IMPLEMENTATION

K.2.4 FIFO queue

The used FIFO queues is implemented like at standard first-in first-out queue, withthe additional use of mutex’es. See section I.3.2 on page 58 for further referenceabout 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.

There is no upper limit to the amount of data in the FIFO-queue, apart fromthose imposed by the running architecture.

70

Page 71: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX L. BUTTERWORTH APPROXIMATION

Appendix LButterworth approximation

In this appendix the maximally flat magnitude approximation Butterworth, is de-scribed. This is done in order to use the Butterworth approximation in appendixH.

First the properties for |N(jω)|2 to be a squared magnitude function of somerational function H(jΩ) is found. From these propertise an expression for themaximally flat magnitude function can be found. Because the expression for themaximally flat magnitude function can not be used in practice an approximationis made, which gives the Butterworth approximation

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

L.1 Properties of |N(jω)|2In stead of looking at the necessary properties for the magnitude function |N(jω)|it is more convenient to look at the square of the magnitude function |N(jω)|2.

First |N(jω)|2 is rewritten to

|N(jω)|2 = N(jω) ·N∗(jω) = N(jω) ·N(−jω) (L.1)

where:∗ indicates the complex conjugated.

Justification for the last expression is that for rational funktions with real coeffi-cients the complex conjugated is found by replacing jω with -jω.

Now let N(s) be expressed as

N(s) =c0 + c1s + c2s

2 + c3s3 + c4s

4+.....

d0 + d1s + d2s2 + d3s3 + d4s4+.....(L.2)

By replacing s with jω

N(jω) =c0 − c2ω

2 + c4ω4 − ..... + j(c1ω − c3ω

3 + .....)d0 − d2ω2 + d4ω4 − ..... + j(d1ω − d3ω3 + .....)

(L.3)

71

Page 72: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

L.2. MAXIMALLY FLAT MAGNITUDE FUNCTION

Inserting the expression for N(jω) in equation L.1

|N(jω)|2 =g0 − g2ω

2 + g4ω4 − g6ω

6 + g8ω8−.....

f0 − f2ω2 + f4ω4 − f6ω6 + f8ω8−.....(L.4)

Note that gi and fi in equatin L.4 is not necessarily the same as ci and di in equationL.3.

From equation L.4 it can be seen that for a given |N(jω)|2 to be the magnitudesquared function of some rational function N(s), it is necessary and sufficient that

• The function |N(jω)|2 be a ratio of even polynomials in ω.

• Any poles or zeros on the jω axis be of even order.

L.2 Maximally flat magnitude function

The aim is to obtain a magnitude squared function |N(jω)|2 that in the low fre-quency range starting at zero has as flat a characteristic as possible. A way ofobtaining this is to set as many derivatives to zero at ω = 0 rad/s.

Expressing the maximally flat magnitude function so that it maintains the prop-erties described in section L.1 yields

|N(jω)|2 = H2 1 + b1ω2 + b2ω

4 + ....

1 + a1ω2 + a2ω4 + ....(L.5)

Dividing the denominator into the numerator

|N(jω)|2 = H2[1 + (b1 − a1)ω2 + (b2 − a2 + a21 − a1b1)ω4 + ...] (L.6)

From equation L.6 it can be seen that

ai = bi (L.7)

for as many coefficients as possible, in order to make as many derivatives zero at ω= 0.

L.3 Butterworth function

The Butterworth function is a approximation of the maximally flat magnitudefunction. This means that the butterworth function has a maximally flat curve atlow frequencies. In order to make the cut off at higher frequencies all the zeros ofthe function is placed at infinity making the numerator a constant. This meansthat all the coefficients bi of equation L.5 is zero. From equation L.7, when bi iszero then ai must also be zero, except for the highest order one. The resultingmagnitude squared function is

|N(jω)|2 =H2

1 + ω2n(L.8)

72

Page 73: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX L. BUTTERWORTH APPROXIMATION

L.4 Pole location of the Butterworth function

The poles of the Butterworth function may be found by combining equation L.1and L.8 and substituting ω with s

j

N(s)N(−s) =H2

1 + ω2n

∣∣∣ω2=−s2

=H2

1 + (−1)ns2n(L.9)

Setting the denominator of equation L.9 to zero, gives that the poles are located atthe value of s that satisfies

s = [−(−1)n]12n . (L.10)

Thus for n even

s = (−1)12n = e

jπk2n (L.11)

where:k = [1, 3, 5, ....., 4n− 1]

For n odd

s = (1)12n = e

jπk2n (L.12)

where:k = [0, 2, 4, ....., 4n− 2]

From this it can be seen that the poles a located on the unit circle. Lookingonly at the poles on the left-half-plane, the poles can be expressed as

pk = σk + jωk (L.13)

where:σk = -sin

(2k−12n π

)

ωk = cos(

2k−12n π

)

k = [1,2,3,....,n]

73

Page 74: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix MSallen and Key filter

In this appendix a method for filter realization using a Sallen and Key filter isdescribed. This is done in order to use the realization method of the Sallen andKey filter in appendix H.

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

M.1 Low pass Sallen and Key filter realization

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

R1 R2

R3 R4

C1

C2

V2V1

Figure M.1: Low pass Sallen and Key filter

The transfer function for the filter is

V2(s)V1(s)

=K

R1R3C2C4

s2 + s( 1R3C4

+ 1R1C2

+ 1R3C2

− KR3C4

) + 1R1R3C2C4

(M.1)

where:K is the gain factor [gg]

74

Page 75: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX M. SALLEN AND KEY FILTER

Comparing equation M.1 with the general form of the second order low passfilter

V2(s)V1(s)

=H0ω

2n

s2 + (ωnQ )s + ω2

n

(M.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

(M.3)

1Q

=√

R3C4

R1C2+

√R1C4

R3C2+ (1−K) ·

√R1C2

R3C4(M.4)

H0 = K (M.5)

Because there are five unknowns and only three equations, some definitions needsto 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. Two parametersn and m are defined as

n =R3

R1

m =C4

C2

and

R = R1

C = C2

With these definitions equation M.1 can be rewritten as

V2(s)V1(s)

=1

mnR2C2

s2 + ( 1RC )(n+1

n )s + 1mnR2C2

(M.6)

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

ωn =1√

mnRC(M.7)

1Q

= (n + 1)√

m

n(M.8)

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

75

Page 76: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

M.2. HIGH PASS SALLEN AND KEY FILTER REALIZATION

m ≤ 14Q2

(M.9)

Then n can be calculated from

n =( 1

2mQ2− 1

)± 1

2mQ2

√1− 4mQ2 (M.10)

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

M.2 High pass Sallen and Key filter realization

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

V2V1R2R4C1 C3

Figure M.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

(M.11)

where:K is the gain factor [gg]

By comparing equation M.11 with the general form of the second order highpass filter

V2(s)V1(s)

=H0s

2

s2 + ωnQ s + ω2

n

(M.12)

the following equations can be obtained

76

Page 77: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX M. SALLEN AND KEY FILTER

ωn =1√

R2R4C1C3

(M.13)

1Q

=√

R4C3

R2C1+

√R2C1

R4C1+

√R2C3

R4C1−K

√R4C3

R2C1(M.14)

H0 = K (M.15)

As for 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 nand m to be

m =C3

C1

n =R4

R2

(M.16)

and

C = C1

R = R2

With these difinitions the transfer function M.11 can be rewritten to

V2(s)V1(s)

=s2

s2 + sRC

1n

m+1m + 1

mn(RC)2

(M.17)

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

ωn =1√

mnRC(M.18)

1Q

=m + 1√

mn(M.19)

Setting m to 1, which means that C3 = C1 gives

ωn =1√

nRC(M.20)

Q =√

n

2(M.21)

77

Page 78: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix NFM demodulation

Demodulation is the process of removing the modulation from a modulated signal,thus retrieving the message signal. This chapter introduces some conventional de-modulation methods theoretically. Since the demodulator of this project is to beimplemented in software, any hardware considerations are left out. The methodspresented should serve as background information for designing and implementinga software demodulator.

Before presenting any demodulation methods, a convenient representation of anarbitrary FM signal, which is slightly different than the one presented in appendixD, is introduced. An arbitrary sinusoidal signal is expressed as equation (N.1).

s(t) = A · cos(φi(t)

)(N.1)

where:s(t) is a sinusoidal signal [-]A is the amplitude [V]φi(t) is the instantanous phase [rad]

To calculate this result for the case of an FM signal, assume a message signalm(t) which can be any continous wave signal, but normalized to a maximum am-plitude of 1. When m(t) is frequency modulated on a carrier frequency fc, theinstantanous frequency of the modulated signal is by definition as shown in (N.2).

fi(t) = fc + ∆fm(t) (N.2)

where:fi(t) is the instantaneous frequency of the modulated signal [Hz]fc is the carrier frequency of the modulated signal [Hz]∆f is the maximum deviation from the carrier frequency fc [Hz]m(t) is a continous wave message signal [-]

Since frequency is related to angular velocity by a 2π factor and since the an-gular velocity is the time derivative of the angle or phase, the instantaneous phase

78

Page 79: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX N. FM DEMODULATION

can be determined by integrating the instantaneous frequency, as shown in equation(N.3).

φi(t) = 2π

∫ t

0

fi(τ)dτ (N.3)

= 2πfct + 2π∆f

∫ t

0

m(τ)dτ (N.4)

where:φi(t) is the instantaneous phase of the modulated signal [rad]

By combining (N.1) and (N.3) a sinusoidal FM signal is expressed as equation(N.5).

s(t) = Ac cos(2πfct + 2π∆f

∫ t

0

m(τ)dτ)

(N.5)

where:s(t) is the modulated signalAc is the amplitude of the carrier

Equation (N.5) will be the basis on which each demodulation method is described.

[Carlson, 1986, pages 230-234] [Haykin, 2001, pages 109-111]

The remaining of this appendix will introduce the principles of two common de-modulation methods, frequency- and phase discrimination.

N.1 Frequency discrimination

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 the messagesignal is low and vice versa. The time derivative of the FM signal of equation (N.5)is calculated in equation (N.6).

s′(t) = −Acd

dt

[2πfct + 2π∆f

∫ t

0

m(τ)dτ]sin

(2πfct + 2π∆f

∫ t

0

m(τ)dτ)

(N.6)

s′(t) = 2πAc(fc + ∆fm(t)) sin(2πfct + 2π∆f

∫ t

0

m(τ)dτ + π)

(N.7)

The sine part of the signal has a frequency within fc±∆f , which should be higherthan the frequency of the baseband signal m(t). If this is the case the basebandsignal can be derived by using an envelope detector to filter out the frequencies nearthe carrier. An envelope detector simply outputs the envelope of an AC signal, andit conatins some time constant to determine sensitivity. The principle is usefull inmany other applicatin i.e. powersupplies. For now it is sufficient to view it a filter.Using an envelope detector yields the output y(t) of equation (N.8).

y(t) = 2πAc(fc + ∆fm(t))= 2πAcfc︸ ︷︷ ︸

DC

+2πAc∆fm(t) (N.8)

79

Page 80: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

N.1. FREQUENCY DISCRIMINATION

The signal y(t) contains a DC offset and a scaled version of the message signal m(t).

The applicability of this method relies on whether envelope detection is possible.The carrier frequency will always be present in the output of the slope detector,so to properly detect the message frequencies and ignore the carrier, the carrierfrequency must be significantly higher than the highest frequency of the messagesignal.

N.1.1 Slope detection

The slope detection, which in the previous section was described by a time deriva-tive, will be discussed a little further to aid the understanding of another basicdemodulation method, namely the balanced frequency discriminator.

A slope detector is in general a filter which has a gain proportional to the fre-quency of the input signal. Linearity is obtained by assuming that the signal rangeof frequencies lies on an approximately linear interval of the filter slope. In thisdescription it will be sufficient to discuss the ideal slope circuit which has the am-plitude response |H1(f)| = 2πf . However the theory will hold for any responsesthat are linear in amplitude in the frequency range fc±∆f . The response is shownfor positive frequencies in figure N.1. Note that when no modulation is applied,

fc

H1,0

H1max

H1,min

fc + ∆ffc −∆ff

|H1(f)|

Figure N.1: Amplitude response of an ideal slope circuit.

m(t) = 0, the output of the slope circuit is an offset value, H1,0, due to the carrierfrequency. As the frequency of the modulated signal varies in the range fc ±∆f ,the output varies linearly between some H1min and H1max. If the slope is differentthan 2π, which it usually is, the output gain will also differ.

N.1.2 Balanced frequency discrimination

Balanced frequency discrimination offers an elegant alternative to simply blockingthe DC offset. A frequency discriminator basically consists of a slope circuit, anenvelope detector and a DC-block connected in series. In balanced frequency dis-crimination the DC-block is omitted, and a parrallel signal route consisting of yetanother slope circuit, H2 and and envelope detector is added. The setup is shown infigure N.2. The relation between the slope circuits H1 and H2 must fulfill equation(N.9).

|H2(f + fc)| = |H1(−f + fc)| (N.9)

80

Page 81: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX N. FM DEMODULATION

Env∑

H2

H1

Env

s(t)+

-

y(t) = KD∆fm(t)

Figure N.2: Block diagram of a balanced slope detector.

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 N.3a. The two signals at hand are: the envelope of

(a) (b)

fc

|H2(f)| |H1(f)| |H1(f)−H2(f)|

fc −∆f fc + ∆ff f

fc −∆f fc

fc + ∆f

Figure N.3: Amplitude responses of a balanced frequency discriminator.

the modulated signal passed through H1 and the envelope of the modulated signalpassed through H2. When these two are subtracted the offset amplitude cancels outand a frequency response of figure N.3b is achieved. Note that the resulting slope istwice 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]

N.2 Phase shift discrimination

The principle of the phase shift discriminator is to use a circuit that changes thephase of the input according to the frequency of the input, henceforth a phase shiftnetwork (PSN).

The PSN is discussed a little further before proceding with the demodulation solu-tion. Feeding a FM or PM signal through a linear network produces distortion, andthis distortion can be used to derive the message signal. Consider an input signalis given by (N.10), which by the definition could be any phase modulated signal.

xc(t) = Ac cos(2πfct + φ(t)) (N.10)

81

Page 82: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

N.2. PHASE SHIFT DISCRIMINATION

The output of the network is then given by (N.11).

yc(t) = A(t) cos(2πfc · (t− t0) + φ(t− t1)) (N.11)

where:Ac is the carrier amplitude [V]A(t) is the amplitude of the linear network output [V]t0 is the carrier delay of the network [s]t1 is the group delay of the network [s]

The PSN is a filter which has a linear phase response in the frequency range fc±∆fand has fct0 = 90 rad, as shown in figure N.4. By using equation (N.11), the phase

fc −∆f fc fc + ∆ff0

-90

-180

6 H(s)

Figure N.4: Ideeal phase response of a linear phase shift network.

of the output of the PSN is therefore given by equation (N.12).

sPSN(t) = 2πfc · (t− t0) + φ(t− t1)= 2πfc · t− 2π · 90 rad + φ(t− t1)= 2πfc · t− 90o + φ(t− t1) (N.12)

This yields a phase response of exactly -90 degrees at fc which is why the phase shiftdiscriminator is also referred to as a quadrature detector. [Carlson, 1986, page 249]

The demodulation method is to multiply the received FM signal with the samesignal applied to the PSN. The setup is shown in figure N.5. The result is lowpassfiltered. Why this demodulates FM is maybe not obvious, so the calculation is

y(t) = KD∆fm(t)s(t) Limiter BPF

PSN

LPF

Figure N.5: Block diagram of quadrature detector.

shown in the following. In the calculation the carrier amplitude is negelected. TheFM signal is defined as cos(2πfc + φ(t)). The result of the multiplication is shown

82

Page 83: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX N. FM DEMODULATION

in equation (N.13) to (N.17). First it is noted that a phase shift of -90 degress turnsthe cosine into a sine:

y(t) = cos(2πfct + φ(t)) · sin(2πfct + φ(t− t1)) (N.13)

The two functions to be multiplied are rewritten using Euler.

y(t) =12(ej(2πfct+φ(t)) + e−j(2πfct+φ(t))

). . .

. . . · 12j

(ej(2πfct+φ(t−t1)) − e−j(2πfct+φ(t−t1))

)(N.14)

y(t) =14j

(ej(4πfct+φ(t)+φ(t−t1)) − e−j(4πfct+φ(t)+φ(t−t1)) . . .

. . .− ej(φ(t)−φ(t−t1)) + e−j(φ(t)−φ(t−t1)))

(N.15)

y(t) =12[ 12j

(ej(4πfct+φ(t)+φ(t−t1)) − e−j(4πfct+φ(t)+φ(t−t1))

). . .

. . .− 12j

(ej(φ(t)−φ(t−t1)) − e−j(φ(t)−φ(t−t1))

)](N.16)

The last result is recognized as two sine functions:

ˆy(t) =12(sin(4πfct + φ(t) + φ(t− t1))− sin(φ(t)− φ(t− t1))

)(N.17)

Equation (N.17) consists of sinusoidal signals of two frequency ranges. Since thefirst sinusoidal signal is located near 4πfc it can be filtered out. After the filtrationthe output of the detector is as (N.18). Assuming the group delay of the PSN, t1,to be so small that |φ(t)−φ(t−t1)| << π, the approximation sin(φ(t)−φ(t−t1)) ≈φ(t)− φ(t− t1) is valid, this is shown in equation (N.19).

y(t) = −12(sin(φ(t)− φ(t− t1))

)

= k · (sin(φ(t)− φ(t− t1)))

(N.18)

≈ k · (φ(t)− φ(t− t1))

(N.19)

where k is some constant. This result will be of use later. Now consider the phaseof the FM signal of equation (N.5) and its time derivative:

φ(t) = 2π∆f

∫ t

0

m(τ)dτ (N.20)

φ′(t) = 2π∆fm(t) (N.21)

The approximation for a time derivative of some continous signal, i.e. φ(t), is givenby equation (N.22).

φ′(t) ≈ φ(t)− φ(t− t1)t1

(N.22)

Combining equations (N.19) and (N.22) yields (N.23).

φ(t)− φ(t− t1) ≈ t1φ′(t)

≈ t12π∆fm(t) (N.23)

83

Page 84: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

N.2. PHASE SHIFT DISCRIMINATION

Note that equation (N.23) is the message signal, m(t), with some gain. Substitutingequation (N.23) into (N.19) yields (N.24).

y(t) ≈ k · (t12π∆fm(t))

≈ KD∆fm(t) (N.24)

where:KD is called the demodulation constant

84

Page 85: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX O. AUTOMATIC GAIN CONTROL

Appendix OAutomatic 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.

O.1 Theory of operation

A integrated circuit known as a Voice Operated Gain Adjusting Device (VOGAD)is chosen for the AGC circuit, see figure O.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.

O.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 ] (O.1)

C206 =1

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

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

85

Page 86: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

O.2. DESIGN

C205 =1

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

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

C206 =1

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

= 936 · 10−12[F ] (O.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 O.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 O.1: Components used in the AGC circuit

86

Page 87: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX P. MEASUREMENTS OF SIGNAL STRENGTH

Appendix PMeasurements 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.

P.1 Method

The test setup is shown i figure P.1.

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

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

Table P.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.

87

Page 88: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

P.2. RESULTS

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

P.2 Results

The results of the test is that the output of the downconverter described in appendixG 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.

P.3 Conclusion

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

88

Page 89: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX Q. TEST OF ALGORITHM

Appendix QTest of FM-demodulation algorithm

In order to compare FM-demodulation a test method is described in the this ap-pendix. The FM-demodulation algorithm will be tested using the following meth-ods:

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

2. DFT analysis of a 1 kHz demodulated signal.

3. Listening test.

4. Complexity of the algorithm in O(n) notation.

The signal to noise ratio test and the FFT analysis test will be implemeted asan automated test in an Matlab script file.

Q.1 Theory/Principle

The principle of the test methods are:

Q.1.1 Signal to Noise ratio

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

S/N = 20 · log(

VS

VN

)(Q.1)

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

89

Page 90: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Q.1. THEORY/PRINCIPLE

The signal to noise ratio in the passband is calculated using multiple sinusoidaltest signals with frequencies ranging from 300 Hz to 3 kHz. Figure Q.1 showshow the test is implemented in Matlab. The sinusoidal test are generated andmodulated using Matlab commands. The modulated signal is then demouled inthe tested FM-demodulating algorithm. The signal to noise signal is calculated forthe demoulated signal. Finally signal to noise ratio is plotted in Matlab.

Figure Q.1: Implemention of the signal to noise test.

Figure Q.2 illustrate a way to find the S/N for an arbitrary signal.

Figure Q.2: Signal to noise block diagram.

The only nontrivial part in the calculation of the signal to noise ratio is thefilter. The passband must be small and the attenuation outside the pass band mustbe high in order to seperate the signal from the noise. If the bandpass filter doesn’thave a unity gain in the passband the noise signal will be calculated wrong. It’salso important that the filtered signal isn’t phase shifted, when substracting it fromthe unfilteret signal.

A simple way of automating the filter generation for different frequencies, is touse the matlab command fir1. When given a filter order, the passband frequenciesand the filter window, fir1 designs a FIR filter with unity gain at the passbandand as much attenuation as possible outside the a narrow passband. The hammingwindow in choosen as a compromise between width of the main lobe and a low peakamplitude of the side lobe. The order of the filter is chosen to 1000. In priciplethe order could be much higher, but since an N order filter needs N samples tosettle, increasing N will require more samples in the test signal, thus the executiontime of the test will increase. Figur Q.3 on the next page shows the normalizedfreqcuecy responce of the filter, designed to pass frequencies between 975 Hz and1025 Hz with a sampling frequency of 48 kHz.

The matlab filtfilt command filters the test signal from both sides, thusavoiding any phase shifting that normally would be caused by the filter. As thefilter have a settling time of 1000 samples, the first and last 1000 samples are leftout when calculating the signal to noise ratio.

90

Page 91: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX Q. TEST OF ALGORITHM

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

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

Figure Q.3: 1000 order FIR frequency responce

Q.1.2 DFT analysis

A discreet fourier transform on a 1 kHz demodulated signal is used to visuallyinspect the frequency spectrum of the signal. Unwanted frequency compontentsinside the pass band, 300 Hz to 3 kHz, are especially critical because it’s impossibleto attenuate them in a filter. Figure Q.4 shows how the test is implemented inMatlab. A 1 kHz sinusoidal signal is generated and modulated using Matlab com-mand. The modulated signal is then demodulated in the tested FM-demodulatingalgorithm. Finally a DFT of the signal is plotted in Matlab.

Figure Q.4: Implemention of the DFT analysis test.

The DFT can be calculated by

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

x[n]W knN (Q.2)

where:x[n] is a discreet signalN is the resolution of the DFTWN is e−j·2·pi/N

91

Page 92: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Q.2. VERIFICATION

A window g[n] is applied to x[n] in the timedomain, the resulting discreet signalcan be calculated

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

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

g[n] =(

1, 0 ≥ n ≥ L

0, else

)(Q.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 MatLab, this is a speed op-timized version of the DFT. Passing the entire signal x to the fft function is theequivalent of using a rectangular window with the same size as the signal. [Haykin,2001, cha. ??]

Q.1.3 Complexity

The complexity of the demodulation algorithm is evaluated using the O(n) notation.The O(n) is a mathematical description of relationship between the work n passedto the algorithm and the resulting workload. [Standish, 1995, p. 220-225]

Q.1.4 Listening test

The final test is a listening test, which will be a subjective evaluation of the audiblesound quality of the algorithm. Each member of the group will listen to all thedemodulaions on the same system (computer, software player, sound card andloudspeakers). Thereafter the demodulations should the sorted after what soundsbest. The worst sounding algorithm will recieve a score of 1, the second worst ascore of 2 and so on. The best algorithm will be the one with to total highest score.FiXme: A listening sound clip, sould be make/found/something

Q.2 Verification

The Signal/Noise test algorithm will be tested by utilizing it on:

1. a pure sine wave (1000 Hz) where the expected frequency is 1000 Hz. Theresult should be a high signal/noise ratio.

2. a pure sine wave (2000 Hz) where the expected frequency is 1000 Hz. Theresult should be a low signal/noise ratio.

3. two pure sine waves (1000 Hz and 2000 Hz) with the same amplitude. Theresult should be about 0 dB.

The FFT analysis will be tested by utilizing it on a pure sine wave (1000 Hz)viewing the result.

92

Page 93: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX Q. TEST OF ALGORITHM

Q.2.1 Results

The result fom the Signal/noise ratio can be seen in table Q.2.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 Q.5.

100

101

102

103

104

Frequency [Hz]

Frequency spectrum

Figure Q.5: FFT analysis of 1 kHz sine tone

93

Page 94: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix RDemodulation Technique:Zero-Cross Detection

R.1 Theory/principle

The Zero-Cross Detection Demodulation Algorithm (ZCDDA) [Carlson, 1986, p.262-263] utilizes the fact that is descibed in equation (R.1).

f =1λ

(R.1)

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

A ZCDDA can be seen at figure R.1. The principle of the ZCDDA is that thefrequency of the pulses generated by Hard limiter follows the frequency of the mod-ulated signal. By integrating them, the original signal should emerge. However, thisdemodulation method requires that the highest allowable frequency in the messagesignal is significantly lower than the carrier frequency.

Figure R.1: Block diagram Zero-crossing Detection Demodulation Algorithm.Figure 7.3-9 in [Carlson, 1986, p. 262]

R.2 Mathematic description

From figure R.1 the following can be derived: The square-wave FM signal (s1(t)triggers a monostable pulse generator, which produces a short pulse of fixed am-plitude A and duration τ at each upward (or downward) zero crossing of s1(t). If

94

Page 95: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX R. DEMOD: ZC DETECTION

the function is viewed for a short while T such that the maximum message signalW , such that W ¿ 1/T ¿ fc, the monostable output s2(t) looks like rectan-gular pulse train with nearly constant period 1/(f(t) + fc(t)). Thus, there arenT ≈ T (f(t) + fc(t) pulses in this interval, and continually integrating s2(t) overthe past T seconds yields:

1T

∫ t

t−T

s2(λ)dλ =1T

Aτ ≈ Aτ(f(t) + fc(t) (R.2)

s1(t) =∞∑

n=0

∞∑

i=0

∂(n− λi!) (R.3)

R.3 Digitalisation considerations

R.4 MATLAB implementation/simulation

R.5 Evaluation/simulation of MATLAB implementedalgorithm. According to approved test-specification.

R.6 C implementation considerations

R.7 Conclusion

95

Page 96: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

Appendix SM-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.

S.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 S.1. The filter has a centerfrequency 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 .

S.2 Mathematical description

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

Corresponding to the discrete-time notation of

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

96

Page 97: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX S. M-ORDER FIR BANDPASS FILTER

102

103

104

Frequency [Hz]

Figure S.1: 20 order FIR bandpass filter

f

|H(ejω)|

BW BW

fc−fc

Figure S.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 (S.3)

The product of (S.2) is in the frequency domain equal to the convolution

H(ejω) =12π

∫ π

−π

Hd(ejω) ·W (ejω−φ)dφ (S.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ω M2

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

0 Otherwise(S.5)

can be written.

97

Page 98: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

S.3. DIGITALISATION CONSIDERATIONS

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

hd[n] =12π

∫ π

−π

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

=12π

∫ −ωc+ωb

−ωc−ωb

e−jω M2 ejωndω +

12π

∫ ωc+ωb

ωc−ωb

e−jω M2 ejωndω (S.7)

=1

π(n− M2 )

·[sin

((ωc + ωb)(n− M

2))

. . .

. . . − sin(

(ωc − ωb)(n− M

2))]

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

=M∑

n=0

hd[n] · z−n (S.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 (S.1) and figure S.2 on thepage before.

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] (S.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 (S.8).

S.3 Digitalisation 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.

S.4 MATLAB implementation

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.

98

Page 99: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX S. M-ORDER FIR BANDPASS FILTER

• 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 currently set to zero, due to need of samplesbefore t = 0.

S.5 Evaluation of implementation

Tested against MATLABs internal commands (FIR1), the designed filter producesthe same coefficients as MATLAB.

Utilized on the same signal, the two algorithms produces the same output ap-proximately same output. FiXme Note: jtkr04: add figure showing ”aproximatelysame output”.

S.6 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.

99

Page 100: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

S.7. CONCLUSION

S.7 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 of the first M samples must handled for implementation with smalldata length or large values of M .

100

Page 101: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

APPENDIX T. QUADRATURE DETECTION

Appendix TQuadrature detection

T.1 Theory

T.2 IQ generator

In section T.1 the I- and Q-signal is difined as

Isignal =A

2cos(φ(n)) (T.1)

Qsignal =A

2sin(φ(n)) (T.2)

In this seciton a mathematical description of the I- and Q-signal is descriped.After the mathematical description, an implementation in matlab is made in orderto use the I- and Q-signal in the following demodulation technics.

In figure ?? the principle for making the I- and Q-signal is described.

T.3 Arctan demodulator

T.4 Differentiating 1

T.5 Differentiator 2

T.6 Conclusion

101

Page 102: kom.aau.dkkom.aau.dk/group/05gr506/051129/report.pdf · Elektronik og Elektroteknik Fredrik Bajers Vej 7B Telefon 96 35 98 36 Fax 98 15 36 62 Title: FM radio receiver Theme: Realtime

LIST OF CORRECTIONS

List of Corrections

FiXme Note: find sidetal i HF-teknik, eller en anden kilde . . . . . . . . . 18FiXme: Ref til Jes’s afsnit om sampling . . . . . . . . . . . . . . . . . . . 33FiXme: at this point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35FiXme: fejl i legend + forkert sprog . . . . . . . . . . . . . . . . . . . . . . 38FiXme: Find a better example . . . . . . . . . . . . . . . . . . . . . . . . . 58FiXme Note: jtkr: add block-diagram describing interfaces (skaerings-

flader) with the rest of the world. This should use the ”general”block-diagram supplied in the main report. (that is why it isn’tfixed yet..) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63

FiXme Note: jtkr: Add reference to html-doxygen-thingy on the CD, addthis in the bibtex reference! (Both should be wisible in the bibliography 67

FiXme Note: jtkr: Add reference to code on appendix CD . . . . . . . . . 67FiXme: A listening sound clip, sould be make/found/something . . . . . . 92FiXme Note: ncmh04: add placement of fc to figure, noted by jtkr04 . . . 96FiXme Note: jtkr04: add figure showing ”aproximately same output” . . . 99

102