51
EEET1237 Minor Thesis Computer Engineering Digital Signal Processing Using Symbian C++ in Embedded Systems Supervisor: A/Prof. Dinesh Kumar ([email protected]) Student: Wilson Castillo Bautista ([email protected] ) ([email protected] ) Subject Code: EEET1237 Minor Thesis Computer Engineering Melbourne, November 19 th , 2007

Digital Signal Processing Using Symbian C++ in Embedded Systems

Embed Size (px)

DESCRIPTION

Embedded Systems are present everywhere around the world, from small tiny applications to high-end complex systems. An embedded system is a special-purpose system in which the computer is completely encapsulated by the device it controls. Unlike a general-purpose computer, such as a personal computer, an embedded system performs one or a few pre-defined tasks, usually with very specific requirements. Since the system is dedicated to specific tasks, design engineers can optimize it, reducing the size and cost of the product. (www.en.wikipedia.org, 2006/11/17).An embedded system must interact with the environment in which it is working. Consequently, it must be able to perceive the external signals which make it take decisions. For that, it must process the information received by its sensors connected to it. And it is the point where digital signal processing comes into high level of importance because through this process the system is able to interact and develop the functions which it has been designed for.The present document shows the results obtained in the development of an application that collect information from a mobile device and process it using DSP techniques. The system implemented runs on a mobile device that uses Symbian as operating system. Hence, the application was developed win Symbian C++ using Microsoft Visual Studio.Net 2003, a Nokia SDK for the Nokia 7710 and a Nokia 7710 mobile device in which the application was tested with satisfactory results. Consequently, this document will present some basic concepts regarding to DSP technology, Symbian OS and the development results.

Citation preview

Page 1: Digital Signal Processing Using Symbian C++ in Embedded Systems

EEET1237 Minor Thesis Computer Engineering

Digital Signal Processing Using Symbian C++ in Embedded Systems

Supervisor: A/Prof. Dinesh Kumar ([email protected])

Student: Wilson Castillo Bautista ([email protected]) ([email protected])

Subject Code: EEET1237 Minor Thesis Computer Engineering

Melbourne, November 19th, 2007

Page 2: Digital Signal Processing Using Symbian C++ in Embedded Systems

2 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Table of Contents

1 Introduction................................................................................................................................... 6 2 Digital Signal Processing.............................................................................................................. 7

2.1 Sampling................................................................................................................................. 7 2.1.1 Sampling Theorem ........................................................................................................ 7 2.1.2 Aliasing ............................................................................................................................ 8

3 Discrete Fourier Transform (DFT) ............................................................................................... 10 3.1 Properties of the DFT........................................................................................................... 11

3.1.1 Linearity ......................................................................................................................... 11 3.1.2 Symmetry ...................................................................................................................... 11 3.1.3 Circular Time Shift ........................................................................................................ 11 3.1.4 Convolution.................................................................................................................. 12 3.1.5 Multiplication by exponential.................................................................................... 12 3.1.6 Modulation ................................................................................................................... 12

3.2 Leakage ............................................................................................................................... 12 3.3 Windowing ........................................................................................................................... 15

3.3.1 Rectangular Window.................................................................................................. 15 3.3.2 Triangular Window....................................................................................................... 15 3.3.3 Hanning Window ......................................................................................................... 15 3.3.4 Hamming Window....................................................................................................... 15

4 Fast Fourier Transform................................................................................................................. 17 4.1 FFT Code............................................................................................................................... 21

5 Filtering ......................................................................................................................................... 23 5.1 Finite Impulse Response Filters .......................................................................................... 23 5.2 Infinite Impulse Response Filters........................................................................................ 24

6 Symbian OS ................................................................................................................................. 26 6.1 Hardware Architecture...................................................................................................... 26 6.2 C++ and Object Orientation ............................................................................................ 27

6.2.1 Fundamental Data Types........................................................................................... 27 6.2.2 Naming Conventions.................................................................................................. 28

6.2.2.1 Class Names.......................................................................................................... 28 6.2.2.1.1 T Classes............................................................................................................. 28 6.2.2.1.2 C Classes ........................................................................................................... 28 6.2.2.1.3 R Classes ............................................................................................................ 29 6.2.2.1.4 M Classes........................................................................................................... 29 6.2.2.1.5 Static Classes .................................................................................................... 29 6.2.2.1.6 Structs................................................................................................................. 29

6.3 Symbian Software Structure in Nokia Devices ............................................................... 29 6.3.1 Application Class......................................................................................................... 30 6.3.2 Document Object....................................................................................................... 30 6.3.3 AppUi............................................................................................................................. 30 6.3.4 View Control................................................................................................................. 30 6.3.5 Model/Engine .............................................................................................................. 30

7 Development of the Application ............................................................................................ 31 7.1 Technical Specification of the Nokia 7710 ..................................................................... 31 7.2 Tools Used............................................................................................................................. 32

Page 3: Digital Signal Processing Using Symbian C++ in Embedded Systems

3 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

7.2.1 Microsoft Visual Studio.Net 2003 ............................................................................... 32 7.2.2 Nokia 7710 SDK for Symbian OS for C++ Supporting Microsoft Visual Studio .NET 2003 C++ and Borland C++BuilderX Mobile Edition.............................................................. 32 7.2.3 Emulator ........................................................................................................................ 33 7.2.4 Active Perl Version 5.6 ................................................................................................ 33

7.3 DSP Application .................................................................................................................. 34 7.3.1 CWavCreator............................................................................................................... 34 7.3.2 CRecordTimer .............................................................................................................. 34 7.3.3 CWavReader ............................................................................................................... 34 7.3.4 CDSPProcessor ............................................................................................................. 35 7.3.5 TMatrix ........................................................................................................................... 35 7.3.6 CWavWriter................................................................................................................... 35 7.3.7 CSettingsDialog ........................................................................................................... 35 7.3.8 CSendAppUi................................................................................................................. 35

7.4 Screen Shots of the application ....................................................................................... 36 8 Conclusions ................................................................................................................................. 37 9 References .................................................................................................................................. 38 Annex 1 – FFT Code........................................................................................................................... 40 Annex 2 – DSP Application Flow Diagram ..................................................................................... 41 Annex 3 – Application UML Model.................................................................................................. 42 Annex 4 – Model/Engine UML Model. ............................................................................................ 43 Annex 5 – DSP Application Use Case ............................................................................................. 44 Annex 6 – ECG Diagram Circuit ...................................................................................................... 45 Annex 7 – ECG Device Supplied by RMIT ...................................................................................... 46 Annex 8 – Screen shots of DSP Application................................................................................... 47

Page 4: Digital Signal Processing Using Symbian C++ in Embedded Systems

4 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Table of Figures Figure 1: DSP Processing (Lynn and Fuerst, 1999). .......................................................................... 7 Figure 2: Sampling Process ................................................................................................................. 7 Figure 3: Aliasing Condition................................................................................................................ 8 Figure 4: DFT of sin(ωt), with frequency = 4 Cycles ...................................................................... 13 Figure 5: DFT of sin(ωt), with frequency = 3.5 Cycles ................................................................... 14 Figure 6: Comparison of the rectangular vs Hanning, Hamming and Triangular windows functions.............................................................................................................................................. 16 Figure 7: FFT Implementation of an 8-point DFT using two-point DFT. (Lyons, 2004)................ 19 Figure 8: FFT Implementation for an input sequence of 8-point, (Lyons, 2004). ...................... 20 Figure 9: Single 2-point DFT (Basic FFT Butterfly). ........................................................................... 20 Figure 10: Full FFT Implementation for an 8-point input sequence.(Lynn and Fuerst, 2004) .. 21 Figure 11: Filtering Process ................................................................................................................ 23 Figure 12: FIR Structure ...................................................................................................................... 24 Figure 13: IIR Structure ....................................................................................................................... 25 Figure 14: Two chip solution ............................................................................................................. 26 Figure 15: ASICs –Application Specific Integrated Circuit. (Sales, 2005) .................................. 27 Figure 16: UML Diagram – Symbian Application Structure.......................................................... 29 Figure 17: Application Running in Nokia Device used in the DSP application. Photo from the target device ..................................................................................................................................... 31 Figure 18: Development Environment used in this project ......................................................... 32 Figure 19: EPOC emulator used in the development process ................................................... 33 Figure 20: Active Perl 5.6................................................................................................................... 33 Figure 21: Desktop Icon of DSP Application. (Photo from the target device)......................... 36 Figure 22: FFT Code ........................................................................................................................... 40 Figure 23: DSP Application Flow Diagram ..................................................................................... 41 Figure 24: Application UML Model .................................................................................................. 42 Figure 25: DSP Application Use Case.............................................................................................. 44 Figure 27: ECG Circuit Supplied by RMIT. Its circuit drawing can be seen inFigure 26........... 46 Figure 28: DSP Started ....................................................................................................................... 47 Figure 29: Option to Create New File ............................................................................................. 47 Figure 30: New File Created............................................................................................................. 47 Figure 31: Signal Processed.............................................................................................................. 48 Figure 32: Signal Processed using ECG input ................................................................................ 48 Figure 33: Signal Processed using ECG input. (Photo from the target device) ....................... 48 Figure 34: Selection File to Transmit................................................................................................. 49 Figure 35: Send data using three different options. ..................................................................... 49 Figure 36: Selection to other device to transmit the signal using Bluetooth. (Photo from the target device).................................................................................................................................... 49 Figure 37: Settings Menu - Output files ........................................................................................... 50 Figure 38: Filtering Options ............................................................................................................... 50 Figure 39: Setting Menu - Duration of the WAV recording.......................................................... 50

Page 5: Digital Signal Processing Using Symbian C++ in Embedded Systems

5 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Table of Tables

Table 1: DFT Leakage effects........................................................................................................... 14 Table 2: Comparison of complexity between DFT and FFT. (Lockhart and Cheetham, 1989).............................................................................................................................................................. 17 Table 3: Values of W8nm ..................................................................................................................... 18 Table 4: Bit reversal for an 8-point FFT............................................................................................. 21 Table 5: Symbian OS Fundamental Types (Harrison, 2003). ........................................................ 28 Table 6: Technical Specification of the Nokia 7710 ..................................................................... 32

Page 6: Digital Signal Processing Using Symbian C++ in Embedded Systems

6 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

DSP Using Symbian C++ in Embedded Systems

1 Introduction Embedded Systems are present everywhere around the world, from small tiny applications to high-end complex systems. An embedded system is a special-purpose system in which the computer is completely encapsulated by the device it controls. Unlike a general-purpose computer, such as a personal computer, an embedded system performs one or a few pre-defined tasks, usually with very specific requirements. Since the system is dedicated to specific tasks, design engineers can optimize it, reducing the size and cost of the product. (www.en.wikipedia.org, 2006/11/17). An embedded system must interact with the environment in which it is working. Consequently, it must be able to perceive the external signals which make it take decisions. For that, it must process the information received by its sensors connected to it. And it is the point where digital signal processing comes into high level of importance because through this process the system is able to interact and develop the functions which it has been designed for. The present document shows the results obtained in the development of an application that collect information from a mobile device and process it using DSP techniques. The system implemented runs on a mobile device that uses Symbian as operating system. Hence, the application was developed win Symbian C++ using Microsoft Visual Studio.Net 2003, a Nokia SDK for the Nokia 7710 and a Nokia 7710 mobile device in which the application was tested with satisfactory results. Consequently, this document will present some basic concepts regarding to DSP technology, Symbian OS and the development results.

Page 7: Digital Signal Processing Using Symbian C++ in Embedded Systems

7 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

2 Digital Signal Processing Digital Signal Processing (DSP) is related to the numerical manipulation of signals and data which are stored in sampled form (Lynn and Fuerst, 1999). It involves several steps which are implemented from the acquisition of the analog input (using the analog-to-digital conversion - ADC), which it can be the result of a sensor output (voltage, temperature, pressure, and so on) to the generation of an analog output (using and digital-to-analog conversion DAC) as a result of the processing. This scheme can be seen in Figure 1.

Figure 1: DSP Processing (Lynn and Fuerst, 1999).

2.1 Sampling As it was discussed above, one of the processes involved in DSP is the ADC (Analog-to-Digital conversion) which consists in the conversion of an analog continuous signal into discrete signal. This process is shown in Figure 2 where a 1 Hz sinusoidal input signal is sampled at a sampling frequency, Fs = 16 samples/second, during 4 seconds.

Figure 2: Sampling Process

2.1.1 Sampling Theorem

Page 8: Digital Signal Processing Using Symbian C++ in Embedded Systems

8 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

As it was shown in the DSP scheme in Figure 1, the aim of an embedded system is to be able to represent the signal which it is processing. Consequently, it must convert the analog signal into a discrete sequence of numbers. The key point in this process is to define how often the system must take a sample of the signal in order to have an accurate representation of it. This question was formulated and solved by Shannon and his conclusion is defined by the Shannon’s theorem. This theorem states that an analog signal, containing components up to a maximum frequency f1 Hz, is able to be reconstructed completely if it is sampled a regularly-spaced time intervals with a frequency of at least 2f1 samples per second. This is shown in Equation 1.

121f

T =

Equation 1: Sampling Interval

2.1.2 Aliasing If the sampling condition establish by the sampling theorem, discussed previously, is not satisfied then frequencies will overlap, which means that frequencies above the sampling frequency will appear below half the sampling frequency. This condition can be seen in Figure 3 where the system is designed to acquire a 1 Hz sinusoidal signal. However, a 7 Hz sinusoidal signal may affect the sampling process.

Figure 3: Aliasing Condition

Aliasing condition is solved under the following conditions:

Page 9: Digital Signal Processing Using Symbian C++ in Embedded Systems

9 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Sampling at least with a sampling frequency (Fs) equal to 2B, where B is the maximum frequency of the input signal.

Implementing a low pass filter, usually called anti-aliasing filter. The function of this filter is to restrict the bandwidth of the signal in order to satisfy the sampling theorem.

The following section is related with Fourier Transform which is the heart of every digital signal processing system.

Page 10: Digital Signal Processing Using Symbian C++ in Embedded Systems

10 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

3 Discrete Fourier Transform (DFT) Spectrum analysis is the basic step in digital signal processing and always has been a matter of concern in different fields of the engineering. The Digital Fourier Transform (DFT) is the straightforward method to obtain the frequency components of any digital sequence. However, the DFT requires large number of computations, which means time and processing power for embedded systems, and these resources are critical in real world applications. Consequently, since 1965 — after the discovery of a procedure to reduce the number of computations in the computation of the DFT (Cooley and Tukey, 1965) —, a series of algorithms has been developed in order to reduce the amount of required computations to obtain the frequency components, these are called, collectively, Fast Fourier Transform (FFT) Algorithms. As it can be seen later in this document, they are a mathematical procedure that give the same result as the DFT but more efficiently. The use of discrete Fourier series is restricted to periodic signals, which make them impossible to apply when the signal to analyse is a non-periodic one (Lai, 2004). However, Discrete Fourier Transform (DFT) can be named as an additional Fourier representation, which can be used to analyse any digital signal of finite length (Lynn and Fuerst, 1998). The DFT is derived from the continuous Fourier Transform which is defined as below (Lyons, R, 2004):

dtetxfX ftj π2)()( −∞

∞−∫= Equation 2: Continuous Fourier Transform

Where x(t) is the continuous time-domain signal. This equation is used to extract spectrum information from the input signal, x(t), (McClellan, Schafer, Yoder, 2003). In fact, the result of its application to any input signal is the frequency domain representation, X(f). However, this mathematical procedure can only be applied to continuous time-domain signals. Consequently, a discrete version is defined in Equation 3:

∑−

=

−=1

0

/2)()(N

n

NnmjenxmX π

Equation 3: DFT Equation (exponential Form) Equation 3 is called DFT (in exponential form) because it is a discrete Fourier-Like transformation.

∑−

=

−=1

0)]/2sin()/2)[cos(()(

N

nNnmjNnmnxmX ππ

Equation 4: DFT Equation (rectangular form)

Page 11: Digital Signal Processing Using Symbian C++ in Embedded Systems

11 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Using Euler’s relationship )sin()cos( φφ je j −=− , Equation 3 can be converted into Equation 4. This is called DFT equation in rectangular form where it is possible to visualize the real and imaginary components of the transform where: x(n) = nth component of the input signal which is represented in discrete form. X(m) = mth component of the output. m = index of the DFT output in the frequency domain, N = number of samples of the input signal. The DFT can be seen as a mathematical transformation of any discrete input signal into its spectral representation. In fact, it gives N distinct spectral coefficients X(m) for any given discrete signal.

3.1 Properties of the DFT There are important DFT properties that make it useful in DSP processing. These properties are demonstrated in several references (Cristi 2004), (Lynn and Fuerst, 1999). The following gives a summary of some of them:

3.1.1 Linearity If

][][ 11 mXnx ↔ and ][][ 22 mXnX ↔ Then

][][][][ 2211 mBXnAXmBXnAx ↔↔+ Equation 5: Linearity property of DFT

3.1.2 Symmetry If the input signal, denoted as x[n] with n= 0, 1, 2, 3,… N-1, is real then:

)()( * mNXmX −= 1 Equation 6: Symmetry property of DFT

3.1.3 Circular Time Shift If

][][ mXnx = Then

00 ][][][ )/2(01

mnn

Nmnj WmXemXnnx =↔− − π Equation 7: Time shifting property of DFT

1 The * symbol means conjugation

Page 12: Digital Signal Processing Using Symbian C++ in Embedded Systems

12 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

3.1.4 Convolution If

][][ 11 mXnx ↔ and ][][ 22 mXnX ↔ Then

][][][][ 21

1

021 mXmXnkxnx

N

k↔−∑

=

Equation 8: Convolution property of the DFT

3.1.5 Multiplication by exponential If

][][ mXnx ↔ Then

])[(][ /2N

NnMj MnXenx −↔π Equation 9: Multiplication by exponential property of the DFT

3.1.6 Modulation If

][][ 11 mXnx ↔ and ][][ 22 mXnX ↔ Then

∑−

=

−↔1

02121 ][][1][][

N

kkmXkX

Nnxnx

Equation 10: Modulation property of the DFT

3.2 Leakage Because DFT output is just an approximation of the true spectra of the original input signal, it is possible to find output values in the spectrum that do not match the real spectra values of the input. This condition is called leakage. In order to understand the leakage characteristic in the DFT it is necessary to see the following examples. Figure 4 shows the DFT of the input signal denoted as sin(ωt) with f=1Hz. The frequency sampling, Fs, has been established as 16 Samples per cycle. In this example a four cycles signal is being analysed which means N = 64. The DFT is applied to the input signal in order to determine the frequency components of it. As can be seen in Figure 4, most of the output values of the DFT, denoted as |X(m)|, are zero with exception of the frequency components with index m=4 and m=60, that is X(4) = 32 and X(60) = 32. As it was stated above each output value of |X(m)| represents the magnitude of the frequency component determined by the index m. Moreover, to

Page 13: Digital Signal Processing Using Symbian C++ in Embedded Systems

13 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

determine which component represent m=4 and m=60 the following equation must be applied:

Nmfmf s

component =)( , where m=0,1,2,…, N-1.

Equation 11: DFT frequency component

As a result of applying this equation, it is possible to obtain the frequency values of m=4 and m=64;

hzff scomponent 1

644)4( == and hzff s

component 1564

60)60( ==

The importance of this result is that the frequency component, m=4, corresponds to 1hz which is accordingly with the pure sinusoidal input signal, with frequency 1hz, that is being analysed. The value found at m=60, corresponds to the symmetry property of the DFT as it was discussed before.

Figure 4: DFT of sin(ωt), with frequency = 4 Cycles

Page 14: Digital Signal Processing Using Symbian C++ in Embedded Systems

14 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

However, the following example, shown in Figure 5, gives a different result. In this case, the frequency of the input signal has been changed to 0.875 hz, note that The Sampling Theorem is still enforced (Lynn and Fuerst, 1999). Consequently, under this new conditions an input signal of 3.5 cycles is being analysed with the same Fs=16 samples per cycles and with N=64.

Figure 5: DFT of sin(ωt), with frequency = 3.5 Cycles

As can be seen in the figure, the application of the DFT to the new signal gives a set of different results. Applying Equation 11, to the first set of outputs, give the following results:

m Fcomponent(m) |X(m)| 0 0.00 Hz 5.76 1 0.25 Hz 6.28 2 0.50 Hz 8.59 3 0.75 Hz 21.88 4 1.00 Hz 19.07 5 1.25 Hz 5.65 6 1.50 Hz 3.06 7 1.75 Hz 2.00 8 2.00 Hz 1.44

Table 1: DFT Leakage effects Table 1 shows the magnitude values for the first nine frequency components. It is noted that there are values different from zero to frequencies that does not match this frequency of the input signal. This is called leakage. Moreover, according to the results shown there is a DC component in the input, which it is not true. Frequency component, m=0 corresponds to DC. The previous results showed an undesired characteristic of the DFT, Leakage. And it is caused due to the fact that the input signal does not have an integral number of cycles

Page 15: Digital Signal Processing Using Symbian C++ in Embedded Systems

15 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

over the period analysed, in this case N=64 samples. Consequently, the input energy of the signal has leaked in the other frequency components (Lyons, 2004).

3.3 Windowing Leakage is a common problem that is present in practical digital signal processing systems. Because signals in the real world contain a mixture of frequencies and very few of them behave in the way presented in Figure 4, where it was possible to capture an integer number of cycles. In contrast, it is more common to find applications like the one shown in Figure 5 (Lynn and Fuerst, 1999). In order to reduce the leakage effect a common practice in digital signal processing system is to multiply the input signal by a suitable window function before processing (applying the DFT) (Lyons, 2004). The selection of the window to be applied to the input signal depends of the application; the following mathematical expressions define the coefficients of some window functions (Lyons, 2004).

3.3.1 Rectangular Window

1)( =nw , for n = 0, 1, 2, …, N-1

3.3.2 Triangular Window

2/)(

Nnnw = , for n = 0, 1, 2, …, N/2 and

2/2)(

Nnnw −= , for N/2+1, N/2+2,…, N-1

3.3.3 Hanning Window

⎟⎠⎞

⎜⎝⎛

−−=

12cos5.05.0)(N

nnw π, for n = 0, 1, 2, …, N-1

3.3.4 Hamming Window

⎟⎠⎞

⎜⎝⎛

−−=

12cos46.054.0)(N

nnw π, for n = 0, 1, 2, … N-1

Applying window functions to the input, shown in Figure 5, and then applying the DFT, give the results shown in the following figures. For a better understanding, only the first 32 values are plotted:

Page 16: Digital Signal Processing Using Symbian C++ in Embedded Systems

16 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Figure 6: Comparison of the rectangular vs Hanning, Hamming and Triangular windows functions.

As can be seen in the figures above, the effect of applying the window function to the input signal before processing improve the output and the magnitude of the frequency components no related with the input are reduced considerably.

Page 17: Digital Signal Processing Using Symbian C++ in Embedded Systems

17 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

4 Fast Fourier Transform The DFT is the mathematical procedure that straightforward gives the frequency components of a discrete-time input signal. However, its computation is very inefficient, especially when the input sequence (N) is large. In fact, the complexity of the DFT is related with the input sequence and it grows as N2. A procedure that reduces substantially the amount of computations was discovered in

1965 (Cooley and Tukey, 1965) and it reduces the complexity to NN2log

2. This procedure

led to the development of other algorithms which are called collectively Fast Fourier Transform (FFT) algorithms (Ingle and Proakis, 2007). The comparison of the number of computations between DFT and the FFT algorithms is shown in the Table 2. As it can be seen in this table, the efficiency of FFT over DFT increases as N is larger which make the use of FFT ideal for real time applications. The FFT is based on the DFT equation which it was described before. For instance, in order to obtain the frequency components for any digital input sequence composed by N points, the following DFT equation is applied.

∑∑−

=

=

− ==1

0

1

0

/2 )()()(N

n

mnN

N

n

Nnmj WnxenxmX π , where NjN eW /2π−=

Equation 12: Origin of the FFT

N DFT = N2 FFT = N/2log2N DFT/FFT

η2

16 256 32 8 75.00% 64 4096 192 21 89.06%

256 65536 1024 64 93.75% 1024 1.05 x 106 5120 205 96.00% 4096 1.68 x 107 24576 683 97.22%

16384 2.68 x 108 114688 2341 99.79% 65536 4.29 x 109 524288 8192 98.44%

Table 2: Comparison of complexity between DFT and FFT. (Lockhart and Cheetham, 1989)

2 Efficiency FFT over DFT

Page 18: Digital Signal Processing Using Symbian C++ in Embedded Systems

18 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Note that the value NjN eW /2π−= is calculated several times during the computation of the

DFT as nmNW . It is demonstrated (Lynn and Fuerst, 2004), (Lyons, 2004) that for an input

sequence of N=8 only eight different values of nmW8 are calculated. These results can be seen in the following table.

Value of n 0 1 2 3 4 5 6 7 0 1 1 1 1 1 1 1 1 1 1 2

)1( j− -j 2

)1( j−− -1 2

)1( j−− j 2

)1( j−

2 1 -j -1 j 1 -j -1 j

Value 3 1 2)1( j−−

j 2)1( j−

-1 2)1( j−

-j 2)1( j−−

of m 4 1 -1 1 -1 1 -1 1 -1 5 1 2

)1( j−− -j 2

)1( j− -1 2

)1( j− j 2

)1( j−−

6 1 j -1 -j 1 j -1 -j 7 1 2

)1( j− j 2

)1( j−− -1 2

)1( j−− -j 2

)1( j−

Table 3: Values of W8nm The reason of this is because the periodicity of the nm

NW term ( mNW is often called twiddle

factor). Consequently, the computation of the DFT is slow and processing expensive. Indeed, the FFT algorithms take the approach of reducing the number of redundant computations. Lyons, 2004, shows how the Radix-2 FFT algorithm divide any N=2i sequence input in two segments, even and odd components, as it is shown in the following equation.

∑∑−

=

=

++=1)2/(

02/

1)2/(

0)12()2()( 2/

N

n

nmN

mN

N

n

nm WnxWWnxmX N

and

∑∑−

=

=

+−=+1)2/(

02/

1)2/(

0)12()2()2/( 2/

N

n

nmN

mN

N

n

nm WnxWWnxNmX N

Equation 13: Simplification of the DFT computation Note that to obtain the second half of the FFT it is not necessary to calculate again those values. In fact, only changing the sign of the twiddle factor ( m

NW ) in the results of X(m) it is possible to obtain X(m+N/2) values. The implementation of this FFT, for an input sequence of N=8 values, is shown in Figure 7.

Page 19: Digital Signal Processing Using Symbian C++ in Embedded Systems

19 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

∑3

04)2( nmWnx

∑ +3

04)12( nmWnx

Figure 7: FFT Implementation of an 8-point DFT using two-point DFT. (Lyons, 2004).

The previous results could be simplified in order to obtain four 2-point DFT. Consequently, Equation 13 can be converted in the following one:

),()()( mBWmAmX mN+=

and

)()()2/( mBWmANmX mN−=+

Where

∑∑∑−

=

+−

=

=

++==1)4/(

0

)12(2/

1)4/(

0

22/

1)2/(

0)24()4()2()( 2/

N

n

mnN

N

n

nmN

N

n

nm WnxWnxWnxmA N

It is possible to say that nm

Nnm

N WW 4/2

2/ = which gives the following result:

∑∑−

=

=

++=1)4/(

04/2/

1)4/(

04/ )24()4()(

N

n

nmN

mN

N

n

nmN WnxWWnxmA

Equation 14 Equation 14 is similar to Equation 13 and shows the possibility to reduce the number of computations in the implementation of DFT. Similarly, it is possible to compute B(m):

Page 20: Digital Signal Processing Using Symbian C++ in Embedded Systems

20 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

∑∑−

=

=

+++=1)4/(

04/2/

1)4/(

04/ )34()14()(

N

n

nmN

mN

N

n

nmN WnxWWnxmB

Equation 15 The results obtained in Equation 14 and Equation 15 show the possibility of reducing the number of mathematical multiplications in order to obtain an efficient way to calculate the DFT for any given input sequence. In fact, Figure 8 shows the implementation of the FFT for an 8-point input sequence. As in can be seen in the figure, the problem has been simplified into four 2-point DFT computations.

Figure 8: FFT Implementation for an input sequence of 8-point, (Lyons, 2004).

The computation of the basic 2-point DFT is shown in the following figure. The flow signal is similarly to a butterfly. It is the reason why this computation is also known as FFT butterfly.

WNN/2

WN0

x(r)

x(r+N/2)

Figure 9: Single 2-point DFT (Basic FFT Butterfly). The definition of the twiddle factor is Nmjm

N eW /2π−= which gives the following results for

1/020 == − NjN eW π and 1)2/(22/ −=== −− ππ jNNjN

N eeW . These results, give the full 8-point implementation of the FFT, shown in Figure 10.

Page 21: Digital Signal Processing Using Symbian C++ in Embedded Systems

21 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

x(0)

x(4)

A(0)

A(1)

W40

x(2)

x(6)

A(2)

A(3)

W42

W41

W43

x(1)

x(5)

B(0)

B(1)

W40

x(3)

x(7)

B(2)

B(3)

W42

W41

W43

W80

W81

W82

W85

W86

W87

X(0)

X(1)

X(2)

X(3)

X(4)

X(5)

X(6)

X(7)

W84

W83

-1

1

-1

1

-1

1

-1

1

Figure 10: Full FFT Implementation for an 8-point input sequence.(Lynn and Fuerst, 2004)

Another important aspect to point out is the fact that the input sequence is bit reversed before the FFT implementation. It is called bit reversal because the input data index is obtained by reversing the bits of the binary representation of the normal input data index order. This is better understood with the following table:

Data Input

Binary Code

Reversed Code

Data Input to FFT

x(0) 000 000 x(0) x(1) 001 100 x(4) x(2) 010 010 x(2) x(3) 011 110 x(6) x(4) 100 001 x(1) x(5) 101 101 x(5) x(6) 110 011 x(3) x(7) 111 111 x(7)

Table 4: Bit reversal for an 8-point FFT.

4.1 FFT Code

Page 22: Digital Signal Processing Using Symbian C++ in Embedded Systems

22 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

The code, exposed in Annex 1 – FFT Code, shows the implementation of the radix-2 FFT algorithm. The code executes the bit reversal prior to calculate the FFT.

Page 23: Digital Signal Processing Using Symbian C++ in Embedded Systems

23 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

5 Filtering Digital Filtering consists in the processing of a Digital Signal using mathematical computations in order to remove undesired frequency components. They behave in the same way as their counterpart in the analog domain. Consequently, it is possible to define digital filters like Low-Pass, Band-Pass, High-Pass, and so on. Digital Filters can achieve theoretically any filtering effect if a mathematical algorithm can express this characteristic. However, their main constrain is speed because they cannot operate any faster that the embedded system that posses them.

Figure 11: Filtering Process

Digital Filters can be found in two different forms: Finite Impulse Response (FIR) filters and Infinite Impulse Response (IIR) filters.

5.1 Finite Impulse Response Filters Finite impulse response filters (FIR) are the most popular filters because of the simplicity in their implementation. Basically, FIR filters use only current and past input samples without using any previous output samples. This is one of the reasons why FIR filters are commonly referred as nonrecursive filters. FIR filter have useful properties that make them suitable for different applications:

Because of their structure FIR filters are inherently stable. They do not require feedback. The phase change is proportional to the frequency which means they can be

designed to be linear phase.

Page 24: Digital Signal Processing Using Symbian C++ in Embedded Systems

24 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

The equation difference for the FIR filter is shown Equation 16.

][...]1[][][ 10 Nnxbnxbnxbny N −++−+= Equation 16: FIR Difference Equation

A basic structure of a FIR filter can be seen in Figure 12 where it is possible to observe that they use addition to calculate their outputs; b0, b1, … bN-1 are called the filter coefficients and they are calculated as a result of the design of the filter. Additional literature, Lyons, 2004, shows deeply detail regarding to analysis and implementation of FIR filters.

Figure 12: FIR Structure

5.2 Infinite Impulse Response Filters The main difference between Infinite Impulse Response (IIR) filters and FIR filters is that the former ones require feedback. In fact, each IIR filter output sample depends on previous input samples and previous filter output samples. In contrast, FIR filter output samples depend only on past input samples.

][...]2[]1[ ][...]1[][][

21

10

NnyanyanyaMnxbnxbnxbny

N

M

−−−−−−−−++−+=

Equation 17: IIR Difference Equation The feedback characteristic of IIR filters give to a DSP system a computational reduction in the processing of signals that the system requires to filter. However, they may become unstable (oscillating indefinitely) if the feedback coefficients are calculated improperly. IIR filters structure can be seen in Figure 13. As it can be seen it is more complex that their counterpart FIR filters because of the feedback loops. Additionally, this generates high quantization error which they are implemented, in practice, as cascade first and second-order rather that the straight structure shown here. Another aspect to have into account in the implementation is that the coefficients should be taken as reals to avoid complex calculations (Hussain, 2007). The design of IIR filters is highly dependent in their analog counterparts because of the great amount of resources available. Consequently, if the design of an IIR needs to be

Page 25: Digital Signal Processing Using Symbian C++ in Embedded Systems

25 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

carried out, first their analog version is designed (Chebyshev, Butterworth, Elliptic filters), using common methods. Then, this design is converted to digital using either technique Bilinear Transformation or Impulse Invariance which are commonly called as discretization techniques.

Figure 13: IIR Structure

Page 26: Digital Signal Processing Using Symbian C++ in Embedded Systems

26 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

6 Symbian OS This section assumes that the reader has a basic knowledge on C++ in order to understand the terminology used here. Many online resources exist to learn C++ from the basics (www.cplusplus.com, 2007/08/01). Symbian OS is a multitasking operating system which includes features like file system, a graphical user interface framework, multimedia support, a TCP/IP stack and libraries for different communication features (Babin, 2006). Symbian OS was designed specifically for mobile devices, for that reason it has small memory and lower power consumption. Additionally, there is a wide amount of resources (see www.symbian.com, 2007/08/01) that allow third party entities to produce applications. Thus, applications developed in Symbian can run in different platforms for years without restarting the device (Nokia, 2004). Symbian OS is object oriented which means that all system objects from applications to interrupt handlers are defined as C++ classes. Additionally, the pre-defined APIs allow the use of multitasking and efficient memory management (Nokia Forum, 2004).

6.1 Hardware Architecture As it was described before, some of the main key issues in the design of Symbian devices are the lower power consumption, the limited memory resources and the quality of the applications in order to avoid restarting the system. Consequently, the hardware designed for these tasks must meet these constrains. Inside a Symbian system there are two domains; one is related with the mobile radio interface, referred commonly as Baseband processor or modem and the other domain is related with the application processor which runs the user interface and the high-level code under Symbian. This two domains solution can be seen in the Figure 14.

Figure 14: Two chip solution

The two domains system operates independently from each other. The baseband processor requires hard real-time software, periodic power management and security for the network. Meanwhile, the application processor is able to operate in two modes; full

Page 27: Digital Signal Processing Using Symbian C++ in Embedded Systems

27 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

power when it is interacting with the user and sleep mode, running the basic software routines when the system is in idle mode. The application processor code contains the frameworks and libraries for build-in applications and third-party development (Sales, 2005).

ARMCPU DSP DMA LCD

controller

System Bus

PIC RTC

fast

IRAM

USB Audio IPC NANDMemory

Controller

slow

UART IR I/O

Figure 15: ASICs –Application Specific Integrated Circuit. (Sales, 2005)

The application processor is the core of the Symbian system that is contained in a single piece of silicon commonly referred as System-on-chip ASICs (Application Specific Integrated Circuits) or ASSP (Application Specific Semiconductor parts). It has CPU, memory, display, audio interfaces, input/output interfaces and additional peripherals according to the particular design. An example of the structure for a System-on-chip can be seen in Figure 15.

6.2 C++ and Object Orientation Symbian OS makes use of C++ for system applications. However, the use of C++ in a Symbian environment differs of its use on other system environments:

C++ has private inheritance, but Symbian OS does not use it. C++ does not know anything about DLL, but Symbian OS does additionally, Symbian

OS define (explicitly) the number of bits to represent basic types. Symbian OS is focusing in error handling and cleanup in order to make a better

memory management.

6.2.1 Fundamental Data Types Symbian OS define different classes and each of them has different characteristics. These characteristics differ in the way how the objects are created (either in the heap or in the stack) and specifically how they should be cleaned up. These classes have a particular set of rules which are used to define the creation or destruction of instance of these classes straightforward. In order to distinguish the different types, Symbian OS use a simple naming convention which gives a prefix to the class name (usually T, C, M or R). A design engineer easily can

Page 28: Digital Signal Processing Using Symbian C++ in Embedded Systems

28 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

determine the behaviour of the parent according to the basic types contained on it. Consequently, there is no need to concern about cleaning and creation issues instead there will be more space to give particular attention to the important factor, the role of the class.

Data Type Description TInt8, TUint8 Signed and unsigned 8-bit integers TInt16, TUint16 Signed and unsigned 16-bit integers TInt32, TUint32 Signed and unsigned 32-bit integers Tint, TUint Signed and unsigned integers: in practice, this means a 32-bit integer TReal32, TReal64, TReal

Single- and double-precision IEEE 754 floating-point numbers (equated to float and double). TReal is equated to TReal64

TText8, TText16 Narrow and wide characters (equated to unsigned char and unsigned short int)

TBool Boolean– actually equated to int due to the early compilers used.Some code depends on this so it has not been changed with the new compilers.

TAny Equated to void, and usually used as TAny* (a 'pointer to anything' ) Table 5: Symbian OS Fundamental Types (Harrison, 2003).

6.2.2 Naming Conventions Every system use naming conventions to indicate what it is important. Consequently, Symbian OS is not the exception to this rule. However, as a engineer developer there is no need to adhere to this rules but it will help to understand the code in a easier way. The fundamental rule is to use names that have meaning without exaggerate in the abbreviation. Additionally, there is a basic rule in the design of application program interfaces (APIs), use American English spelling. American English is the international language of APIs (Harrison, 2003).

6.2.2.1 Class Names The initial character of the class indicates the basic properties of it. The following are the main classes defined by Symbian OS. 6.2.2.1.1 T Classes They behave in the same way as the build-in classes in C++, hence they are prefixed with the same letter, “T”, which means type. They do not have destructor. Consequently, T classes should not contain any member class that has a destructor. Examples of T Classes are: TDesC, TPoint, TFileName. 6.2.2.1.2 C Classes C classes are named with the prefix “C” which means that they are derived from the CBase class (which is defined in e32base.h). They have two main characteristics:

Page 29: Digital Signal Processing Using Symbian C++ in Embedded Systems

29 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

First, CBase class has a virtual destructor which means that CBase derived classes may be destroyed properly by simple deletion of the CBase pointer. Second, CBase oveloads the zero operator which means that any instance of the derived CBase classes are initialized to zero. The great advantage of this is that developer engineer does not have to initialize manually the elements in the constructor. CBase derived classes must be created in the heap. 6.2.2.1.3 R Classes R Classes indicate the use of a resource; hence, “R” should be added as a prefix in the name of the class. R classes are related with any class that owns a resource other than on the default heap. R Classes use Close() or Reset() method to free the object. 6.2.2.1.4 M Classes M Classes refer to those ones with pure virtual functions and with no member data. They are the only one which use multiple inheritance and they are referred as ‘mixins’ hence the use of “M”. 6.2.2.1.5 Static Classes There is no more naming conventions in relation with the naming of classes. Symbian OS has left some space to the creation of classes with no prefix letter; they are the static member functions which cannot be instantiated. 6.2.2.1.6 Structs Structs are C-style struct, without any member functions.

6.3 Symbian Software Structure in Nokia Devices The best way to understand the application structure inside a Symbian device is to observe the UML class diagram in Figure 16 (forum.nokia.com 2007/08/01).

Figure 16: UML Diagram – Symbian Application Structure

The four application framework classes are:

Page 30: Digital Signal Processing Using Symbian C++ in Embedded Systems

30 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Application Class Document Object AppUi View Control

6.3.1 Application Class The Application class is initiated as startup object and it defines the properties of the application. Additionally, it creates a new blank document. This class inherits its properties from the CEikApplication class defined in the application framework.

6.3.2 Document Object The document object is used to store the application’s persistent data. If the application is file bases, this object is responsible for storing and retrieving application’s data. It is compulsory from the system point of view to have an instance of the Document Class (inherited from CEikDocument) even if the application does not handle persistent data.

6.3.3 AppUi The AppUi is responsible for handling application events such as Options menu commands, opening/closing files and the application losing focus. Additionally it creates an instance of the view control which it posses. Its base class is CEikAppUi.

6.3.4 View Control The view control is responsible for the interaction with the user because it displays data on the screen in such a way that the user can operate. In Nokia devices, the term container is used instead of view, but the functionality is the same. A view control is derived either from CCoeControl or CEikDialog.

6.3.5 Model/Engine The model engine is used to encapsulate the application functionality; it handle data, persistence and algorithms.

Page 31: Digital Signal Processing Using Symbian C++ in Embedded Systems

31 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

7 Development of the Application This section shows the results obtained in the development of the application result of this project. The name of the application was “originally named” DSP.

Figure 17: Application Running in Nokia Device used in the DSP application. Photo from the target device

The project was developed in a Nokia 7710 device that uses Symbian OS version 7.0 which has the following specifications.

7.1 Technical Specification of the Nokia 7710

Characteristic Description Series Series 90 1.1

Symbian OS 7.0s Memory 90 Mb

Processor 32-bit RISC CPU based on ARM-9 series, ~150 Mhz Battery Lithium Polymer, 1300 mAh

Network GSM 900/1800/1900 Datasupport (E)GPRS, HSCSD Dimentions 128 x 69.5 x 19 mm, 142.5 cc,

Weight 189 g Flashcards MMC

Screen 16 bit, 640 x 320 pixels IR/bluetooth no/yes

Camera 0,99 Mp Music support Stereo

Radio Yes Voice support yes

Page 32: Digital Signal Processing Using Symbian C++ in Embedded Systems

32 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Loudspeaker Yes Table 6: Technical Specification of the Nokia 7710

7.2 Tools Used To accomplish this development the following tools where used:

7.2.1 Microsoft Visual Studio.Net 2003 The development system used in this project was Microsoft Visual C++ .NET version 2003 as Nokia suggested it in the widely documentation offered for application development.

Figure 18: Development Environment used in this project

7.2.2 Nokia 7710 SDK for Symbian OS for C++ Supporting Microsoft Visual Studio .NET 2003 C++ and Borland C++BuilderX Mobile Edition

The software development kit used for the application is the Nokia 7710 which provides the needed tools, application program interfaces (API), sample code, and documentation used to develop C++ applications. The SDK comes with an emulator which is used to test the applications prior to embedded in the target device.

Page 33: Digital Signal Processing Using Symbian C++ in Embedded Systems

33 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

7.2.3 Emulator An important tool in the development process is the emulator (EPOC) which is part of the SDK supplied by Nokia. The emulator allows test the application in the development process reducing the time to market in real world applications. However, it is the target device which determines the real behaviour of the application.

Figure 19: EPOC emulator used in the development process

7.2.4 Active Perl Version 5.6 In order to compile and install the application in the target device it is necessary to install the version 5.6 of Active Perl.

Figure 20: Active Perl 5.6

Page 34: Digital Signal Processing Using Symbian C++ in Embedded Systems

34 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

7.3 DSP Application The results of this development are shown in the UML diagram model which can be seen in Annex 3 – Application UML Model and Annex 4 – Model/Engine UML Model. It is possible to note that the structure of the DSP application follows the implementation rules established by Symbian OS as it was point out in section 6.3 (Symbian Software Structure in Nokia Devices). In fact, DSP Application contains the main classes; CTest2App, CTest2Document, CTest2AppUi and CTest2Container. Additionally, it is observable that CTest2App inherits from CEikApplication, CTest2Document inherits from CEikDocument and CTest2AppUi inherits from CEikAppUi. Additionally, the model/engine class is represented by several subclasses each one executing one role in the whole system. The UseCase and the flow diagram of the application can be seen in Annex 5 – DSP Application Use Case and Annex 2 – DSP Application Flow Diagram. The several subclasses that compound the model/engine are enumerated as follows:

CWavCreator CRecordTimed CWavReader CDSPProcessor TMatrix CWavWriter CSettingsDialog CSendAppUi

These classes are the heart of this project because they execute the main functions inside the application:

7.3.1 CWavCreator It is a Symbian C class derived from CBase and MMdaObjectStateChangeObserver, its main purpose is to create a wav file with a variable duration (defined by the user). The outcome of this class is a wav file named YYYYMMDD-HHmmSS.wav where YYYY is the year; MM, the moth; DD, the day of the month; HH the hour in 24-hour format; mm the minutes and SS corresponds to the seconds.

7.3.2 CRecordTimer This is a Symbian C class derived from CActive which create thread to record a wav file from the audio input, either embedded microphone or external handsfree device. It uses CMdaAudioRecorderUtility to create the wav file.

7.3.3 CWavReader

Page 35: Digital Signal Processing Using Symbian C++ in Embedded Systems

35 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

This class is in charge to read the wav stored in the memory of the device and extract the information related to it, like Frequency Sampling, Fs; Number of bits per samples, BPS; and the length of data N. Once the information is read it is converted to a TMatrix instance which is owned by CTest2AppUi. CWavReader is derived from CBase.

7.3.4 CDSPProcessor This class is one of the most important classes of the whole development. It is derived from CBase and it is in charge of the calculation of the FFT and inverse FFT. Additionally, it filters the signal according to the settings defined by the user. The filter used in this application is a spectral filter, hence the system has access to spectral content of the signal. The FFT algorithm used is a 2-radix FFT as it is shown in Annex 1 – FFT Code.

7.3.5 TMatrix TMatrix is a T class which contains the information of the data being processed. It has methods to write itself in a text file. The data contained in this class is complex. Additionally, it has the CPlot methods that allow it to be plotted in the screen.

7.3.6 CWavWriter This class creates a wav file as a final outcome of the processing of the data. The information is taken from the TMatrix instance which is used as an input parameter for the creator method.

7.3.7 CSettingsDialog CSettingsDialog is a class derived from CEikDialog and it is used to allow the user to set up the parameter of the application. These parameters are: Output File: Allows the user to choose between

7.3.8 CSendAppUi This is a API supplied by Nokia as part of their SDK and this class is used to execute operations of sending messages through either Email, MMS and Bluetooth.

Page 36: Digital Signal Processing Using Symbian C++ in Embedded Systems

36 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

7.4 Screen Shots of the application Annex 8 – Screen shots of DSP Application shows different screen shots taken from emulator and from the nokia device. In order to start using DSP application, the user needs select the DSP icon which appears in the desktop as it can be seen in Figure 21. The code application can be obtained under the following links ([email protected], [email protected] ).

Figure 21: Desktop Icon of DSP Application. (Photo from the target device)

Page 37: Digital Signal Processing Using Symbian C++ in Embedded Systems

37 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

8 Conclusions The development of the present project clearly gave evidence that theory can be followed in the practice in relation with the DSP processing techniques. In fact, the DSP algorithms designed in theory for this project were implemented by softwares routines that worked all of the time. The development process of the Symbian C++ application took many working days because of the set of rules that must be followed to develop for Symbian devices. However, once, as developer engineer, I was used to them and obtained familiarity to the development tools, this process was more enjoyable focusing in the main role of the application. The complexity of the DFT led to the development of algorithms in order to improve efficiency in the calculations. It is widely demonstrated that the complexity of the calculation of the DFT is reduced because of the cyclic redundancies in the twiddle factor ( m

NW ). One of the important key points in the FFT algorithm implemented is that the properties and characteristics of the DFT apply straight forward to the FFT. The outcome of the DSP project could be used as a starting point for another project initiative that will have to process the signal obtained. Because the main job in process the signal is already done, hence other future developments do not have to start from scratch.

Page 38: Digital Signal Processing Using Symbian C++ in Embedded Systems

38 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

9 References

Babin S., 2006, Developing Software for Symbian OS, An Introduction to Creating

Smartphone Applications in C++, Jhon Wiley & Sons, Ltd, West Sussex, England

Cooley J. W., Tukey J. W., 1965, An algorithm for the machine computation of complex

Fourier series. Mathematical computations, 19:297-301, April 1965.

‘cplusplus.com – The C++ Resources Network’, www.cplusplus.com, 2007/08/01.

Cristi R., 2004, Modern Digital Signal Processing, Thomson Learning, Pacific Grove, USA.

‘Designing C++ Applications For the Nokia 7710 device’, 2004, www.forum.nokia.com.

Harrison, R., 2004, Symbian OS C++ for Mobile Phones, John Wiley & Sons, Ltd, West Sussex,

England.

Hussain Z. M., 2007, Digital Signal Processing, Lecture Notes EEET2113, EEET1469, EEET1416,

EEET1123, RMIT University, School of Electrical and Computer Engineering, Melbourne,

Australia.

Ingle V.K., Proakis J. G., Digital Signal Processing Using Matlab, Second Edition, Thomson,

Toronto, Canada

Jones, D. L., 2006, Decimation in Time (DIT) Radix-2 FFT,

www.cnx.rice.edu/content/m12016/latest/

Lai, E., 2004, Practical Digital Signal Processing for Engineers and Technicians, Elsevier,

Burlington, USA.

Linn, P., Fuerst, W., 1999 Introductory Digital Signal Processing with Computer Applications,

Second Edition, John Wiley, New York, USA

Lockhart G. B., Cheetham B. M. G. 1989, Basic Digital Signal Processing, Butterworths,

Norwich, England.

Lyons, R. G., 2004, Understanding Digital Signal Processing, Second Edition, Prentice Hall,

New Jersey, USA.

‘Nokia 7710: Getting Started with C++ Application Development’, 2006

http://www.forum.nokia.com/main/resources/technologies/symbian/index.html, Nokia

Forum, 2007/08/01.

McClellan J. H., Schafer R. W., Yoder M. A., 2003, Signal Processing First, Prentice Hall, New

Jersey, USA.

Page 39: Digital Signal Processing Using Symbian C++ in Embedded Systems

39 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Sales, J., 2005, Symbian OS Internals, Real-time kernel programming , John Wiley & Sons, Ltd.

West Sussex, England.

Symbian, Symbian Developer Network, http://www.symbian.com/developer/index.html,

2007/08/01.

Page 40: Digital Signal Processing Using Symbian C++ in Embedded Systems

40 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 1 – FFT Code The following code calculates the FFT for any input sequence with N values where n is a power of 2i.(Jones, 1992, http://creativecommons.org/licenses/by/1.0).

void fft(int n, int m, double *x, double *y) { int i,j,k,n1,n2; double c,s,e,a,temp1,temp2; j = 0; /* bit reversal */ n2 = n/2; for (i=1; i < n - 1; i++) { n1 = n2; while ( j >= n1 ) { j = j - n1; n1 = n1/2; } j = j + n1; if (i < j) { temp1 = x[i]; x[i] = x[j]; x[j] = temp1; temp1 = y[i]; y[i] = y[j]; y[j] = temp1; } } n1 = 0; /* FFT Calculation*/ n2 = 1; for (i=0; i < m; i++) { n1 = n2; n2 = n2 + n2; e = -6.283185307179586/n2; a = 0.0; for (j=0; j < n1; j++) { c = cos(a); s = sin(a); a = a + e; for (k=j; k+n1 < n; k=k+n2) { temp1 = c*x[k+n1] - s*y[k+n1]; temp2 = s*x[k+n1] + c*y[k+n1]; x[k+n1] = x[k] - temp1; y[k+n1] = y[k] - temp2; x[k] = x[k] + temp1; y[k] = y[k] + temp2; } } } return EXIT_SUCCESS; }

Figure 22: FFT Code

Page 41: Digital Signal Processing Using Symbian C++ in Embedded Systems

41 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 2 – DSP Application Flow Diagram

[Start App(DSP)]

Initial Conditions

[User Selection]

[Settings]

[Output]

File Output

[Filter]

Filtering

[Duration]

Duration

[OK Cancel]

[New File]

New *wav File

[File Created]

Select Process

[Process File]

Open *.wav File

[Wav File Opened]

[Info obtained (Fs, Bits, N)]

Extract, Fs, N, Bits

Calculate FFT

[FFT Calculated]

Filtering

[Data Filtered]

Create FFT File

[FFT File Created]

Calculate Inverse FFT

[iFFT Created]

Create Data File

[Data File Created]

Plot

[Data Plotted]

[Tx email]

send email

[Tx MMS]

send MMS

[Use Bluetooth]

Bluetooth

[Transmitted] [Transmitted]

[Exit]

Mobile DSP ProcessingUsing Symbian C++ on

Embedded Systems

[User SelectsNew File or

Change Settings]

Figure 23: DSP Application Flow Diagram

Page 42: Digital Signal Processing Using Symbian C++ in Embedded Systems

42 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 3 – Application UML Model

+NewL(inout aRect : const TRect, in aAppUi : CTest2AppUi*) : CTest2Container *+NewLC(inout aRect : const TRect, in aAppUi : CTest2AppUi*) : CTest2Container *+~CTest2Container()+PrintLineL(inout aText : const TDesC)+OfferKeyEventL(inout aKeyEvent : const TKeyEvent, in aType : TEventCode) : TKeyResponse+Draw(inout aRect : const TRect)+CountComponentControls() : TInt+ComponentControl(in aIndex : TInt) : CCoeControl *-ConstructL(inout aRect : const TRect)-CTest2Container(in aAppUi : CTest2AppUi*)-SizeChanged()

-iListBox : CEikTextListBox *-iMessageList : CDesCArrayFlat *-iMsgIndex : TInt-iOutputText : HBufC16 *-iAppUi : CTest2AppUi *

CTest2Container

+ConstructL()+CTest2AppUi()+~CTest2AppUi()+Matrix() : TMatrix *+Plot() : TBool+HandleCommandL(in aCommand : TInt)+DynInitMenuPaneL(in aResourceId : TInt, in aMenuPane : CEikMenuPane*)+StoreL(inout aStore : CStreamStore) : TStreamId+RestoreL(inout aStore : const CStreamStore, in aStreamId : TStreamId)+SendFileAsAttachmentL()-ExternalizeL(inout aStream : RWriteStream)-InternalizeL(inout aStream : RReadStream)

-iDisplayState : TDisplayState-iAppContainer : CTest2Container *-iWavCreator : CWavCreator *-iWavReader : CWavReader *-iWavWriter : CWavWriter *-iFileName : HBufC16 *-iDSPProcessor : CDSPProcessor *-iFs : RFs-iFHigh : TReal-iFLow : TReal-iCreateFFTFile : TBool-iRecordTime : TUint-iCreateDataFile : TBool-iFilter : TBool-iDuration : TInt-iRemoveDC : TBool-iPassword : TBuf16<KPasswordLength>-iSettingsDialog : CSettingsDialog *-iSendAppUi : CSendAppUi *-iPoints : CArrayFix<TPoint> *-iPlot : TBool+iTMatrix : TMatrix *

CTest2AppUi

External Classes::CEikAppUiExternal Classes::CEikDocument

+NewL(inout aApp : CEikApplication) : CTest2Document *+NewLC(inout aApp : CEikApplication) : CTest2Document *+~CTest2Document()+RestoreL(inout aStore : const CStreamStore, inout aStreamDic : const CStreamDictionary)+StoreL(inout aStore : CStreamStore, inout aStreamDic : CStreamDictionary)+OpenFileL(in aDoOpen : TBool, inout aFilename : const TDesC, inout aFs : RFs) : CFileStore *+CreateAppUiL() : CEikAppUi *-CTest2Document(inout aApp : CEikApplication)-ConstructL()

-iTest2AppUi : CTest2AppUi *CTest2Document

+OpenIniFileLC(inout aFs : RFs) : CDictionaryStore *#CreateDocumentL() : CApaDocument *#AppDllUid() : TUid

CTest2App

External Classes::CEikApplication

+KPI : TReal = 3.14159265358979324«utility»Utility::DSPProcessor

+KAlmostZero : TReal = 0.00005+KLineBufferLength : TInt = 38+KArrayGranularity : TInt = 100+KBufferLength : TInt = 2048

«utility»Utility::Matrix

+KMinimumDuration : TInt = 3+KMaximumDuration : TInt = 10+KIdealDuration : TInt = 5

«utility»Utility::SettingsDialog+KIntervalRecord : TInt = 5000000+KLengthFileName : TUint = 19

«utility»Utility::WavCreator

+KStandardFormatChunkLen : TInt = 16+KChunkHeaderLen : TInt = 8+KChunkDataHeaderLen : TInt = 8+KFormat16Bit : TInt = 16+KFormatMono : TInt = 1+KDataFormat : TInt = 1+KBlockAlign : TInt = 2+KConversionFactor32768 : TReal32 = 32768.0

«utility»Utility::WavReader

+KDataWriteLen : TInt = 4096«utility»Utility::WavWriter

1

Figure 24: Application UML Model

Page 43: Digital Signal Processing Using Symbian C++ in Embedded Systems

43 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 4 – Model/Engine UML Model.

Page 44: Digital Signal Processing Using Symbian C++ in Embedded Systems

44 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 5 – DSP Application Use Case

CaptureInformation

User

Sensor

NewFile

SendInformation

Start

«uses»

ReadWavFile«uses»

GetFs

GetBPS

«uses»

«uses»

GetN

«uses»

ProcessSignal

DSP Application

«uses»

GetFFT

FilterSignal

«uses»

«uses»

PlotSignal

«uses»

GetInverseFFT

«uses»

TransmitSignal

«extends»

WriteWavFile «uses»

WriteFFTFile

WriteDataFile

«extends»

«extends»

TxBluetooth TxEmail TxMMS

«extends» «extends» «extends»

Figure 25: DSP Application Use Case

Page 45: Digital Signal Processing Using Symbian C++ in Embedded Systems

45 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 6 – ECG Diagram Circuit

Figure 26: ECG Circuit Used for testing. Device supplied by RMIT

Page 46: Digital Signal Processing Using Symbian C++ in Embedded Systems

46 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 7 – ECG Device Supplied by RMIT

Figure 27: ECG Circuit Supplied by RMIT. Its circuit drawing can be seen inFigure 26.

Page 47: Digital Signal Processing Using Symbian C++ in Embedded Systems

47 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Annex 8 – Screen shots of DSP Application

Figure 28: DSP Started

Figure 29: Option to Create New File

Figure 30: New File Created

Page 48: Digital Signal Processing Using Symbian C++ in Embedded Systems

48 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Figure 31: Signal Processed

Figure 32: Signal Processed using ECG input

Figure 33: Signal Processed using ECG input. (Photo from the target device)

Page 49: Digital Signal Processing Using Symbian C++ in Embedded Systems

49 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Figure 34: Selection File to Transmit

Figure 35: Send data using three different options.

Figure 36: Selection to other device to transmit the signal using Bluetooth. (Photo from the target device)

Page 50: Digital Signal Processing Using Symbian C++ in Embedded Systems

50 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering

Figure 37: Settings Menu - Output files

Figure 38: Filtering Options

Figure 39: Setting Menu - Duration of the WAV recording

Page 51: Digital Signal Processing Using Symbian C++ in Embedded Systems

51 of 51 Melbourne, 19th November, 2007

EEET1237 Minor Thesis Computer Engineering Supervisor: A/Prof. Dinesh Kumar

DSP Using Symbian C++ in Embedded Systems Wilson Castillo ([email protected])

RMIT University © 2007 School of Electrical and Computer Engineering