01+2*345(,$*67894:4)4%(* ,(2*...

80
Departamento de Engenharia Electrotécnica Development of a Portable PV1fed Signal Acquisition and Processing Device and an Application to Human Heart Sound1based Diagnosis Projecto apresentado para a obtenção do grau de Mestre em Automação e Comunicações em Sistemas de Energia Autor Jérôme Nameche Orientadores Fernando Ferreira, Fernando Lopes Instituto Superior de Engenharia de Coimbra Co1Orientadores Pedro Amaro, Marco Silva Instituto Superior de Engenharia de Coimbra Coimbra, Setembro, 2011

Upload: others

Post on 21-Jan-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Departamento**de*Engenharia*Electrotécnica*

Development*of*a*Portable*PV1fed*Signal*Acquisition*and*Processing*Device*and*an*Application*to*Human*

Heart*Sound1based*Diagnosis

**Projecto*apresentado*para*a*obtenção*do*grau*de*Mestre*em*Automação*

e*Comunicações*em*Sistemas*de*Energia**

*

Autor*Jérôme*Nameche*

*Orientadores*

Fernando*Ferreira,**Fernando*Lopes*Instituto*Superior*de*Engenharia*de*Coimbra*

*Co1Orientadores*

Pedro*Amaro,**Marco*Silva*Instituto*Superior*de*Engenharia*de*Coimbra*

****

Coimbra,*Setembro,*2011*

Page 2: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

“Development of a Portable PV-fedSignal Acquisition and Processing Device

and an Application to Human HeartSound-based Diagnosis”

Jérôme Nameche

September 19, 2011

Page 3: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Acknowledgments

My first acknowledgements go to my project supervisors Professor Fernando Ferreira, Pe-dro Amaro, Fernando Lopes and Marco Silva for their guidance, support and availabilityalong my stay in their Institute, the rest of the Electrical Engineering Department andDalia Pires from the International Relations Department. I would like to thank as wellDr. Eduardo Antunes from Santa Marta hospital (Lisboa) for giving me the opportunityto test my device on diseased patients and for answering to lot of my questions.

A specific acknowledgment goes to my Academic Supervisor, Professor Jacques Tichonand to his address book without whom I could never accomplish this erasmus programin Portugal and work on this exciting project. Thanks to Hélène Stievenart from ourInternational Relations department looking after all the administrative forms to makethis experience possible.

Then, I would like to thank many people from Coimbra, who made my everyday lifeeasier and sweeter (Luis Pedro Lemos, Sonia Fiuza, João Seabra, Anthony Brissot,...)

My last acknowledgements go to my parents who have always supported my choices.And last but not least, thanks to my belgian neighbor Marc Gerin, who was really helpfulin advice and who lent me precious hardware.

2

Page 4: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Resumo

O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP genérico portátilde baixo custo com vista a adquirir e processar sinais de sensores externos. Para levara cabo este projecto é fulcral uma minimização do consumo de energia permitindo as-sim uma maior autonomia do aparelho. Esta poupança energética pode ser conseguidaatravés do uso de energia solar combinada com dispositivos IC e software optimizado.Este trabalho tem em vista seleccionar a melhor combinação entre baterias, supercon-densatores e painel solar.

A finalidade do projecto é criar um dispositivo para aplicação médica, nomeadamente,a análise do sinal sonoro do batimento cardíaco com vista ao diagnóstico do estado docoração permitindo a distinção entre um coração são e um doente. O diagnóstico serábaseado nas Transformadas Rápidas de Fourier das ondas sonoras adquiridas com ummicrofone convencional acoplado a um estetoscópio.

Palavras-Chave: Processamento Digital de Sinal, Dispositivo de Baixo Custo, EnergiaSolar, Baixo Consumo, Energético, Diagnostico do batimento Cardiaco, Transfor-mada Rapida de Fourier.

4

Page 5: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Résumé

Le but de ce project est de développer un appareil portatif à prix réduit capable de pouvoiranalyser et traiter des signaux digitaux qu’il acquiert à partir de ses différents capteurs.La réduction de la consommation de l’appereil en vue d’augmenter son autonomie estprimordiale. En vue d’obtenir cette autonomie prolongée, un dispositif d’alimentationsolaire sera mis au point. Une étude sera menée afin de sélectionner quelle est la meilleurecombinaison entre cellule photovoltaïque, batterie et supercapacité.

L’application développée dans le cadre de cette étude est d’ordre médical. L’appareilmis au point doit être capable de récupérer et traiter les signaux sonores du coeur hu-main en vue de proposer un diagnostique sur l’état de santé de ce dernier, normal versusanormal. Le diagnostique est basé sur la transformée de Fourier du signal sonore préal-ablement acquis à l’aide d’un microphone et d’un stethoscope.

Keywords: Digital Signal Processing, Appareil à Prix Réduit , Energie Solaire, FaibleConsommation, Diagnostique de Battement Cardiaques, Analyse Spectrale.

5

Page 6: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Abstract

The aim of this project is to develop a portable low-cost general purpose DSP1 device inorder to acquire and process signals from external sensors. The device power consumptionminimization, in order to extend its autonomy is a key point. To obtain this largeautonomy, the power source is the solar energy, combined with efficient integrated circuitdevices and optimized software. A study will be conducted to select which is the bestcombination between batteries, supercapacitors and solar panel.

In this study, the developed application is intended to be used for medical purposes.The designed device have to analyze the human heart sound’s signal in order to allowthe diagnosis of the heart health, normal vs abnormal. The diagnosis is based on theFast Fourier Transform of the wave sound form acquired with a conventional microphonecoupled with a stethoscope lead.

Keywords: Digital Signal Processing, Low-Cost Device, Solar Energy, Low Power Con-sumption, Heart Beating Diagnosis, Fast Fourier Transform.

1Digital Signal Processing

3

Page 7: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Contents

1 Introduction 101.1 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.2 Context and motivations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101.3 Aim and schedule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10

2 The Human heart 112.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.2 Heart Anatomy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.3 Auscultation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132.4 Heart Sound . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152.5 Heart diseases and Murmurs . . . . . . . . . . . . . . . . . . . . . . . . . . 18

2.5.1 Valvular heart diseases . . . . . . . . . . . . . . . . . . . . . . . . . 192.5.2 Cardiomyopathy - heart muscle disease . . . . . . . . . . . . . . . . 202.5.3 Coronary Artery Disease . . . . . . . . . . . . . . . . . . . . . . . . 212.5.4 Heart murmurs characterization . . . . . . . . . . . . . . . . . . . . 21

2.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24

3 Spectral analysis 263.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.2 Adobe Audition Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . 263.3 Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 303.4 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31

4 The processing device 324.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.2 Hardware . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 324.3 Power Supply . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37

4.3.1 Power supply solution for the developed device . . . . . . . . . . . 374.3.2 Power supply solution for a 24h/24 autonomous acquisition device 40

4.4 Cost of the device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 424.5 Software . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43

4.5.1 Initialization: . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444.5.2 Filter design . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 444.5.3 The main Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

4.6 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

6

Page 8: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Contents Contents

5 Tests and Results 485.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 485.2 Test 1 - Precise Frequencies . . . . . . . . . . . . . . . . . . . . . . . . . . 495.3 Test 2 - Normal Heart sound . . . . . . . . . . . . . . . . . . . . . . . . . 505.4 Test 3 - Diseased Heart sound . . . . . . . . . . . . . . . . . . . . . . . . . 525.5 Test 4 - FFT from oscilloscope . . . . . . . . . . . . . . . . . . . . . . . . 525.6 Test 5 - 4 auscultation areas . . . . . . . . . . . . . . . . . . . . . . . . . . 535.7 Real case tests . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

5.7.1 Define a normal heart sound pattern . . . . . . . . . . . . . . . . . 545.7.2 Diseased patients . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54

5.8 Matlab . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 565.9 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58

6 Conclusion 60

Bibliography 60

Annex A - Spectral analysis - FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 63Annex B - Schematic Design. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66Annex C - PCB - Printed Card Board . . . . . . . . .. . . . . . . . . . . . . . . . . . . 67Annex D - Components List and prices . . . . . . . .. . . . . . . . . . . . . . . . . . . 68Annex E - Source Code. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69

7

Page 9: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

List of Figures

2.1 Heart Anatomy[1] . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112.2 Conduction System of the heart [1] . . . . . . . . . . . . . . . . . . . . . . 122.3 Anterior view of an human heart during his two operating phases[1] . . . . 132.4 A general purpose stethoscope . . . . . . . . . . . . . . . . . . . . . . . . . 142.5 The four auscultatory sites[2] . . . . . . . . . . . . . . . . . . . . . . . . . 152.6 Phonocardiogram of a complete Heart Sound[3] . . . . . . . . . . . . . . . 152.7 ECG signal is not Heart Sound signal[4] . . . . . . . . . . . . . . . . . . . 162.8 Heart diseases per 100 000 inhabitants in 2004 [5] . . . . . . . . . . . . . . 192.9 Phonocardiograms of normal and abnormal heart sounds . . . . . . . . . . 202.10 Summary of normal and abnormal heart sound[6] . . . . . . . . . . . . . . 222.11 Temporal heart sound with mumur [2] . . . . . . . . . . . . . . . . . . . . 222.12 Different possible shapes of a murmur[2] . . . . . . . . . . . . . . . . . . . 232.13 Causes of turbulences inside vessels[2] . . . . . . . . . . . . . . . . . . . . 24

3.1 Adobe Audition - Spectral Tools of a normal heart sound . . . . . . . . . 273.2 Adobe Audition - Spectral Tools of a hypertrophic cardiomyopathy . . . . 273.3 4 Fast Fourier Transform of Normal Heart Signal [0;500hz][0;-120dB][7] . . 293.4 Fast Fourier Transform of Diastolic Murmurs [0;500hz][0;-120dB] . . . . . 293.5 Fast Fourier Transform of Systolic Murmurs [0;500hz][0;-120dB] . . . . . . 293.6 Data charts from a patient with 50-75% artery stenosis. Graph A shows

pre-angiogram data, graph B shows post-angioplasty data.[8] . . . . . . . 303.7 Matlab schema block for an FFT computation of a audio wave file . . . . 303.8 Result of the Matlab FFT computation (left) compared to FFT from adobe

Audition for the same heart sound . . . . . . . . . . . . . . . . . . . . . . 31

4.1 Connection between the electret microphone and the stethoscope . . . . . 324.2 Typical frequency response curve of the Kingstate Microphone . . . . . . . 334.3 Schematic of the acquisition part . . . . . . . . . . . . . . . . . . . . . . . 334.4 Heart sound at the end of the amplification stage . . . . . . . . . . . . . . 354.5 Schematic of the processing and debugging part of the device . . . . . . . 364.6 Hardware schema block . . . . . . . . . . . . . . . . . . . . . . . . . . . . 374.7 Schematic of the power supply chain of the device . . . . . . . . . . . . . . 384.8 dsPIC33fj64MC802 - Power Consumption in operating current . . . . . . . 394.9 Yearly irradiation on a optimaly-inclined south oriented photovoltaic module[9] 414.10 Schema block of the developed software . . . . . . . . . . . . . . . . . . . 434.11 dsPIC FD Lite Version - resulting window after configuring a 50Hz band-

stop filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45

8

Page 10: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

List of Figures List of Figures

4.12 With and without filter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46

5.1 Connection between the stethoscope and the headphone[10] . . . . . . . . 485.2 Frequency response of the headphone Sennheiser HD25-1[10] . . . . . . . . 485.3 Test1 - FFT of 35-65-95-125-155-185-215-245Hz by the acquisition device . 495.4 FFT of the stethoscope acquiring nothing . . . . . . . . . . . . . . . . . . 505.5 FFT of 3 normal heart sounds via the headphone and the acquisition device 505.6 Part of ADC result of my normal heart sound . . . . . . . . . . . . . . . . 515.7 3 FFT result of a normal heart sound acquired on a body . . . . . . . . . 515.8 6 Diseased FFT Heart Sound by the device (source of the heart sound)[7] 525.9 Comparison of a normal and Aortic stenosis heart sound - FFT from Os-

cilloscope . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 535.10 FFT of my heart from the 4 auscultation area . . . . . . . . . . . . . . . . 535.11 FFT of my heart from the 4 auscultation area . . . . . . . . . . . . . . . . 545.12 ADC of an aortic stenosis . . . . . . . . . . . . . . . . . . . . . . . . . . . 555.13 FFT of aortic stenosis on real diseased patients . . . . . . . . . . . . . . . 555.14 FFT of a heart with proproject generating murmurs . . . . . . . . . . . . 565.15 3 Normal heart sound analyzed by Matlab from headphone . . . . . . . . 575.16 3 Diseased sound analyzed by Matlab from headphone[7] . . . . . . . . . . 575.17 My Normal heart sound analyzed by Matlab . . . . . . . . . . . . . . . . . 58

9

Page 11: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

1 Introduction

1.1 Foreword

This project was accomplished as part of an Erasmus exchange program within ISEC(Instituto Superior de Engenharia de Coimbra). The subject was proposed by the hostinstitute (ISEC) and welcomed with open arms.

1.2 Context and motivations

Heart diseases have become one of the major health problems in most of the developingcountries and much worst in developed countries. Everyone doesn’t necessary have adoctor able to analyze heart sound close at hand or the money to afford a medical checkup.Heart sound checkup requires time, a quiet environment and an efficient doctor. Let’simagine, in a developing country, a makeshift hospital trying to checkup village aftervillage. The competent doctor will not have time to listen all hearts. Therefore, havinga cheap and quick heart diagnosis tool able to be handled by nurses can be a solutionto check-up everyone, then the doctor will only have to listen to the diseased heartsdiagnosed by the electronic device.

In this last 20 years, electronic technologies and microprocessors evolved really quicklywith a price decreasing year after year. Developing a device able to analyze heart soundsas a first resource can be a solution to save lives by increasing the number of analyzedpatients.

1.3 Aim and schedule

The goal of this project is to achieve a low-cost electronic device powered with solar energyable to give a basic human heart health diagnosis (normal vs abnormal) by analyzingthe frequency spectrum of the heart sounds. The electronic device will be based on anon-intrusive method, that everyone can handle for a first preventive use.

In a first part, this study will present a brief introduction about the human heart, theheart sounds and the heart diseases. Next, spectral analysis of the heart sounds basedon wave recording will be reviewed.

Then, the designed device responsible for analyzing the heart sounds will be presentedin detail. The study will end with real test cases before concluding and presenting theperspectives.

10

Page 12: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2 The Human heart

2.1 Introduction

In this chapter, basic information about the heart will be explained to understand the ba-sis of the human heart’s anatomy and mechanisms in order to have a good comprehensionof the rest of this study. Heart sounds and murmurs will be reviewed and explained.

2.2 Heart Anatomy

The cardiovascular ensemble is made of the heart and circulatory system. The heartworks as a pump that pushes blood towards the organs, tissues, and cells of the body.The blood delivers oxygen and nutrients to each cell and removes the carbon dioxide andwaste remaining produced by those cells. It is carried from the heart to the rest of thebody through a complex network of arteries, arterioles, and capillaries and comes backto the heart through venules and veins.

Figure 2.1: Heart Anatomy[1]

11

Page 13: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.2. HEART ANATOMY CHAPTER 2. THE HUMAN HEART

The heart is composed of four valves alternatively opening and closing to let the bloodflow in one direction only. Heart valves are separated in two categories:

• Atrioventricular valves:

– The mitral valve controls the oxygen-rich blood from left atrium into leftventricle.

– The tricuspid valve regulates the blood flow from right atrium to right ven-tricle.

• Semilunar valves:

– The aortic valve opens the way for oxygen-rich blood to pass from left ven-tricle into the aorta.

– The pulmonary valve lets the blood flow from the right ventricle into thepulmonary arteries.

Figure 2.2: Conduction System of the heart [1]

Electrical impulses from the heart muscle (the myocardium) cause contractions. Thiselectrical signal begins in the sinoatrial (SA1) node, located at the top of the right atrium.The SA node is sometimes called the heart’s "natural pacemaker." An electrical impulsefrom this natural pacemaker travels through the muscle fibers of the atria and ventricles,causing them to contract. Although the SA node sends electrical impulses at a certainrate, this rate may still change depending on physical demands, stress, or hormonalfactors.

1Sinoatrial

12

Page 14: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.3. AUSCULTATION CHAPTER 2. THE HUMAN HEART

Figure 2.3: Anterior view of an human heart during his two operating phases[1]

The heart operates in two pumping phases:

• The diastole phase is the longer of the two. The heart’s SA node sends out anelectrical signal that causes the atria to contract. This contraction pushes bloodthrough the tricuspid and mitral valves into the resting lower chambers (the rightand left ventricles).

• The systole phase begins when the ventricles are full of blood. The electricalsignals from the SA node travel along a pathway of cells to the ventricles, causingthem to contract. As the tricuspid and mitral valves shut tight to prevent a backflow of blood, the pulmonary and aortic valves are pushed open. While blood ispushed from the right ventricle into the lungs to pick up oxygen, oxygen-rich bloodflows from the left ventricle to the heart and other parts of the body.

After blood moves into the pulmonary artery and the aorta, the ventricles relax, andthe pulmonary and aortic valves close. The lower pressure in the ventricles causes thetricuspid and mitral valves to open, and the cycle begins again.

The heart normally beats about 60 to 80 times a minute when the human is at rest, butthis can vary. As human get older, the resting heart rate rises. Also, it is usually lowerin people who are physically fit. The heart does not work alone. The brain tracks theconditions around the body; climate, stress, and level of physical activity then adjuststhe cardiovascular system to meet those needs.

2.3 Auscultation

There are several techniques to analyze and identify heart diseases. For example: checkthe heartbeat pressure, make an ECG2, an X-Ray analyze, an echocardiogram, some

2Electrocardiogram

13

Page 15: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.3. AUSCULTATION CHAPTER 2. THE HUMAN HEART

physical tests, an ultrasound or heart sound listening. Each technique has its advan-tages and is more able to detect some heart’s disorder than others. Techniques can becharachterized as invasive3 or non-invasive.

In this study, the heart sound listening technique is chosen which is a non-invasivetechnique. This auscultation method use a stethoscope.

Figure 2.4: A general purpose stethoscope

The stethoscope is composed of two parts :

• The bell: it is the bigger probe part, especially efficient for low frequency listeningand used to listen the heart sound during medical auscultation.

• The diaphragm: filters out low pitches and makes the higher-pitched murmurseasier to detect. Not really used during medical auscultation.

During a stethoscope auscultation, information can be gathered about:

• Heart rate

• Valves functioning ( stenosis4, regurgitation5,...)

• Anatomical defects ( atrial septal defects, ventricular septal defect, ...)

3Invasive technique refers to a diagnostic procedure involving the entry of an instrument into the body.Whilst, non-invasive technique does not require any incision into human body or removal of tissue.

4Stenosis: abnormal narrowing in a blood vessel or other tubular organ or structure.5Regurgitation: or insufficiency is a leaking of heart’s valves that causes blood to flow in the reverse

direction during ventricular diastole.]

14

Page 16: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.4. HEART SOUND CHAPTER 2. THE HUMAN HEART

Figure 2.5: The four auscultatory sites[2]

The amplitude of the heart sound waveform depends on where the heart signal iscaught. As shown in Figure (2.5), there are four main auscultation areas. The louderheart sound detected will be associated to the closest valve from the auscultation point.

A study [12] has demonstrated that, if only the spectral details of heart sound areof interest, then the heart sounds recorded from one of the four valid auscultary areas(Aortic, Pulmonary, Mitral and Tricuspid) give the same result. This is a good news forthis study, anyway this information will be checked for the developed device.

2.4 Heart Sound

During the systolic and the diastolic, phases of the cardiac cycle, audible sounds areproduced, due to the:

• Opening and closing of the heart valves

• Flow of blood in the heart

• Vibration of the heart muscles

Figure 2.6: Phonocardiogram of a complete Heart Sound[3]

15

Page 17: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.4. HEART SOUND CHAPTER 2. THE HUMAN HEART

Usually, four heart sounds are generated in a cardiac cycle. The first and the secondheart sounds can be easily detected in a normal heart via a stethoscope placed on anadequate area of the chest. The third heart sound is audible in children and adolescentsbut not in most adults. The fourth heart sound is seldom audible in normal individualsthrough the conventional mechanical stethoscopes but can be detected by sensors withhigh sensitivity, such as electronic stethoscopes and phonocardiography systems.

Sounds other than these four, called murmurs, are abnormal sounds result-ing from valve problems, or sounds made by artificial pacemakers or pros-thetic valves.

Figure 2.7: ECG signal is not Heart Sound signal[4]

Note: Heart sound waveform doesn’t have to be confused with an electrocardiogram(ECG) Figure (2.7) signal which is generated by the electrical activity of theheart (cfr: SA node Chap.(2.2)) and caught with multiple electrodes.

Figure 2.7 illustrates how the four heart sounds are correlated to the electrical andmechanical events of the cardiac cycle.

The first heart sound waveform, named S1 occurs at the onset of ventricular systole.It can be most clearly heard at the apex6 and the fourth intercostal spaces along the leftsternal border. It is characterized by higher amplitude and longer duration in comparisonwith other heart sounds. It has two major high-frequency components that can be easilyheard at bedside. Although controversy exists regarding the mechanism of S1, the most

6Apex: lowest superficial part of the heart. It is directed downward, forward, and to the left, and isoverlapped by the left lung and pleura.

16

Page 18: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.4. HEART SOUND CHAPTER 2. THE HUMAN HEART

compelling evidence indicates that the components result from the closure of the mitraland tricuspid valves and the vibrations set up in the valve cusps, chordate, papillary,muscles, and ventricular walls before aortic ejection [13]. S1 lasts for an average periodof 100–200ms. Its frequency components lie in the range of 10-200Hz[4]. The acousticproperties of S1 are able to reveal the strength of the myocardial7 systole and the statusof the atrioventricular valve’s function. As a result of the asynchronous closure of thetricuspid and mitral valves, the two components of S1 are often separated by a timedelay of 20-30 ms. This delay is known as the (split) in the medical community and is ofsignificant diagnostic importance. An abnormally large splitting is often a sign of heartproblem.

The second heart sound, named S2, occurs within a short period once the ventriculardiastole starts. It coincides with the completion of the T-wave of the electrocardiogram(ECG). These sounds can be clearly heard when the stethoscope is firmly applied againstthe skin at the second or third intercostals space along the left sternal border. S2 consistsof two high-frequency components, one because of the closure of the aortic valve and theother because of the closure of the pulmonary valve. At the onset of ventricular diastole,the systolic ejection into the aorta and the pulmonary artery declines and the risingpressure in these vessels exceeds the pressure in the respective ventricles, thus reversingthe flow and causing the closure of their valves. The second heart sound usually hashigher-frequency components as compared with the first heart sound. As a result of thehigher pressure in the aorta compared with the pulmonary artery, the aortic valve tendsto close before the pulmonary valve, so the second heart sound may have an audiblesplit. In normal individuals, respiratory variations exist in the splitting of S2. Duringexpiration phase, the interval between the two components is small (less than 30 ms).However, during inspiration, the splitting of the two components is evident. Clinicalevaluation of the second heart sound is a bedside technique that is considered to bea most valuable screening test for heart disease. Many heart diseases are associatedwith the characteristic changes in the intensities or the time relation between the twocomponents of S2. The ability to estimate these changes offers important diagnosticclues.

The third and fourth heart sounds, also called gallop sounds, are low-frequency soundsoccurring in early and late diastole, respectively, under highly variable physiological andpathological conditions. Deceleration of mitral flow by ventricular walls may represent akey mechanism in the genesis of both sounds.

7Cardiac muscles.

17

Page 19: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.5. HEART DISEASES AND MURMURS CHAPTER 2. THE HUMAN HEART

2.5 Heart diseases and Murmurs

Heart diseases describe many heart conditions, they can be native from a birth defect,an infection, a non-healthy life (food, alcohol, tobacco,...) or a bad physical condition.Heart diseases are numerous and documentation doesn’t say every time the same thingsabout classification. The classification proposed below is from the WHO8. Some of themwill be a bit more detailed in the next sections in order to understand how it works andwhich are the most common.

• Rheumatic heart disease: is an inflammatory disease that occurs following aStreptococcus9 infection. the illness typically develops two to three weeks after astreptococcal infection. It generates heart murmurs (carditis or pericarditis). Thisdisease is more present in developing countries because of the leak of antibiotictreatment.

• Hypertensive heart disease: caused by high blood pressure. Heart has to workharder to pump against this pressure. Cardiomegaly10 and irregular pulse are thetwo heart related symptoms.

• Ischaemic heart disease: is a disease characterized by ischaemia (reduced bloodsupply) of the heart muscle, usually due to coronary artery disease (atheroscle-rosis11 of the coronary arteries).

• Cerebrovascular disease: is a group of brain dysfunctions related to disease ofthe blood vessels supplying the brain. Hypertension is the most important cause,it damages the blood vessel. Sustained hypertension permanently changes thearchitecture of the blood vessels making them narrow, stiff, deformed, uneven andmore vulnerable to fluctuations in blood pressure. Narrowed blood vessels can thencause ischaemic stroke.

• Inflammatory heart disease: involves inflammation of the heart muscle and-orthe tissues surrounding it.

8W.H.O. : World health Organization - www.who.int9Streptococcus is a spherical, Gram-positive bacterium.

10Cardiomegaly is a medical condition wherein the heart is enlarged. It is due to dilation or ventricularhypertrophy

11Atherosclerosis is a condition in which an artery wall thickens as a result of the accumulation of fattymaterials such as cholesterol.

18

Page 20: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.5. HEART DISEASES AND MURMURS CHAPTER 2. THE HUMAN HEART

Figure 2.8: Heart diseases per 100 000 inhabitants in 2004 [5]

As showed in Figure 2.8, ischaemic, cerebrovascular and hypertensive heart disease arethe most important.

Note: Heart diseases are a bit interconnected together because, for example, a hyper-tensive heart disease can create a coronary artery deteriration which can involveischaemic disease, a cerebrovascular can also generate ischaemic disease... It’s per-haps why literature about heart diseases classification is a bit confused. Besides,the classification proposed by the WHO doesn’t discern coronary artery, cardio-vascular, cardiomyopathy and valvular diseases as separated categories although itcan be find on others literatures.

Now some main heart diseases will be briefly reviewed.

2.5.1 Valvular heart diseases

Valvular heart problems are generally manifested in one or two ways. Either the valveopenings become too narrow and blood has a difficult time crossing the valves (stenosis)or the valves become incompetent, allowing blood to leak across the valves when theyare supposed to be closed (insufficiency-regurgitation). Because atrioventricular andsemilunar valves function oppositely in the cardiac cycle, the effects of stenosis and insuf-ficiency are different. Stenosis of the semilunar valves causes systolic murmurs. Stenosis

19

Page 21: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.5. HEART DISEASES AND MURMURS CHAPTER 2. THE HUMAN HEART

of the atrioventricular valves causes diastolic murmurs. Then insufficiency of the semilu-nar valves is associated with diastolic murmurs and insufficiency of the atrioventricularvalves causes systolic murmurs.

Figure 2.9: Phonocardiograms of normal and abnormal heart sounds

• Systolic murmurs

– Aortic or pulmonary stenosis : narrowing of the Aortic or pulmonary valvewhich increase the blood pressure and speed through the narrowed valve whichwill cause vibrations and murmurs.

– Mitral or tricuspid regurgitation: the mitral or tricuspid valve doesn’t closecompletely and generate a backflow of blood which will generate high fre-quency sound around left or right atrium.

• Diastolic murmurs

– Aortic or pulmonary regurgitation– Mitral or tricuspid stenosis

• Continuous murmurs

– this murmurs are caused by the abnormal communication between the aortaand the pulmonary which causes the patent ductus arteriousus heart problem,a persitent murmur during diastole and systole.

2.5.2 Cardiomyopathy - heart muscle disease

Dilated cardiomyopathy is the most common form of heart failure. For one of many rea-sons, the heart muscle becomes damaged and weakened. In an attempt to compensate for

20

Page 22: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.5. HEART DISEASES AND MURMURS CHAPTER 2. THE HUMAN HEART

this weakening, the heart muscle stretches, causing the heart (especially the left ventricle)to dilate, or enlarge. So the hallmark of dilated cardiomyopathy is a weakened, enlargedheart. The diagnosis of dilated cardiomyopathy hinges on detecting the enlargement ofthe heart’s chambers, especially the left ventricle. Detecting left ventricular dilation canbest be accomplished using the echocardiogram, or a MUGA scan.

2.5.3 Coronary Artery Disease

Coronary artery disease (CAD) is a condition in which plaques build up in the walls ofthe coronary arteries (the vessels that supply blood to the heart muscle). These plaquescan cause a gradual but progressive narrowing of the artery, and as a result, blood flowthrough the artery becomes more difficult. When the obstruction becomes large enough,the patient may experience angina. Because the heart muscle requires a continuoussupply of oxygen and nutrients to survive, obstruction of a coronary artery rapidly leadsto significant problems (heart attack). In addition to causing obstruction by a gradualincrease in their size, plaques are also subject to sudden rupture, which can produce avery sudden obstruction. The medical conditions caused by the rupture of a plaque arereferred to as Acute Coronary Syndrome (ACS).

Myocardial infarction, or heart attack, is a more dire form of ACS. Here, the rupturedplaque causes a total (or near total) occlusion of the coronary artery, so that the heartmuscle supplied by that artery dies. A heart attack, therefore, is death of heart muscle.The seriousness of a myocardial infarction depend largely on how much heart muscle hasdied. Heart attack can be small or large, depending if a small of large portion of heartmuscles dies.

Note: Coronary artery disease is the most common heart disease in the United Statesand many others countries. This disease often appears as a heart attack. In 2010,an estimated 785 000 Americans had a new coronary attack, and about 470 000had a recurrent attack. About every 25 seconds, an American will have a coronaryevent, and about one every minute will die from one[14]. It could be interesting toknow if it’s possible to detect this serious pathology.

2.5.4 Heart murmurs characterization

It is by analysing the murmurs that the developed device will be able to acquire anddetect abnormality. Murmurs are the result of turbulent blood flow, which produces aseries of abnormal vibrations in the cardiac structure. Heart sounds and murmurs canbe classified as listed below.

21

Page 23: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.5. HEART DISEASES AND MURMURS CHAPTER 2. THE HUMAN HEART

Figure 2.10: Summary of normal and abnormal heart sound[6]

Figure 2.11 represents a heart sound having a murmur during the diastole phase.Murmurs are characterized by a longer but smaller intensity and possess higher frequencythan S1 and S2. This illustration also shows that the closing of the mitral (M1) andtricuspid (T1) valve are a bit shifted like for the aortic (A2) and pulmonary (P2) valve’sclosing.

Figure 2.11: Temporal heart sound with mumur [2]

22

Page 24: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.5. HEART DISEASES AND MURMURS CHAPTER 2. THE HUMAN HEART

Murmurs are characterized by their:

• Intensity (6 grades)

• Duration

• Timing (systolic, diastolic, or continuous)

• Location (mitral, aortic, tricuspid, or pulmonary)

• Transmission (of the murmur to others parts of the heart)

• Quality (musical, vibratory, blowing, etc)[15]

The 6 grades intensity scale are:

1. Very faint, only heard in ideal circumstances

2. Loud enough to be generally heard

3. Heard all over the precordium

4. Loud, with palpable thrill

5. Very loud, with thrill, heard with stethoscope partially off chest

6. Very loud, with thrill, heard without stethoscope near the chest

In addition to classifying murmurs by the location where they are heard, murmurs arealso described by their shape:

• Decrescendo: the murmur starts out at a high intensity and decreases in intensity.This shape is characteristic of aortic and pulmonic regurgitation and occurs as theblood flows backward through a valve that fails to close completely.

• Crescendo-Decrescendo: a crescendo-decrescendo murmur starts out at a lowintensity and increases in intensity. This shape is characteristic of systolic murmurscaused by stenotic valves e.g. aortic or pulmonic stenosis.

• Holosystolic: a holosystolic murmur is present throughout systole. In contrastpansystolic or holosystolic murmurs have a uniform intensity throughout systole.

Figure 2.12: Different possible shapes of a murmur[2]

23

Page 25: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.6. CONCLUSION CHAPTER 2. THE HUMAN HEART

The 5 possible turbulent blood flows are listed below :

• Increased flow through a normal structure (A): may cause turbulence. In-creased flow can occur in a patient who is anemic and can cause an aortic systolicmurmur.

• Stenosis (B): causes obstruction to flow, which in turn causes turbulence and amurmur. Mitral stenosis and aortic stenosis are examples.

• Flow into a dilated chamber (C): can also cause a murmur due to the vortexformation that occurs as the blood flows from a narrower to a larger chamber. Thiscan occur when the aortic valve is of normal size and the aorta is dilated. A relativeconstriction is present and this causes the turbulence and thus the murmur.

• A membrane (D): which vibrates as the fluid flows by, can also cause a murmur.This is the mechanism attributed to the murmur produced when a papillary muscleruptures.

• Flow of blood from a high pressure chamber to a lower pressure chamber(E): as occurs when ventricular septal defects are present.

Figure 2.13: Causes of turbulences inside vessels[2]

As previsously said murmurs are either systolic or diastolic in time and are designatedaccording to the valve area where they are heard. They also are usually transmitted inthe direction of the flow of blood that causes them. For example, the murmur of anaortic insufficiency is better heard at the apex and left sternal border. And regardingthe direction of transmission, the murmur of an aortic stenosis is transmitted to the neckover the carotid arteries.

Mitral valve murmurs are an exception. They are heard well at the apex. It is believedthat this is due to transmission of the murmurs through the papillary muscles.

2.6 Conclusion

This chapter showed that heart diseases and murmurs are numerous and their causescan be various. As far as diseases are a bit interconnected and they are not so easy to

24

Page 26: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

2.6. CONCLUSION CHAPTER 2. THE HUMAN HEART

classify. This chapter evenly showed that all heart diseases can be listen or caught witha stethoscope. However, cardiomyopathy will be better diagnosed by an echocardiogramwhile heart rhythm troubles are better detected via an ECG analysis.

Detectable heart diseases with a stethoscope are mainly appointed as valvular. This isthe dedicated classification for heart murmurs. Thus, the rest of this study will focus onthis classification (mainly: aortic/mitral stenosis or regurgitation). But it has to be keptin mind that other diseases than classified as valvular can eventually generate valvularor blood flow troubles.

25

Page 27: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

3 Spectral analysis

3.1 Introduction

This chapter will focus on a global overview of the spectral analysis study performed tounderstand the difference between normal and diseased heart sounds in order to drawthe border between normal and abnormal heart sounds. The first part of this study wasto collect several heart sounds banks. The result of this research and the references usedfor this study were the following:

• Heart Songs 3 from CardioSource.org - American College of cardiology [7]

• Introduction to Heart Sounds : 3M Littmann educational Cd [2]

• Heart Sound from Pr. D. Kaelber - Case Western Reserve University[6]

• A large number of quality heart sounds with several examples for each murmurs

Afterwards, a suitable software was selected in order to analyze these normal and ab-normal heart sounds in the spectral domain (Adobe Audition). Finally, a comparison ofthe spectral analysis between Adobe Audition results and Matlab software was done inorder to confirm the results.

3.2 Adobe Audition Analysis

Adobe Audition is a digital audio software from Adobe Systems© featuring waveformediting view. This software is able to display time-frequency analysis and a global FFTspectrum of the selected track.

26

Page 28: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

3.2. ADOBE AUDITION ANALYSIS CHAPTER 3. SPECTRAL ANALYSIS

Figure 3.1: Adobe Audition - Spectral Tools of a normal heart sound

Illustration 3.1 shows the two frequency tools windows of a normal heart sound. Thebottom of the first window shows the time-frequency signal. It can be noticed that thefrequency power of the signal is definitely ranged between 0 and 500Hz. The second partof the illustration is the global frequency spectrum tool. It’s the kind of tool and outputthat has to be implemented in the future device. In Adobe Audition, some options areavailable to generate the FFT spectrum such as the number of samples and the type ofwindow to use. The maximum sample value was selected with a Hamming window.

Figure 3.2: Adobe Audition - Spectral Tools of a hypertrophic cardiomyopathy

Figure 3.2 represents a time-frequency signal and a FFT of a hypertrophic cardiomy-

27

Page 29: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

3.2. ADOBE AUDITION ANALYSIS CHAPTER 3. SPECTRAL ANALYSIS

opathy. Compared to the previous figure, the presence of a murmur between S1 andS2 can be clearly noticed on the temporal window. The time-frequency graph informsabout a frequency range of 100-600Hz for this murmur. This raising of the frequencybetween 100 and 600Hz can be also perceived on the last FFT window by a spectrumpower higher than -60dB from 100 to 500Hz. It is not the case of the previous normalheart sound FFT 3.1.

These two illustrations can already indicate that:

• The main spectrum power of the heart sound is included between 0 and 500Hz.The intensity begins to decrease beyond this limit.

• Heart sound with murmurs generates more spectrum power beyond 110/120Hz.

Note: As shown in Figure 3.1 and Figure 3.2, time-frequency analysis is known and thismethod determines which frequencies are present at each particular time. Manystudies were already performed in this area demonstrating that time-frequencyanalysis is able to diagnose and discern heart diseases with murmurs. The low-cost device developed in this project is not based on time-frequency analysis buton global frequency analysis because the goal of the developed device is only tobe able to discern normal vs abnormal heart by only using the global frequencyspectrum.

28

Page 30: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

3.2. ADOBE AUDITION ANALYSIS CHAPTER 3. SPECTRAL ANALYSIS

From now on, only the global FFT spectrum of the heart sounds will be used. Astudy based on the heart sound signals ( .wav files) recorded by the American Collegeof Cardiology [7] was conducted to obtain an overview of several diseased Fast FourierTransforms compared to Fast Fourier Transforms of a normal heart signal.

Figure 3.3: 4 Fast Fourier Transform of Normal Heart Signal [0;500hz][0;-120dB][7]

The normal heartbeats in Figure 3.3 can be characterized by two main peaks around80-90Hz and 245Hz. Around 165Hz the FFT reaches a minimum. The next illustrationsin Figure 3.4 and Figure 3.5 represent the main valvular diseases.

Figure 3.4: Fast Fourier Transform of Diastolic Murmurs [0;500hz][0;-120dB]

Figure 3.5: Fast Fourier Transform of Systolic Murmurs [0;500hz][0;-120dB]

On the graphics of Figure 3.5, it can be easily noticed that murmurs generate a higherfrequency spectrum between 110 and 500Hz. Black horizontal lines were added on eachgraphic (and also on the previous normal heart sounds illustration) to show that frequencylevels higher than 110Hz appear around -60dB (cf. black horizontal line) and lower thannormal heart sounds.

29

Page 31: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

3.3. MATLAB CHAPTER 3. SPECTRAL ANALYSIS

A quick note about coronary artery disease, which is the most common disease:During the research, an US patent [8] was found showing that if a bell curve is iden-

tified in the data between a predefined frequency range (e.g., 50 and 80Hz) with a peakmagnitude greater than a predefined threshold, then the patient is likely to have 50 to99 percent stenosis of the coronary artery. If no bell curve is present, the patient mayhave artery stenosis of less than 50 percent. This study has to be taken into account andreviewed in a upcoming chapter after getting the results obtained with the device.

Figure 3.6: Data charts from a patient with 50-75% artery stenosis. Graph A showspre-angiogram data, graph B shows post-angioplasty data.[8]

3.3 Matlab

Matlab code was written to analyze and verify heart sound with the aid of a computer.The goal of the developed code was to check the result yielded by Matlab for a spectralanalysis of a same .wav file than the analysis in Figure 3.2. The code is available inAnnexe E.

Figure 3.7: Matlab schema block for an FFT computation of a audio wave file

30

Page 32: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

3.4. CONCLUSION CHAPTER 3. SPECTRAL ANALYSIS

Figure 3.8: Result of the Matlab FFT computation (left) compared to FFT from adobeAudition for the same heart sound

Spectral analysis obtained by the two softwares are quite similar and prove that pre-vious results can be trusted. A detailed description on the implementation of the FFTis presented in Annex A.

3.4 Conclusion

Results of this study show that normal heart sounds are characterized by a main peakfrequency around 80-90Hz and a smaller one around 230Hz and that main valvular heartdiseases generate higher intensity frequencies beyond 110-120Hz.

31

Page 33: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4 The processing device

4.1 Introduction

In this chapter, the processing device will be described in detail. Design and componentsof the circuit will be explained and justified, including a study about the price, andfinishing by commenting the code written to program the processing unit.

4.2 Hardware

The first designed part of the hardware was the acquisition. The acquisition part iscomposed of a medical stethoscope and two electronic amplification stages. The stetho-scope used in this study is a general purpose stethoscope from NCD Medical LimitedCompany[16]. The stethoscope is a traditional dualhead with two PVC tubes. One ofthe tubes was removed and the corresponding hole stuffed, thus the air compression dueto the bell membrane only goes to one tube. Figure 4.1 represents how the microphonewas connected to the stethoscope. Fortunately, the diameter of the electret microphoneis almost the same as the tube’s hole allowing the microphone to be locked inside thetube without air leak.

Figure 4.1: Connection between the electret microphone and the stethoscope

• The stethoscope: NCD Medical 108 is a traditional dualhead design featuring alightweight aluminum chestpiece with an inlaid non-chill ring, chrome plated brassbinaurals, PVC tubing. “An excellent stethoscope for general auscultation.”

• The Microphone: Kingstate - KECG2742TBL-A, omnidirectionnel electret con-denser, standard operating voltage: 2V ( Max: 10V), sensitivity: -42dB for 1kHz1Pa.

32

Page 34: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.2. HARDWARE CHAPTER 4. THE PROCESSING DEVICE

Figure 4.2: Typical frequency response curve of the Kingstate Microphone

When selecting the electret microphone, the frequency response curve was the main keypoint. According to the price and the needs, the KECG2742TBL-A with a flat frequencyresponse curve as above in Figure 4.2 from Kingstate was chosen. It is important to notethat this graphic starts at 20Hz. However, most electret microphones available in themarket only give a frequency curve starting at 50Hz, which is to high leading to a lackof information for lower frequencies since this study ranges between 1 and 300Hz.

For a basic heart sound without any amplification, the signal’s peaks are around 30to 40mV peak-to-peak at the output of capacitor CM1 in Figure 4.3. It means that, fora maximum amplified output of 3.3V, an amplification stage with a gain of 82 to 110is necessary. For a project gain of 90 and two equal stages, it can be done with twoconsecutive stages with an individual gain at around 9.5 to reach the max rail value of3.3V.

Figure 4.3: Schematic of the acquisition part

33

Page 35: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.2. HARDWARE CHAPTER 4. THE PROCESSING DEVICE

The acquisition stage is composed of two operational amplifiers rail-to-rail in orderto amplify the signal in two times. Rail-to-rail is a necessity so that the widest voltagerange as possible is used, knowing that the processing device requires a signal between 0and 3.3V. It was necessary to use an extra operational amplifier to polarize the quiescentvoltage at the middle of Vdd, 1.65V. MCP6042 and MCP6002 were chosen. MCP60XXseries was chosen because it is a basic and cheap rail-to-rail low power operational am-plifier from Microchip, not only easily available but also of the same brand as the mainprocessing unit which will be presented later.

• MCP6042-6002: Operating voltage [1.4-6V], Low quiescent current: 600nA, Band-width: 14kHz, Slew Rate: 0.003V/µs, Operating Temperature Range:-40°C to+85°C, Max current at output and supply pins: 30mA.

The first amplification stage has a gain around 50:

V

out

= V

in

(1 + R13R12

) = V

in

(1 + 100k10k ) = 11.V

in

The second amplification has a variable gain between 11 and less than 44 :

V

out

= V

in

(1 + R22+R23R21

) = V

in

(1 + 100k+[0�330k]10k ) = [11� 44].V

in

D21, D22 and R24 are in parallel with R22 and R23. This additional circuit on theretro-action loop allows to avoid an excessively quick squared saturation of the signal,which can generate lots of harmonics in the FFT analysis. When the difference of voltagebetween the output and the input of this last amplification stage is higher than 0.65V,then the current will start to flow through R24 which will be put in paralel with R22 andR23 and finally the global feedback resistor will decrease and then the gain will decreaseat the same time (this is a simplified explanation).

It can be noticed that this acquisition scheme is devoid of any lowpass or bandstopfilters. It wasn’t the case in the first prototypes which included an order 2 Butterworthlowpass filter around 400Hz. ADC results with the Butterworth filter compared to re-sutlts obtained without filters didn’t lead to an improvement of the data. An explanationfor this can be the bell probe of the stethoscope which is already an effective lowpassfilter. In fact, theoretically, an anti-aliasing low-pass filter with cut-off frequency around250 Hz should be used for a 512 Hz sampling frequency. However, because spectralcomponents around and above 250 Hz are low energy even for diseased hearts, the re-maining aliasing components will not impair the simple algorithm used in the device anddescribed in Chapter 4.

34

Page 36: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.2. HARDWARE CHAPTER 4. THE PROCESSING DEVICE

Figure 4.4: Heart sound at the end of the amplification stage

Figure 4.4 shows the result obtained at the end of the acquistion’s chain, just beforeentering in the analogic pin of the microcontroller.

35

Page 37: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.2. HARDWARE CHAPTER 4. THE PROCESSING DEVICE

The microcontroller chosen for this project is a dsPIC33fj64MC802 from Microchip[17],ideal for digital signal processing as its name suggests and possessing some DSP library(FFT and digital filters). The choice of this processing unit was motivated by my su-pervisor Prof. Fernando Ferreira and myself as well, knowing a bit how Microchip andMPLab software work and which are their possibilities.

Figure 4.5: Schematic of the processing and debugging part of the device

• dsPIC33fj64mc802: Up to 40 MIPS operation (at 3.0-3.6V), 16-bit architecture,Program memory: 64KB, Linear data memory addressing up to 64 KB, Industrialtemperature range (-40°C to +85°C).

The same voltage is used to supply the entire device and is limited by the processingunit. The typical supply voltage for the dsPIC is 3.3V (max 3.6V), which is very ade-quate according to the supply voltage needed by the two operational amplifiers and themicrophone.

Figure. 4.5 also shows: 5 leds (2 red, 1 yellow, 2 green) used to give the resultand information during the acquisition, some transient filter capacitors for the differentintegrated circuits and a connector for the PICkit21, debugging and programming toolfrom Microchip to live interact with the dsPIC33.

1PICkit2: low-cost development tool with an easy to use interface for programming and debuggingMicrochip’s Flash families of microcontrollers. With Microchip’s powerful MPLAB Integrated De-velopment Environment (IDE) the PICkit 2 enables in-circuit debugging on most PIC® microcon-trollers. In-Circuit-Debugging runs, halts and single steps the program while the PIC microcontrolleris embedded in the application. When halted at a breakpoint, the file registers can be examined andmodified.

36

Page 38: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.3. POWER SUPPLY CHAPTER 4. THE PROCESSING DEVICE

• Ultrabright led: Forward Voltage 2.03V (Green and Yellow) 1.72V (Red), typicalcurrent: 20mA

Figure 4.6: Hardware schema block

The illustration 4.6 represents a scheme block of this hardware part. The blue linesrepresent the path of the signal acquisition to the process unit (in red). The green block’sare the power supply chain of the device and will be reviewed in the following chapter.Humans can interact with the device with buttons to switch on the device and start anacquisition. The result will be displayed with 5 leds:

• 2 green: “Your heart sounds very good”

• 1 green: “You heart sounds good”

• 1 yellow: “Bad acquisition”

• 1 red: “You should go to the doctor”

• 2 red: “You certainly have a disease”

4.3 Power Supply

4.3.1 Power supply solution for the developed device

The chosen solution to supply the acquisition device is based on a solar panel of 39x35mmand 2x1.2V AAA batteries.

37

Page 39: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.3. POWER SUPPLY CHAPTER 4. THE PROCESSING DEVICE

Why not supercapacitors? The solution can work too and was tested, but supercapac-itors have a big advantage and a big disadvantage:

• Advantage: supercapacitors can afford high current, allowing a quick recharge timeand a high current if it’s required by the device, but the developed device doesn’tneed high current and the solar panel can’t provide high current for quick recharge.

• Disadvantage: supercapacitors are definitely a future technology but still expensive.

Knowing that the developed device can’t benefit from the advantages of the supercapac-itors, this solution was discarded.

Solar panel and batteries can’t be directly connected to the rest of the device whichneed a constant and stable 3.3V. Moreover, 2x1.2V, when batteries are fully charged,only give 2.4V. The solution is to add a step-up integrated circuit able to provide astable 3.3V between the power supply and the supplied system. A second criterion wasto have it in DIP case and be able to provide around 200mA as output. This is the casefor the MAX756 from Maxim-IC[18].

Figure 4.7: Schematic of the power supply chain of the device

• Solar Panel: YH-39x35, operating voltage 4V, operating current: 35mA, dimension:39x35x3.2mm, monocrystalline silicon.

• 2x1.2V batteries: Ni-MH 970mAh. 970mAh is not optimal but it’s what was kepton hand. Because of the solar panel, working at 35mAh, it should be better to have350mAh batteries, because there is a rule stating that batteries have to be chargedwith a current that is 10 times less than their capacity value. Then, 970mAh willwork but it isn’t optimal, the battery will take more time to get fully charged, butthe battery will also possess more energy and then will take more time to fullydischarge. Finally, it’s better to have a 970mAh battery than a 150mAh one.

• MAX756CPA: Step-up regulator 3.3V-5V output, output current Max: 0.3A, sup-ply voltage min: 700mV, supply voltage max: 7V, frequency: 500kHz, 87% Effi-ciency at 200mA, 60µA of quiescent current.

There is a switch button between the solar panel, battery system and the MAX756 inorder to simply disconnect the processing device and let the battery charge as fast as thesolar panel can. When the switch button is turned ON, the dsPIC will be powered, an

38

Page 40: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.3. POWER SUPPLY CHAPTER 4. THE PROCESSING DEVICE

acquisition will start immediately and the result will appear at the end. The mechanismis simple and effective. For a second acquisition, all one has to do is to switch the buttonOFF and ON again. Thereby, the device just consumes nothing when it isn’t in use.

Below some power consumption information is presented from datasheets of somecomponents which can give a clue of what the device will consume:

• Microphone Max current consumption: 0.5mA

• MCP6002 & MCP6041: max 30mA, it will never be reached because the ADCinput from the dsPIC doesn’t ask high current

• led: 4mA limited by the dsPIC: 4x5 led = max 20mA

• dsPIC33fj64MC802: The supply current is mainly a function of the operating volt-age and frequency. Other factors, such as I-O pin loading and switching rate,oscillator type, internal code execution pattern and temperature, also have an im-pact on the current consumption. The test conditions for all Idd measurements onthe table in Figure 4.8 are as follows: OSC1 driven with external square wave fromrail-to-rail. All I-O pins are configured as inputs and pulled to Vss. MCLR = Vdd,WDT and FSCM are disabled. CPU, SRAM, program memory and data memoryare operational. In this study, the device runs at 20 MIPS, it will then consumearound 35mA.

Figure 4.8: dsPIC33fj64MC802 - Power Consumption in operating current

39

Page 41: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.3. POWER SUPPLY CHAPTER 4. THE PROCESSING DEVICE

Then, theorically, the power consumption should be around 40mA and 65mA.Note: it’s not so easy to evaluate power consumption via datasheet for this kind of

device. As explained before, microcontroller consumption depends of many aspects. Thebest practice remains to check by acting up:

• Device running at 40 MIPS with all led OFF: 50mA

• Device running with all leds ON: 70mA

4.3.2 Power supply solution for a 24h/24 autonomous acquisition device

This sub-chapter will present the power consumption and supply needed for the developeddevice and also for a similar device having to run 24h/24 as an autonomous acquisitiondevice working day and night acquiring data periodically. The proposed study case is asfollows:

• Power consumption of the device: 40mA at 3.3V

• Idle mode power consumption: 0.04mA at 3.3V

• Working time of the device: 30sec each 10 minutes during 24h, so 72min, 1.2h perday.

• Idle time: 24h-1.2h=22.8h

• Solar Panel: 35mA at 4V during irradiation hours

• Brussels: 946 kWh/m²[19] for one year , average sun hours: 1554h/year so 4,26h/-day, average worst case: 50h/month so 1,66h/day (December)[20]

• Lisbon: 1682 kWh/m²[19] for one year, average sun hours: 3000 h/year so 9,23h/-day, average worst case: 5.1h/day (December)[21]

• Battery: Ni-Mh 2x970mAh

• Worst case: 3 days without sun

40

Page 42: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.3. POWER SUPPLY CHAPTER 4. THE PROCESSING DEVICE

Figure 4.9: Yearly irradiation on a optimaly-inclined south oriented photovoltaic mod-ule[9]

• Device consumption:

3.3V ⇥ 40mA = 132mW

132mW ⇥ 1.2h = 158.4mWh per day

• Solar panel:

4V ⇥ 35mA = 140mW

140mW ⇥ 4, 26h = 596, 4mWh per day in Brussels

Then, for an average yearly day in Belgium, the solar panel produces 3.8 times whatthe device consumes.

140mW ⇥ 9, 23h = 1292.2mWh per day in Lisbon

Then, for an average yearly day in Lisbon, the solar panel produces more than 8 timeswhat the device consumes.

• Worst case:

158.4mWh/3.3V = 48mAh per day

41

Page 43: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.4. COST OF THE DEVICE CHAPTER 4. THE PROCESSING DEVICE

48mAh⇥ 3 = 144mAh

Then, for this worst case, the battery has to be able to supply 144mAh, which iscompletely the case with the 2x970mAh battery. It can be concluded that the battery isoversized, therefore one 970mAh battery is enough. As explained previously in Section4.3.1, for the best charging performance, batteries should be around 360mAh and thenone battery can still be enough.

4.4 Cost of the device

The bill of material can be found in Annexe D. Based on Farnell and RS-Componentsprices, the total amount for the device is around: 48€ (including 5€ of PCB manufac-turing). The most expensive components are:

• Solar panel: 10€

• Stethoscope: 9.5€

• Step-up Max756: 6.5€

• dsPIC33FJ64MC802: 5.8€

The solar panel is expensive, because only one unit was ordered, as well as for the dsPIC33and the MAX756. The same kind of solar panel (6V 35mA 0.21W) can be ordered fromChina or Ebay around 5$.

Moreover, in the Step-up and dsPIC, a DIP case was chosen, to be able to easily testthis devices on breadboard. Now, if SMD components are chosen, the price can seriouslydecrease as well as for the resistors, capacitors and inductors. Then, for a small firstmass production, the prices of this expensive components could decrease around:

• Solar panel: 4€

• Stethoscope: 4€ (only the head is needed)

• Step-up SMD: 3.5€

• dsPIC33FJ64MC802: 4€

So, a total cost less than 30€ can be expected.

42

Page 44: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.5. SOFTWARE CHAPTER 4. THE PROCESSING DEVICE

4.5 Software

The main code file for the dsPIC33FJ64MC802 is presented in Annexe E. The globalidea of the developedsoftware is shown in the next diagram:

Figure 4.10: Schema block of the developed software

File architecture of the project is as follows:

• Source files:

– mainFFTCOmplexIP.c: main file– IIRT_Filters.s: base file from dsPIC FD Lite (digital filter design software

from microchip)– Mybandstop50.s: generated file from dsPIC FD Lite– Mybandstop100.s: generated file from dsPIC FD Lite– Mybandstop200.s: generated file from dsPIC FD Lite– Traps.c: debug file

43

Page 45: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.5. SOFTWARE CHAPTER 4. THE PROCESSING DEVICE

• Header files:

– Init.h: ADC, DMA, oscillator, timer configuration– IIR_Filter.h: file from dsPIC FD Lite (digital filter design software from

microchip)– Mybandstop50.h:generated file from dsPIC FD Lite– Mybandstop100.h:generated file from dsPIC FD Lite– Mybandstop200.h:generated file from dsPIC FD Lite

• Linker Script file:

– Linkerscript.gld: includes all library files needed for FFT,...

4.5.1 Initialization:

The oscillator is set up around 40MHz, half of the maximum operating frequency, so20MIPS and uses the internal RC oscillator at 7,35MHz, then there is no need to useand spend money in an external quartz. Working at this frequency is enough to acquireand process data whithout consuming too much energy.

ADC, Analog Digital Converter, is set up in a 12-bits mode to get the maximumaccuracy that the device can provide. ADC is configured to work in DMA mode. DirectMemory Access facilitates the transfer of data between the CPU and its peripheralswithout CPU assistance. It is optimized for high-performance and real-time applicationalthough it isn’t a necessity in this work. ADC and DMA are triggered by timer5configured to sample 512 times per second. Thereby, the maximum frequency of theFFT is 256Hz. This 512 values are limited by the dsPIC33fj64MC802, which doesn’thave enough memory to support ADC and fractional complex vector of 1024 points. Itshould be better to get the 1024 points ADC and FFT vector of course, but it isn’t socritical because Section 3.2, shows that frequency diseases start around 110Hz, leavingus more than the half of the vector to analyze and detect pathologies.

More Timers were also configured with one of them set to 32 bits (InitTimer32) inorder to use them when needed, such as for a blinking led (Low battery).

In a first approach an UART, Universal Asynchronous Receiver Transmitter, was con-figured to get a back value on the computer via a serial port, before discovering thatthe PICkit2 is able to read, register and memorize values when the device is halted(breakpoints,...)

4.5.2 Filter design

As explained before in Section 4.2, there is no hardware filter in the final prototypeversion, because the one tested didn’t give efficient results and also because most filteringoperations can be done digitally. The software used for designing the digital filters was:

• dsPIC FD Lite Version 1.0.0 Build1 from Microchip

44

Page 46: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.5. SOFTWARE CHAPTER 4. THE PROCESSING DEVICE

Some tests showed that some places are really noisy with 50Hz. It’s also depending ifthe patient is bare foot, etc. Then, bandstop filters were designed at 50, 100 and 200Hzto not disrupt the FFT results and also to be able to see correctly heart beats on theADC graphic. Figure 4.11 shows the result of a 50Hz bandstop filter in dsPIC FD Lite.The configuration used for 50Hz Bandstop is as follow:

• Sampling Frequency: 512Hz

• Passband Frequencies: <48Hz, >52Hz

• Stopband Frequencies: 49-51Hz

• Passband Ripple (dB): 1

• Stopband Ripple (dB): 200

• IIR Analog filter order desired: Butterworth 8th.

Figure 4.11: dsPIC FD Lite Version - resulting window after configuring a 50Hz bandstopfilter

Once done, C code can be generated (2 files: one *.s and one *.h) for dsPIC microcon-troller and be included in the project. An example of the generated code for the 50Hzbandstop filter is presented in Annexe E. To use the designed filter on a vector of theprogram, it only needs to be initialized and called when desired:

• Initialization function: IIRTransposeFilterInit ( &MyBandstop50Filter ) ;

• Calling function: BlockIIRTransposeFilter( &MyBandstop50Filter, &Desired_Vector[0],&Filtered_Vector[0], NUM_SAMPLES );

45

Page 47: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.6. CONCLUSION CHAPTER 4. THE PROCESSING DEVICE

The result is effective! Noise is divided by 4 for this noisy environment and heart beatscan be detected:

Figure 4.12: With and without filter

4.5.3 The main Loop

After checking the battery level, the main loop consists in 10 consecutive ADC acquisi-tions of 1 second sampled at 512Hz. There are two DMA buffers working in ping-pongmode, while one is full, the value converted and the data is ready to be read, the otheris acquiring. A flag warns when one of the DMA buffers is ready to be read. Then theADC_signal[] is filled with 512 values and a small loop is done to get the peak value,used to indicate the signal strength to the user by turning on some led during each ofthe 10 acquisitions.

Data has to be manipulated before going through the FFT process. First, the data hasto be zero centered by removing the offset, because currently data is between 0 and 4095.Once the offset is removed, the 3 bandstop digital filters are applied and 4 consecutivevectors are filled in order to debug the ADC signal[]. (ADC_meaned1, ADC_meaned2,ADC_meaned3, ADC_meanedout).

The ADC_signal[] vector is then transferred in a complex vector ( sigCmpx), requiredfor FFT computation. Now, FFTComplexIP() and BitReverseComplex() can be ap-plied to process the FFT. The real part of the FFT result is extracted, and stored inFFT_ACQ[]. FFT_ACQ[] will receive and sum the FFT result during the 10 timesloop. When the 10 consecutive acquisitions are over, FFT_ACQ[] will be normalizedand stored in FFT_Normalized.

This last vector will be the base for the decision algorithm and finally turn on theappropriate leds. The algorithm will be explained in the next chapter, after real diseasedpatients results are analyzed.

4.6 Conclusion

The current prototype device is as described in this chapter. This third version wasthe first to be tested on real diseased patients. Then, after analysis of these real cases,hardware and software will have to be improved as needed. A review will be done in

46

Page 48: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

4.6. CONCLUSION CHAPTER 4. THE PROCESSING DEVICE

the conclusion of this study. Schematic diagrams, PCB layouts, component listings andsoftware listings are detailed in Annex B, Annex C, Annex D and Annex E respectively.

47

Page 49: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5 Tests and Results

5.1 Introduction

The goal of this chapter is to show the steps which were followed in order to check thedevice’s performance by doing some tests and reviewing the results. During the firsttests, the sound was generated from the computer and transferred to the stethoscopemembrane via a headphone embracing quite well the stethoscope’s head, see Figure 5.1.

Figure 5.1: Connection between the stethoscope and the headphone[10]

The frequency response of the microphone has to be considered and is given in Figure5.2

Figure 5.2: Frequency response of the headphone Sennheiser HD25-1[10]

48

Page 50: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.2. TEST 1 - PRECISE FREQUENCIES CHAPTER 5. TESTS AND RESULTS

5.2 Test 1 - Precise Frequencies

This first test tries to check if it’s possible to get precise frequencies back and check theirintensity. It is then that the non-normalized vector, FFT_ACQ[] is used. Sinusoïdal 35-65-95-... signals are selected to avoid the increase in the peak value because of well-knownoises (50Hz and harmonics).

Figure 5.3: Test1 - FFT of 35-65-95-125-155-185-215-245Hz by the acquisition device

The obtained results match the bolded curve of the previous illustration in Figure 5.2,except in the low frequency region where the signal is weak and too high for 185Hz. Theobtained high value for 185Hz can be explained by two things:

• 185Hz is near 180Hz which is a noisy frequency and that there is no designed filterfor 180Hz. Further information on this problem is given in Section 5.7.1.

• In previous prototype versions, 180Hz and nearby frequencies were already noticedas usually strong.

Finally, this test proves that precise frequencies can be detected by the device and thatif 180Hz and nearby values are persistant in future acquisitions, another filter will haveto be developed to avoid the result from being normalized on a noisy peak frequencyreducing the signal to low values.

The last illustration in Figure 5.4 represents what is obtained for a silent acquisitionhighlighting noisy frequencies.

49

Page 51: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.3. TEST 2 - NORMAL HEART SOUND CHAPTER 5. TESTS AND RESULTS

Figure 5.4: FFT of the stethoscope acquiring nothing

The illustration in Figure 5.4 shows a flat frequency response except for 50, 180 and250Hz. 50Hz is a well-know frequency having been filtered previously, not representinga big problem, especially knowing that murmurs are between 110 and 250Hz. 180 and250Hz however have to be carefully interpreted and if they are the peak frequency of theacquisition, then the decision algorithm should invalidate the test. (Yellow led)

5.3 Test 2 - Normal Heart sound

In this test, as in the previous study with Adobe Audition 3.2, the same normal heartsounds will be acquired. The test will finish and be complete with a normal body acquiredheart sound.

Figure 5.5: FFT of 3 normal heart sounds via the headphone and the acquisition device

50

Page 52: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.3. TEST 2 - NORMAL HEART SOUND CHAPTER 5. TESTS AND RESULTS

Results show that for 3 different heart sounds qualified as normal, the obtained curvesare similar. The peak frequency is around 80Hz as in the previous Adobe audition study.180 and 250Hz are also present as narrowed peaks, except for the Littmann acquisition.

The device will now be tested on a real body. The first Figure 5.6 represents a partof the temporal ADC acquisition - the test is based on 3 successive acquisitions made atthe pulmonary auscultation area.

Figure 5.6: Part of ADC result of my normal heart sound

Figure 5.7: 3 FFT result of a normal heart sound acquired on a body

An important comment has to be done, because this 3 results give the main peakaround 30Hz and not around 80Hz as previous headphone acquisitions. However thiscan be considered normal because the Adobe Audition and Matlab study have this wellpredicted and supported in their .wav file analysis. The second explanation can defi-nitely be that the headphone-to-stethoscope acquisition is not the same as the body-to-stethoscope acquisition. Indeed, for the body acquisition, the stethoscope is in directcontact with the skin and its membrane is following low frequency pulses from the heartat the surface of the skin which really increases the low frequencies by compressing theair in the stethoscope’s PVC tube. Furthermore, as shown in the previous headphonetest in Figure 5.2, the results for frequencies below 50Hz are really low, also accordingto the frequency response curve of the headphone, as explained.

51

Page 53: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.4. TEST 3 - DISEASED HEART SOUND CHAPTER 5. TESTS AND RESULTS

Then,

• No direct contact to the stethoscope membrane comparing headphone and body tostethoscope connection.

• No presence of 30Hz frequency in previous .wav file.

• Weak frequency response of the headphone in low frequency below 50Hz.

Besides this difference between headphone and real body tests, results are quite similarwhich is good news indicating that the device can give reproductive results.

5.4 Test 3 - Diseased Heart sound

Test 3 tries to check what can give diseased heart sounds from the headphone. Heartdiseased sounds come from the same source as data used in Section 3.2.

Note: Chapter 3.2 works between 0 and 500Hz, here it’s between 0 and 256Hz.

Figure 5.8: 6 Diseased FFT Heart Sound by the device (source of the heart sound)[7]

Results are quite impressive, murmurs can really be detected between 110 and 250Hz.Except for the aortic stenosis which remains low energy contents between 110 and 250Hz.

5.5 Test 4 - FFT from oscilloscope

It was also important to make an FFT analysis of the signal just before it enters throughthe ADC pin. A test was done with a Tektronix oscilloscope having the FFT spectral

52

Page 54: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.6. TEST 5 - 4 AUSCULTATION AREAS CHAPTER 5. TESTS AND RESULTS

analysis option. The left FFT represents my body heart sound and the right FFT, anaortic stenosis acquired with headphone to stethoscope. 2 vertical bars were added oneach graphic at 100 and 200Hz.

Figure 5.9: Comparison of a normal and Aortic stenosis heart sound - FFT fromOscilloscope

Results are reassuring and confirming that it is normal that the previous test on mybody (Figure 5.17) showed a low frequency around 30Hz ininstead of 80Hz. The FFToscilloscope gives almost the same result: a peak around 30Hz, a smaller one around80Hz and a weak intensity in higher frequencies. The right illustration part confirmsthat murmurs possess higher intensity in frequencies beyond 110Hz.

5.6 Test 5 - 4 auscultation areas

As explained in the Section 2.3, there are four auscultation areas. This test will acquiremy heart sounds from the four areas in order to test the similarity of the data.

Figure 5.10: FFT of my heart from the 4 auscultation area

This result is in accordance with what was previously seen 2.3. (ed., From my personal

53

Page 55: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.7. REAL CASE TESTS CHAPTER 5. TESTS AND RESULTS

experience, I have to add, that sounds from the Tricuspid and Mitral areas are definitelylouder at the ADC input).

5.7 Real case tests

5.7.1 Define a normal heart sound pattern

In order to draw the border between normal and murmurs heart sound, a small studywas done in ISEC. The pattern is then based on 10 teenagers around 18-30 years and 2teachers, which is not enough, indeed, for a full characterization but still indicative. Thenext illustration represents the obtained average values.

Figure 5.11: FFT of my heart from the 4 auscultation area

Only the average is attached to avoid thousand and thousands of graphics in thereport. The average result show well that main frequency components of a normal heartare between 25 and 100Hz. The detailed study showed that higher frequencies (70-100Hz)were more present in the teacher’s heart sounds.

A second and important point to note is that there are no more peaks around 180 and250Hz. It was found that this noisy problem was actually originating from the computerpower supply which also supplies the device. To confirm that, more tests were doneon battery powered compared to computer PICkit 2 powered and the result is effective.That was the problem !

5.7.2 Diseased patients

After filling some administrative forms, Dr. Eduardo Antunes let me enter his hospital1in order to test my device on real diseased patients. It has to be said that 40% of thepatients in this hospital suffer from coronary artery disease, which is the most commondisease, and another 40% from aortic stenosis, all adults or elderly people. Dr. EduardoAntunes explained to me that the best place to listen aortic stenosis is on the aortic

1Hospital de Santa Marta, Rua de Santa Marta, 1169-024 Lisboa

54

Page 56: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.7. REAL CASE TESTS CHAPTER 5. TESTS AND RESULTS

area, definitely confirmed after testing the 3 others areas. Dr. Eduardo Antunes sent mepatients with murmurs (aortic stenosis) and some without murmurs but with coronaryartery disease to check if I was able to find something (cf. the discussion about the USpatent 3.2).

The next Figure 5.12 represents the temporal ADC values of the patient 02.MF withan aortic stenosis of class 3.

Figure 5.12: ADC of an aortic stenosis

From what I was able to listen with my novice ears was a sound composed of only oneaudible beat, longer and composed of higher frequencies than a normal heart sound.

Figure 5.13: FFT of aortic stenosis on real diseased patients

This top-left grapic in Figure 5.13 shows the result of 4 aortic stenosis based on validchecked ADC acquisition. Murmurs are well present beyond 110Hz. The patient 02.MFhad a murmur of class 3 on the 6 grades intensity scale 2.5.4, which are the much loudermurmurs I heard during my two days of auscultation, confirmed by the FFT spectrum.

This graphic also shows that a pattern can’t be defined for a murmur, these 4 aorticstenosis FFT are all different but well composed of high frequencies.

It also has to be said that on skinny people the sound was easier to acquire (also becausethe potentiometer wasn’t set with the best resistor’s values yet). The next illustration

55

Page 57: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.8. MATLAB CHAPTER 5. TESTS AND RESULTS

rightly shows a skinny man having a heart proproject generating a murmur.

Figure 5.14: FFT of a heart with proproject generating murmurs

About the coronary artery disease, which doesn’t create murmurs, the results didn’tgive something effective to show as expected. Before working on this kind of morecomplex case, the device still has to be improved and tested on more patients to improvethe filters and design patterns.

Note: I have to say that patients auscultation isn’t an easy task for an improvised doctorlike me and sometimes it wasn’t easy to find the best place to listen the murmur,which invalidates many results.

5.8 Matlab

An extra study was conducted with Matlab to test and check what this software is able todo and detect. This part doesn’t use the acquisition device, except the same microphoneto acquire data on the computer via the microphone input line after a small DIY2.The Matlab code allows to acquire 5 seconds of live audio sound from the microphoneand stethoscope with only the embedded internal amplification of the laptop. Then, itcomputes the FFT after processing a basic Hamming window, there is no complex digitallow-pass filter or other, just an FFT and a Hamming window. The next Figure 5.15 showthe result for 3 normal heart sounds and afterwards for diseased heart audio files (stillthe same audio files as previously).

2do-it-yourself

56

Page 58: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.8. MATLAB CHAPTER 5. TESTS AND RESULTS

Figure 5.15: 3 Normal heart sound analyzed by Matlab from headphone

Results show well the main frequency curve around 80-90Hz and also narrowed peaksat 50, 100, 150, 180, 200, 250 and 350Hz, which are logic because of the lack of digitalfilters.

Figure 5.16: 3 Diseased sound analyzed by Matlab from headphone[7]

Results for diseased heart sound files also work but not as well. Note: the volume hadto be turned higher (ed., I was able to hear the murmur sitting near to my headphone,50 cm). But like I previously said, headphones can’t make the stethoscope’s membranevibrate as skin is able to do it.

The graphics in Figure 5.17 is a live acquistion of my heart sound.

57

Page 59: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.9. CONCLUSION CHAPTER 5. TESTS AND RESULTS

Figure 5.17: My Normal heart sound analyzed by Matlab

The temporal result is quite good and the FFT result is as expected. Further studiesshould be done in this direction, but with a different goal from the one in this study.Indeed, with Matlab tools it is possible to work on complex digital filters (easier to doand modify than in C language) and neuronal networks, which are currently a growingsubject in order to train artificial intelligence on many patient’s cases and finally beingable to design a pattern for different diseases. The only important requirement will be awell designed acquisition’s entry.

Back to this study and checking if Matlab can be a low cost solution able to computeFFT? Matlab’s solution is composed of a stethoscope, a microphone, a computer anda Matlab license. This solution can be cheap or not, depending on the point of viewrefering to the computer. The two expensive objects are the computer and the Matlablicense.

Some points are to be considered:

• The Matlab license price can be avoided by creating a standalone version of theMatlab code. Indeed, Matlab possesses a compiler able to generate an executablefile for Windows[22].Then, only one license is needed during the development time.

• About the computer price, it remains an expensive part indeed, but as previouslysaid, it depends on the point of view. Where in the world don’t we have a basiccomputer? Furthermore, the generated Matlab standalone software will not requirea high performance computer.

Then, if the computer isn’t considered as expensive, because already owned, then thissolution can be considered as low-cost, but not as low power consumption.

5.9 Conclusion

The results of this chapter show that the developed device is able to process correctFFT and provide adequate and expected results. Valvular diseased heart sounds can be

58

Page 60: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

5.9. CONCLUSION CHAPTER 5. TESTS AND RESULTS

effectively detected and discerned from a normal heart sound pattern.The noise remains sometimes a problem for weak signals and has to be reduced by

improving the software and hardware.Future hardware improvements are:

• Optimizing the best resistor’s values for the amplification stage.

• Finally, a simple hardware low-pass filter should be tested at the end of the twoamplification stages before the signal enters through the analogic pin of the micro-controller in order to reduce high frequencies that amplification stages can generate.

• Shielding of the microphone’s wires.

• Reducing the size of the PVC stethoscope’s tube, and perhaps remove it at the endcompletely by creating a tiny device having the size of the stethoscope’s head.

Future software improvements are:

• Improving digital filters, after having enough cases analysed.

• Test the results with a 1024 points FFT in order to have results between 1 and500Hz. For that, the dsPIC33fj64mc802 has to be replaced by one having moredata memory.

• More detailed definition and description of the decision algorithm.

The next chapter should be this algorithm definition, but for that, the device should betested on more normal and diseased hearts. Time is a bit missing for that, althoughI’m welcome in Santa Marta hospital by Dr. Eduardo Antunes for further analysis. Butbefore that, hardware and software should be improved on some aspects in order to getoptimal results when in the field acquiring data on real diseased patients.

59

Page 61: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

6 Conclusion

Obtained results are quite promising with a draft of normal and diseased heart soundspatterns taking shape. Still, the currently presented system is only a prototype whichproves that it is working and that more studies should be done. Hardware and softwarecan be improved in order to provide the best acquisition possible and thereby to continueto go forward.

A discussion has to be take place about the solar panel implemented in this devicewhen targeting a medical application. Indeed, this heart sound acquisition device willwork most of the time indoor, what is not optimal to benefit from the maximum of thissupply solution. It will increase the price too much for not enough benefits. Moreover,this medical application doesn’t consume a lot of energy and many acquistions can bedone already with only one AAA battery and a simple switch button which should bethe cheapest solution. Anyway, I was glad to learn how to design a green power suppliedsolution for this kind of acquisition device. However, for a generic automation signalacquisition device, many applications can be found that can benefit from the solar panelsolution.

Let’s hope that this work will motivate further studies in this area, heart diseasesbecome so much important in developing and developed countries, and so much peopledie or suffer due to a late diagnosis.

60

Page 62: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Bibliography

[1] T. H. Institute. (2010, July) The heartbeat. [Online]. Available:http://www.texasheart.org/HIC/Anatomy/systole.cfm

[2] D. R. Murphy. (2003-2004) Introduction to heart sounds, 3m littmann educationalcd series.

[3] (2007) The heart sound structure. [Online]. Available: http://www.biomedical-engineering-online.com/content/6/1/16/figure/F1?highres=y

[4] A. K. Abbas and R. Bassam, Phonocardiography Signal Processing, U. o. C. JohnD. Enderle, Ed. Morgan Claypool, 2009, no. 9781598299762.

[5] Cardiovascular diseases - word health organization. [Online]. Available:http://www.who.int/en/

[6] (2006, 12) The cardiac exam: Auscultation. [Online]. Available:http://filer.case.edu/dck3/heart/listen.html

[7] F. Michael J. Barrett, MD. Heart songs 3 - cardiosource - american college of car-diology.

[8] F. rie G. Johnson, “Detection of coronary artery disease using an electronicstethosope,” United States Patent, Tech. Rep. Patent Number: US 7,520,860 B2,2009.

[9] “Europa sun irradiation,” 2008. [Online]. Available:http://re.jrc.ec.europa.eu/pvgis/countries/europe.htm

[10] Frequency response of the senheiser hd25-1 ii. [Online]. Available:http://www.headphone.com/headphones/sennheiser-hd-25-1-ii.php

[11] S. W. Smith, The Scientist and Engineer’s Guide to Digital Signal Processing (secondedition), ser. ISBN 0-9660176-6-8. California Technical Publishing, San Diego,California, 1999.

[12] J. N. T. A Haghigui-Mood, “Coherence analysis of multichannel heart sound record-ing,” Ph.D. dissertation, School o f Engineering and Trafford Centre for MedicalResearch, University of Sussex, Brighton, UK, 1996.

[13] J. E. Corwin, Handbook of Pathophysiology: Foundations of Health and Disease, 3rdEd., 2006.

61

Page 63: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Bibliography Bibliography

[14] (2008) Circulation - heart diseases and statistics. [Online]. Available:http://circ.ahajournals.org/content/early/2008/12/15/CIRCULATIONAHA.108.19126

[15] “National cancer institute,” 08/2011. [Online]. Available:http://nciterms.nci.nih.gov/

[16] (2010) Ncd medical stethoscope company. [Online]. Available:http://www.ncdmedical.ie/stethoscopes.htm

[17] (2009) Microchip technology inc. [Online]. Available: http://www.microchip.com/

[18] (2011) Maxim integrated circuit company. [Online]. Available: http://www.maxim-ic.com/

[19] O. for Economic Co-operation and Development, OECD Environmental Perfor-mance Reviews OECD Environmental Performance. OECD, 2006.

[20] “Belgium forecast and statistic information,” 2011. [Online]. Available:www.meteo.be

[21] (2011) Lisbon sun irradiation. [Online]. Available:http://www.climatetemp.info/portugal/lisbon.html

[22] I. The MathWorks. Matlab compiler. [Online]. Available:http://www.mathworks.co.uk/products/compiler/index.html

[23] “National renewable energy laboratory,” 2011. [Online]. Available:http://www.nrel.gov/

[24] (2003, 02) A brief survey of common heart problems. [Online]. Available:http://heartdisease.about.com/cs/starthere/l/blsurveyheartpr.htm

[25] C. E. Davila, “Introduction to biomedical engineering catheterization and cardiacoutput,” Master’s thesis, SMU Electrical Engineering Departmen, 2001.

[26] A. J. B. John C. Wood and D. T. Barry, Time-Frequency Transforms: A NewApproach to First Heart Sound Frequency Dynamics. IEEE TRANSACTIONS ONBIOMEDICAL ENGINEERING, 1992.

[27] J. PM Bentley, Time-frequency analysis and diagnosis of native heart valve sounds.Department of Electrical, The University of Edinburgh, 1995.

[28] D. G. Andrew Houghton, Making Sense of the ECG, 3rd edition. Hodder Education,2008.

62

Page 64: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Annexes

Annex A -Spectral analysis - FFT

Spectral analysis is the measurement of the amplitude of the components of a complexwaveform throughout the frequency range of the waveform. To do that, a mathematicaltool exists, which is called the Fast Fourier Transform (FFT). The Fast Fourier Transformis a way to quickly calculate the Fourier transform:

f(⇠) =´ +1�1 f(x)e�2⇡ix⇠

dx

such as,

f(x) is an integrable time depending (x) function with f : R ! C

This Fast Fourier Transform becomes possible by sampling the source signal in discreteelements. The integral become:

X

k

=P

N�1n=0 x

n

e

�i2⇡ nN with k = 0, ...N � 1

The FFT operates by decomposing an N point time domain signal into N time do-main signals each composed of a single point. The second step is to calculate the Nfrequency spectra corresponding to these N time domain signals. Lastly, the N spectraare synthesized into a single frequency spectrum.

Figure A.1: The FFT Decomposition [11]

63

Page 65: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

An N point signal is decomposed into N signals each containing a single point. Eachstage uses an interlaced decomposition, separating the even and odd numbered samples.In Figure ??, a 16 point signal is decomposed through four separate stages. The firststage breaks the 16 point signal into two signals each consisting of 8 points. The secondstage decomposes the data into four signals of 4 points. This pattern continues until thereare N signals composed of a single point. An interlaced decomposition is used each timea signal is broken in two, that is, the signal is separated into its even and odd numberedsamples.

Figure A.2: FFT Bit Reversal [11]

The FFT time domain decomposition can be implemented by sorting the samplesaccording to bit reversed order. It’s definitely here that the time profit is achieved, asimple address bit reverse is enough to compute the FFT. This operation can be easilydone by any computer or microprocessor.

The next step in the FFT algorithm is to find the frequency spectra of the 1 pointtime domain signals. Nothing could be easier; the frequency spectrum of a 1 point signalis equal to itself. This means that nothing is required to do this step.

The last step in the FFT is to combine the N frequency spectra in the exact reverseorder that the time domain decomposition took place. This is where the algorithm getsmessy. But another trick is again used.

64

Annexes

Page 66: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Figure A.3: Butterfly [11]

An 8 point time domain signal can be formed by two steps: dilute each 4 point signalwith zeros to make it an 8 point signal, and then add the signals together. That is,abcd becomes a0b0c0d0, and efgh becomes 0e0f0g0h. Adding these two 8 point signalsproduces aebfcgdh. As shown in Figure 12-4, diluting the time domain with zeros cor-responds to a duplication of the frequency spectrum. Therefore, the frequency spectraare combined in the FFT by duplicating them, and then adding the duplicated spectratogether. In order to match up when added, the two time domain signals are dilutedwith zeros in a slightly different way. In one signal, the odd points are zero, while in theother signal, the even points are zero. In other words, one of the time domain signals(0e0f0g0h) is shifted to the right by one sample. This time domain shift correspondsto multiplying the spectrum by a sinusoid. This simple flow diagram in Figure ?? iscalled a butterfly due to its winged appearance. Because a shift in the time domain isequivalent to convolving the signal with a shifted delta function. This multiplies thesignal’s spectrum with the spectrum of the shifted delta function. The spectrum of ashifted delta function is a sinusoid.

The butterfly is the basic computational element of the FFT, transforming two complexpoints into two other complex points. At the end of the butterfly computation the FastFourier Transform is accomplished.

Note: This fast algorithm only will work if N is multiple of N = 2x

65

Annexes

Page 67: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Annex B - Schematic Design

Note: In the final prototype, CU1, CU2 and C33 are replaced by capacitors around330/470uF, which helps to reduce the noise at U2:A output and the ripple voltage of theMAX756.

66

Annexes

Page 68: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Annex C - PCB - Printed Card Board

67

Annexes

Page 69: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Annex D - Components List and prices

68

Annexes

Page 70: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Annex E - Source Code

MPLab: init.h#define FCY 20360000 // MIPS frequency#define U1BAUD 19200 // Baudrate#define BRGVAL ((FCY/U1BAUD) /16)�1#define Fs 512 // Sampling Frequency#define SAMPPRD (FCY/Fs )�1 // Configure Timer5 period used for ADC Acquisition .

512 Sample/s

/∗���������������������������������������������������������������������FFT configuration�����������������������������������������������������������������������∗/// Number of sample in the FFT vector#define FFT_BLOCK_LENGTH 512// Number of "Butter f ly " Stages in FFT processing nb : 2^9=512#define LOG2_BLOCK_LENGTH 9#define FFTTWIDCOEFFS_IN_PROGMEM// DMA Ping�pong buf fer Af r a c t i o n a l BufferA [FFT_BLOCK_LENGTH] __attribute__ (( space (dma) ) ) ;// DMA Ping�pong buf fer Bf r a c t i o n a l BufferB [FFT_BLOCK_LENGTH] __attribute__ (( space (dma) ) ) ;

/∗���������������������������������������������������������������������Function Name: Osc_configurationDescription : o s c i l l a t o r configuration

�����������������������������������������������������������������������∗/

void Osc_conf igurat ion ( void ) {

// Configure PLL prescaler , PLL postscaler , PLL div i sorPLLFBD=20; // M=22 20,36Mhz = FoscCLKDIVbits .PLLPOST=0; // N1=2CLKDIVbits .PLLPRE=0; // N2=2OSCTUN=0; // Tune FRC osc i l l a to r , i f FRC is usedRCONbits .SWDTEN=0;__builtin_write_OSCCONH(0 x01 ) ;__builtin_write_OSCCONL(0 x01 ) ;while (OSCCONbits .COSC != 0b001 ) ;while (OSCCONbits .LOCK!=1) {} ;

}

/∗���������������������������������������������������������������������Function Name: Pin_configurationDescription : Pin ’ s Configuration

�����������������������������������������������������������������������∗/

void Pin_conf igurat ion ( ) {

TRISB = 0xFFFF ; //configure a l l PortB as inputTRISBbits . TRISB11 = 0 ; // set IO as outputs GREENTRISBbits . TRISB12 = 0 ; // set IO as outputs GREENTRISBbits . TRISB13 = 0 ; // set IO as outputs MIDDLETRISBbits . TRISB14 = 0 ; // set IO as outputs REDTRISBbits . TRISB15 = 0 ; // set IO as outputs REDLATBbits .LATB11 = 0 ; // Set PORTB to 0LATBbits .LATB12 = 0 ; // Set PORTB to 0LATBbits .LATB13 = 0 ; // Set PORTB to 0LATBbits .LATB14 = 0 ; // Set PORTB to 0LATBbits .LATB15 = 0 ; // Set PORTB to 0

}

/∗���������������������������������������������������������������������Function Name: InitTimer32Description : 32 b i t s timer based on timer 2 & 3

�����������������������������������������������������������������������∗/

void InitTimer32 ( ) {

T3CONbits .TON = 0 ; // Stop any 16�b i t Timer3 operationT2CONbits .TON = 0 ; // Stop any 16/32� b i t Timer3 operationT2CONbits . T32 = 1 ; // Enable 32�b i t Timer modeT2CONbits .TCS = 0 ; // Se lect internal instruct ion cycle c lockT2CONbits .TGATE = 0 ; // Disable Gated Timer modeT2CONbits .TCKPS = 0b00 ; // Se lect 1:1 Prescaler (Fcy div ider )

69

Annexes

Page 71: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

TMR3 = 0x00 ; // Clear 32�b i t Timer (msw)TMR2 = 0x00 ; // Clear 32�b i t Timer ( lsw )

PR3 = 0x0136 ; // Load 32�b i t period value (msw)PR2 = 0xab40 ; // Load 32�b i t period value ( lsw )

// 136ab40h = 2 036 000 = FCY => 1hz

IPC2bits . T3IP = 0x01 ; // Set Timer3 Interrupt Priori ty LevelIFS0bi t s . T3IF = 0 ; // Clear Timer3 Interrupt FlagIEC0bits . T3IE = 1 ; // Enable Timer3 interruptT2CONbits .TON = 1 ; // Start 32�b i t Timer

}

/∗���������������������������������������������������������������������Function Name: InitTmr1Description : Timer 1 i n i t i a l i s a t i o n

�����������������������������������������������������������������������∗/

void initTmr1 ( ) {

T1CONbits .TON = 0 ; // Disable TimerT1CONbits .TCS = 0 ; // Se lect internal instruct ion cycle c lockT1CONbits .TGATE = 0 ; // Disable Gated Timer modeT1CONbits .TCKPS = 0b00 ; // Se lect 1:1 PrescalerTMR1 = 0x00 ; // Clear timer reg i s t e rPR1 = 0x4DAA; // 1024hz

IPC0bits . T1IP = 0x01 ; // Set Timer1 Interrupt Priori ty LevelIFS0bi t s . T1IF = 0 ; // Clear Timer1 Interrupt FlagIEC0bits . T1IE = 1 ; // Enable Timer1 interruptT1CONbits .TON = 1 ; // Start Timer

}

/∗���������������������������������������������������������������������Function Name: InitTmr5Description : Used for ADC SAMPLING

�����������������������������������������������������������������������∗/

void initTmr5 ( ) {

TMR5 = 0x0000 ; // Clear TMR5PR5 = SAMPPRD; // Load period value in PR5IFS1bi t s . T5IF = 0 ; // Clear Timer 5 Interrupt FlagIEC1bits . T5IE = 0 ; // Clear Timer 5 interrupt enable b i tT5CONbits .TON = 1 ; // Enable Timer 5

}

/∗���������������������������������������������������������������������Function Name: InitUART1Description : UART2 Configuration

�����������������������������������������������������������������������∗//∗void InitUART1() {

// ============> Remappable Pin Configuration <==============TRISBbits .TRISB12 = 1; //RP12 = inputTRISBbits .TRISB13 = 0; //RP13 = outputRPINR18bits .U1RXR = 12; //U1RX ��> RP12 cfr p.181RPOR6bits .RP13R = 3; //U1TX ��> RP13 cfr p.62 & 167 ! !

//============================================================

U1MODEbits.STSEL = 0; // 1�stop b i tU1MODEbits.PDSEL = 0; // No Parity , 8�data b i t sU1MODEbits.ABAUD = 0; // Auto�Baud DisabledU1MODEbits.BRGH = 0; // Low Speed modeU1BRG = BRGVAL; // BAUD Rate Sett ing for 9600

U1MODEbits.UARTEN = 1;U1STAbits .UTXEN = 1;

U1STAbits .UTXISEL1 = 1; // 1 ou 00000U1STAbits .UTXISEL0 = 1;U1STAbits .URXISEL = 0;

// i n i t i a l i s a t i o n des interrupt ions en receptionIFS0bits .U1RXIF = 0; // Reset U1RXIF interrupt f l a gIFS0bits .U1TXIF = 0;

IPC2bits .U1RXIP = 3; // U1RXIF Interrupt pr ior i ty l e v e l=3

70

Annexes

Page 72: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

IEC0bits .U1RXIE = 1; // Enable U1RX interrupt

IEC0bits .U1TXIE = 0;IEC0bits .U1RXIE = 0;IEC4bits .U1EIE = 0;

}∗/

/∗���������������������������������������������������������������������Function Name: InitADC1Description : ADC1 in i t i a l i z a t i o n (12 bi t s , ch0 , . . . . )

�����������������������������������������������������������������������∗/

void initADC1 ( ) {// To configure an ADC we have to :// � configure the input pin ANx as analogic// � configure the 3 reg i s t e r : ADxCON1, ADxCON2, ADxCON3

//AD1CHS0: A/D Input Se lect RegisterAD1CHS0bits .CH0SA = 1 ; // MUXA +ve input se l ec t ion (AN1) for CH0AD1CHS0bits .CH0NA = 0 ; // MUXA �ve input se l ec t ion (Vref�) for CH0//AD1CHS123 = 0x0000 ; // unimplemented when ad12b = 1 ( se l e c t ANx to be connected to

the Samp/H amp.

AD1PCFGL=0xFFFF ; // Put a l l port as d i g i t a l , then contro l l ed by the TRISx, LATx, and PORTx reg i s t e r s

AD1PCFGLbits .PCFG0 = 0 ; // except AN0AD1PCFGLbits .PCFG1 = 0 ; // and AN1 that we put in analog mode.TRISAbits .TRISA0 = 1 ; //Port pin used as ADC pins as inputs

// AD1CON1: set channel scanning here , auto sampling and convert , with de fau l t read�format mode

AD1CON1 = 0x0000 ;AD1CON1bits .ADON=0; // ADC is off , l e t configure ADC correct lyAD1CON1bits .ADSIDL=1; // Stop module operation in Id le modeAD1CON1bits .ADDMABM=0; // DMA buf fers are written in Scatter/Gather modeAD1CON1bits .AD12B=1; // 12�bi t , 1�channel ADC operationAD1CON1bits .FORM=0; // Data Output Format b i t s = Integer (000 dddd dddd dddd)//AD1CON1bits .FORM=3; // Data Output Format : Signed Fraction (Q15 format )

//AD1CON1bits .SSRC=0; // clear sample b i t s ta r t s convertion == Manuel Trigger (withAD1CON1bits .SAMP)

AD1CON1bits .SSRC=4; // Timer5 generates SOC tr i gger//AD1CON1bits .SSRC = 7; // Internal Counter (SAMC) ends sampling and s tar t s conversion

//AD1CON1bits .SIMSAM=1; //unimplemented in 12�b i t s modeAD1CON1bits .ASAM=1; // Sampling begins immediately a f ter conversion

AD1CON1bits .SAMP=1; // ADC sampling

//DMAAD1CON1bits .ADDMABM = 1; // DMA buf fers are bu i l t in conversion order mode

// AD1CON2AD1CON2 = 0x0000 ;AD1CON2bits .CHPS = 0 ; // unimplemented in 12�b i t mode � Converts CH0AD1CON2bits . SMPI = 0 ; // SMPI must be 0 = how often the DMA RAM buf fer pointer i s

incremented .

// AD1CON3 Set sample and b i t conversion time .AD1CON3bits .ADRC = 0 ; // ADC Clock i s derived from Systems Clock// cfr p.28 (ADC with example datasheet )AD1CON3bits .ADCS = 2 ; // Only used i f AD1CON3bits .ADRC = 0// Tsmp = SAMC∗Tad Tad = ADC clock period// 117 ,6ns<Tad ( c fr . p .389) Tad = 1/Fcy∗(ADCS+1)= 147 ns ==> 6,79Mhz// ==> Tsmp = 147 ns & Fcy = 20360000// http ://www. microchip .com/forums/tm. aspx?m=439681&high=adc+uart// ADC Conversion Time for 12�b i t Tconv = 14 ∗ TAD = 2063 ns (485 KHz)// then 485 kHz w i l l be the max Fs sampling speed ( c fr timer5 et PR5/Fs value )

//AD1CON3bits .SAMC = 3; // only used i f AD1CON1bits .SSRC=7//AD1CON3bits .SAMC = 0; // Auto Sample Time = 0∗Tad

//AD1CON4. . . . . . . . // set up the number of conversion resu l t stored in DMA buf ferfor each ANx

// ADC interrupt reg i s t e rIFS0bi t s .AD1IF = 0 ; // Clear the A/D interrupt f l a g b i tIEC0bits .AD1IE = 0 ; // disab le A/D interrupt

71

Annexes

Page 73: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

// s tar t ADCAD1CSSL = 0x0000 ; // skip ANx for input scanAD1CON1bits .ADON = 1 ; // Turn on the A/D converter

}

void modifyADC1_input ( ) {AD1CHS0bits .CH0SA = 0 ; // MUXA +ve input se l ec t ion (AN0) for CH0

}/∗������������������������������������������������������������������������������������

Function Name: initDMA0Description : Read from peripheral address 0�x300 (ADC1BUF0) and write to DMA RAM

AMODE: Register indirec t with post incrementMODE: Continuous , Ping�Pong ModeRQ: ADC InterruptADC stores re su l t s stored a l t e rna t i v e l y between BufferA [ ] and BufferB [ ]

��������������������������������������������������������������������������������������∗/

void initDma0 ( ) {DMA0CONbits .AMODE = 0 ; // Configure DMA for Register ind irec t with post incrementDMA0CONbits .MODE = 2 ; // Configure DMA for Continuous Ping�Pong mode

DMA0PAD = ( int )&ADC1BUF0; // Peripheral Address Register : ADC buf ferDMA0CNT = (FFT_BLOCK_LENGTH�1) ; // DMA Transfer Count i s (FFT_BLOCK_LENGTH�1)

DMA0REQ = 13 ; // ADC interrupt se lec ted for DMA channel IRQ

DMA0STA = __builtin_dmaoffset ( BufferA ) ; // DMA RAM Start Address ADMA0STB = __builtin_dmaoffset ( BufferB ) ; // DMA RAM Start Address B

IFS0bi t s .DMA0IF = 0 ; // Clear the DMA interrupt f l a g b i tIEC0bits .DMA0IE = 1 ; // Set the DMA interrupt enable b i t

DMA0CONbits .CHEN = 1 ; // Enable DMA channel}

72

Annexes

Page 74: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

MPLab: MainFFTComplexIP.c#include <p33Fxxxx . h>#include "dsp . h"#include " s td i o . h"#include " s t d l i b . h"

#include " . . \ h\ i n i t . h"#include " . . \ h\ I IR_Fi l ter . h" // FIR Dig i ta l F i l t e r#include " . . \ h\MyBandstop50 . h"#include " . . \ h\MyBandstop100 . h"#include " . . \ h\MyBandstop200 . h"

#define LED_RED2 LATBbits .LATB11#define LED_RED1 LATBbits .LATB12#define LED_MID LATBbits .LATB13#define LED_GREEN1 LATBbits .LATB14#define LED_GREEN2 LATBbits .LATB15

#define NUM_SAMPLES 512

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ PIC Configuration ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

_FWDT(FWDTEN_OFF) ;_FOSCSEL(FNOSC_FRC) ;_FOSC(FCKSM_CSECMD & OSCIOFNC_OFF & POSCMD_NONE) ;_FPOR(PWMPIN_ON & HPOL_ON & LPOL_ON & FPWRT_PWR32) ;_FICD(JTAGEN_OFF & ICS_PGD1) ;_FBS(BSS_NO_FLASH & BWRP_WRPROTECT_OFF) ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ g loba l var iab le ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

int flagTmr32 = 0 ;int flagTmr1 = 0 ;int f l a g = 0 ;int i , j , k ;int m = 0;

// ADCint ADC_value ; // max of int = 65535int ADC_Peak;int ADC_signal [FFT_BLOCK_LENGTH] ;int ADC_meanedin [FFT_BLOCK_LENGTH] ;int ADC_meanedout [FFT_BLOCK_LENGTH] ;int ADC_meaned1 [FFT_BLOCK_LENGTH] ;int ADC_meaned2 [FFT_BLOCK_LENGTH] ;int ADC_meaned3 [FFT_BLOCK_LENGTH] ;

long int ADC_Offset , FFT_acq ;int Of f s e t ;

unsigned int DmaBuffer = 0 ; // Dma var iab leextern f r a c t i o n a l BufferA [FFT_BLOCK_LENGTH] ; // Ping pong buf fer Bextern f r a c t i o n a l BufferB [FFT_BLOCK_LENGTH] ; // Ping pong buf fer B

// FFTint PeakFrequency ;int FFTPeakValue ;unsigned int FFT_ACQ[FFT_BLOCK_LENGTH/2 ] ;int FFT_Normilized [FFT_BLOCK_LENGTH/2 ] ;

f ractcomplex twidd leFactor s [FFT_BLOCK_LENGTH/2 ] __attribute__ (( s e c t i on ( " . xbss , �bss , �xmemory" ) ,a l i gned (FFT_BLOCK_LENGTH∗2) ) ) ;

f ractcomplex sigCmpx [FFT_BLOCK_LENGTH] __attribute__ (( space (ymemory) , far , a l i gned (FFT_BLOCK_LENGTH ∗ 2 ∗2) ) ) ;

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Main ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

int main (void ) {

Osc_conf igurat ion ( ) ;

73

Annexes

Page 75: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Pin_conf igurat ion ( ) ;initADC1 ( ) ;InitTimer32 ( ) ;initTmr1 ( ) ;initDma0 ( ) ;initTmr5 ( ) ;// TwiddleFactor and Hamming Window in i t i a l i z a t i o nTwidFactorInit (LOG2_BLOCK_LENGTH, &twidd leFactor s [ 0 ] , 0 ) ;// Call the FIRFilterInit routine to zero out the delay l ineI IRTran spo s eF i l t e r I n i t ( &MyBandstop50Filter ) ;I IRTran spo s eF i l t e r I n i t ( &MyBandstop100Filter ) ;I IRTran spo s eF i l t e r I n i t ( &MyBandstop200Filter ) ;

i f (ADC1BUF0 < 2000) { // Check Battery l e v e lLED_RED2 = 1 ;do{

i f ( flagTmr32 ) {LED_RED2 = ~LED_RED2;flagTmr32 = 0 ;i++;

}}while ( i < 5) ;

}else {modifyADC1_input ( ) ;while (m<1){ // one loop i s enough

while (k<10){ // Do 10 ADC Acq before computing FFT// while (1){ // Testing ADC

i f ( f l a g ) { // DMA f l ag interrupt

//�������������������clean some variab les��������������������

ADC_value = ADC_Peak = ADC_Offset = Of f s e t = 0 ;LED_RED2 = LED_RED1 = LED_MID = LED_GREEN1 = 0 ; // Shut Down Led Signal Power

Indicator

//������������������������� ADC Acquisition ������������������

for ( i =0; i < FFT_BLOCK_LENGTH; i++){ // Get ADC Value from DMA// And put 512 ADC value in sigCmpx . rea l

i f (DmaBuffer == 0) {ADC_value = BufferA [ i ] ;

}else {

ADC_value = BufferB [ i ] ;} sigCmpx [ i ] . r e a l = ADC_value ;ADC_signal [ i ] = sigCmpx [ i ] . r e a l ; // Watch Window debug

i f (ADC_signal [ i ] > ADC_Peak) {ADC_Peak = ADC_signal [ i ] ; // Getting ADC Peak value

}}

//��������Offset ca lcu la t ion and recording of 5 consecutive ADC������������

for ( i = 0 ; i < FFT_BLOCK_LENGTH; i++) // Calculate OffsetADC_Offset = ADC_Offset + sigCmpx [ i ] . r e a l ; // Sum of elements

ADC_Offset = ADC_Offset>>(LOG2_BLOCK_LENGTH) ; // Divide by number of elementsOf f s e t = ADC_Offset ; // Watch Window debug

for ( i = 0 ; i < FFT_BLOCK_LENGTH; i++){ // Removing the OffsetsigCmpx [ i ] . r e a l = sigCmpx [ i ] . r e a l � ADC_Offset ;sigCmpx [ i ] . imag = 0 ;ADC_meanedin [ i ] = sigCmpx [ i ] . r e a l ;

}//�������������������������� FIR 50h 100 and 200 hz Fi l t e r ���������������������

BlockI IRTransposeFi l t e r ( &MyBandstop50Filter , &ADC_meanedin [ 0 ] , &ADC_meanedout [ 0 ] ,NUM_SAMPLES ) ;

BlockI IRTransposeFi l t e r ( &MyBandstop100Filter , &ADC_meanedout [ 0 ] , &ADC_meanedin [ 0 ] ,NUM_SAMPLES ) ;

BlockI IRTransposeFi l t e r ( &MyBandstop200Filter , &ADC_meanedin [ 0 ] , &ADC_meanedout [ 0 ] ,NUM_SAMPLES ) ;

// Correcting unexpected obtained high peak at the beginning of ADC vec .for ( i = 0 ; i < 10 ; i++){ // 10 1 s t value of ADC give unexpected high

value . .i f ( ADC_meanedout [ i ] >500)

ADC_meanedout [ i ] = 100 ;i f ( ADC_meanedout [ i ]<�500)

ADC_meanedout [ i ] = �100;

74

Annexes

Page 76: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

}for ( i = 502 ; i < 512 ; i++){ // 10 1 s t value of ADC give unexpected high

value . .i f ( ADC_meanedout [ i ] >500)

ADC_meanedout [ i ] = 100 ;i f ( ADC_meanedout [ i ]<�500)

ADC_meanedout [ i ] = �100;}

for ( i = 0 ; i < FFT_BLOCK_LENGTH; i++){switch ( k ) { // Watch Window debug of consecutive ADC acquis i t ion

case 6 : // k depends of the while loopADC_meaned1 [ i ] = ADC_meanedout [ i ] ; // Watch Window debugbreak ; // Just to see 5 consecutive acquis i t ionscase 7 :ADC_meaned2 [ i ] = ADC_meanedout [ i ] ;break ;case 8 :ADC_meaned3 [ i ] = ADC_meanedout [ i ] ;break ;

}sigCmpx [ i ] . r e a l = ADC_meanedout [ i ] ;

}

//����������������������������������� FFT COMPUTING �����������������������������

FFTComplexIP (LOG2_BLOCK_LENGTH, & sigCmpx [ 0 ] , &twidd leFactor s [ 0 ] ,COEFFS_IN_DATA) ; // Perform FFT operation

BitReverseComplex (LOG2_BLOCK_LENGTH, &sigCmpx [ 0 ] ) ;

for ( i = 0 ; i < FFT_BLOCK_LENGTH; i++){ // Watch Window debugi f ( sigCmpx [ i ] . r ea l <0)

sigCmpx [ i ] . r e a l = �sigCmpx [ i ] . r e a l ;FFT_ACQ[ i ] = FFT_ACQ[ i ] + sigCmpx [ i ] . r e a l ;

}

f l a g = 0 ;LED_GREEN2 = ~LED_GREEN2; // b l ink ing led @ 1hz (512 DMA samples are made

each 1sec )

//������������������������������� Led Signal � Power indicator ����������������������������

i f (ADC_Peak > 4090) { // Visual LED HelpLED_RED2 = LED_RED1 = LED_MID = LED_GREEN1 = 1 ;

}else i f (ADC_Peak > 3500) { // Visual LED Help

LED_RED1 = LED_MID = LED_GREEN1 = 1 ;}else i f (ADC_Peak > 3200) { // Visual LED Help

LED_MID = LED_GREEN1 = 1 ;}else i f (ADC_Peak > 2800) { // Visual LED Help

LED_GREEN1 = 1 ;}

k++;} // end i f ( f l a g )

} // c los ing whileLED_RED2 = LED_RED1 = LED_MID = LED_GREEN1 = LED_GREEN2 = 0 ; // shut down a l l LED

//�������������������������� Normalization of the FFT Result ������������������������������

// removing unexpected big value due to noise and d i s tor t ing normlized FFTFFT_ACQ[ 0 ] = 0 ;FFT_ACQ[ 4 8 ] = FFT_ACQ[ 4 9 ] = (FFT_ACQ[47]+FFT_ACQ[ 5 1 ] ) /2 ;FFT_ACQ[ 1 5 0 ] = (FFT_ACQ[149]+FFT_ACQ[ 1 5 1 ] ) /2 ;FFT_ACQ[ 1 8 0 ] = (FFT_ACQ[179]+FFT_ACQ[ 1 8 1 ] ) /2 ;

FFTPeakValue = 0 ;for ( i =0; i <256; i++){i f (FFT_ACQ[ i ]>FFTPeakValue ) {

FFTPeakValue=FFT_ACQ[ i ] ;PeakFrequency=i ;

}}

for ( i =0; i <256; i++){ // NormalizingFFT_acq = FFT_ACQ[ i ] ; // to avoid overflow of intFFT_Normilized [ i ] =FFT_acq∗100/FFTPeakValue ;

}

75

Annexes

Page 77: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

m++;} // c los ing while

} // c los ing check battery e l se} // c los ing main

/∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗ Timer interrupt ∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗∗/

void __attribute__ (( in te r rupt , no_auto_psv ) ) _DMA0Interrupt (void ) {DmaBuffer ^= 1 ; // Ping�pong buf fer s e l e c t f l a gf l a g = 1 ; // Ping�pong buf fer f u l l f l a g

// Ping�pong l e t a buf fer to be readed when the others i s ge t t ing new valuesIFS0bi t s .DMA0IF = 0 ; // Clear the DMA0 Interrupt Flag

}

void __attribute__ (( __interrupt__ , no_auto_psv ) ) _T1Interrupt (void ) {// 1024Hz, then we w i l l be able to t r i gger our An0 input to convert an ADC valueIFS0bi t s . T1IF = 0 ; // Clear Timer1 Interrupt FlagflagTmr1 = 1 ; //not used

}

void __attribute__ (( __interrupt__ , no_auto_psv ) ) _T3Interrupt (void ) {// 1hzflagTmr32 = 1 ; // Not usedIFS0bi t s . T3IF = 0 ; // Clear Timer3 Interrupt Flag

}

76

Annexes

Page 78: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

MPLab: MyBandstop50.s; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .; F i l e MyBandstop50 . s; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

. equ MyBandstop50NumSections , 1

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .;; A l l o ca t e and i n i t i a l i z e f i l t e r c o e f f i c i e n t s;; These c o e f f i c i e n t s have been des igned for use in the Transpose f i l t e r only

. s e c t i on . MyBandstop50const , "x"

MyBandstop50Coefs :. hword 0x3F35 ; b( 1 ,0) /2. hword 0x989C ; b( 1 ,1) /2. hword 0x6764 ; a ( 1 ,1) /2. hword 0x3F35 ; b( 1 ,2) /2. hword 0xC195 ; a ( 1 ,2) /2

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .; A l l o ca t e s t a t e s bu f f e r s in ( u n i n i t i a l i z e d ) Y data space

. s e c t i on . ybss , "b"

MyBandstop50States1 :. space MyBandstop50NumSections∗2

MyBandstop50States2 :. space MyBandstop50NumSections∗2

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .; A l l o ca t e and i n t i a l i z e f i l t e r s t r u c tu r e

. s e c t i on . data

. g l oba l _MyBandstop50Filter

_MyBandstop50Filter :. hword MyBandstop50NumSections�1. hword p s v o f f s e t ( MyBandstop50Coefs ). hword psvpage ( MyBandstop50Coefs ). hword MyBandstop50States1. hword MyBandstop50States2. hword 0x0000

; . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .; Sample assembly language c a l l i n g program; The f o l l ow ing d e c l a r a t i o n s can be cut and pasted as needed in to a program; . extern _IIRTransposeF i l t e r In i t; . extern _BlockIIRTransposeFi l ter; . extern _MyBandstop50Filter;; . s e c t i on . bss;; The input and output bu f f e r s can be made any de s i r ed s i z e; the value 40 i s j u s t an example � however , one must ensure; that the output bu f f e r i s at l e a s t as long as the number o f samples; to be f i l t e r e d ( parameter 4); input : . space 40; output : . space 40; . t ext;;; This code can be copied and pasted as needed in to a program;;; Set up po in t e r s to ac c e s s input samples , f i l t e r taps , de lay l i n e and; output samples .; mov #_MyBandstop50Filter , W0 ; I n i t a l i z e W0 to f i l t e r s t r u c tu r e; c a l l _I IRTransposeF i l t e r In i t ; c a l l t h i s func t i on once;; The next 4 i n s t r u c t i o n s are r equ i r ed p r i o r to each subrout ine c a l l; to _BlockIIRTransposeFi l ter; mov #_MyBandstop50Filter , W0 ; I n i t a l i z e W0 to f i l t e r s t r u c tu r e; mov #input , W1 ; I n i t a l i z e W1 to input bu f f e r; mov #output , W2 ; I n i t a l i z e W2 to output bu f f e r; mov #20, W3 ; I n i t i a l i z e W3 with number o f r equ i r ed output samples; c a l l _BlockIIRTransposeFi l ter ; c a l l as many times as needed

77

Annexes

Page 79: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Matlab code : FFT of a read .wav file%% FFT of a wave F i l e%% This code ge t s va lues from an audio . wav f i l e and analyze i t% in the f requency domain .%

% Get value and frequency sample o f the . wav f i l e% [1 175000] l e t s choose a part o f the . wav f i l e% And only analyze one o f the s t e r e o channel[ x , f s ]=wavread ( ’ 01 . Normal�Heartbeat . wav ’ , [ 1 120000 ] ) ;data = x ( : , 1 ) ;

%% Apply an Hamming window to my s i g n a l and compute FFT%H=data .∗hamming( l ength ( data ) ) ;Y=f f t (H) ;

%% plo t waveform%f i g u r e (1) ;t =(0: l ength ( data )�1)/ f s ;subplot (2 , 1 , 1 ) ;p l o t ( t , data ) ;l egend ( ’ 01 . Normal�Heartbeat . wav ’ ) ;x l ab e l ( ’Time� ( s ) ’ ) ;y l ab e l ( ’ Amplitude ’ ) ;g r id on ;

%% Plot FFT%hz500=500∗ l ength (Y) / f s ; % max des i z ed x�ax i s f requency valuef =(0: hz500 ) ∗ f s / l ength (Y) ;

subplot (2 , 1 , 2 ) ;p l o t ( f ,20∗ l og10 ( abs (Y( 1 : l ength ( f ) ) )+eps ) ) ;l egend ( ’FFT ’ ) ;x l ab e l ( ’ Frequency� (Hz) ’ ) ;y l ab e l ( ’ Magnitude� (dB) ’ ) ;g r id on ;

78

Annexes

Page 80: 01+2*345(,$*67894:4)4%(* ,(2* …files.isec.pt/DOCUMENTOS/SERVICOS/BIBLIO/teses/Tese_Mest_Jerome... · Resumo O objectivo deste trabalho é o desenvolvimento de um dispositivo DSP

Matlab code : FFT of a live audio acquisitionf p r i n t f ( ’ Press �any�key�when�you� are � ready� to � record �5 sec � o f �your� heartbeat \n ’ ) ;pausef p r i n t f ( ’ Recording . . . \ n ’ ) ;

%Wave record from the microphoneFs = 44100;y = wavrecord (4∗Fs , Fs , ’ in t16 ’ ) ;f p r i n t f ( ’Done ! �Here� i s � the � r e s u l t : \ n ’ ) ;%wavplay (y , Fs ) ;

%Saving the audio F i l ewavwrite (y , Fs , ’ l i v eda t a . wav ’ ) ;

%Read the wav f i l e[ x , f s , nb i t s ]=wavread ( ’ l i v eda t a . wav ’ ) ;

%In case o f x i s s t e r e odata = x ( : , 1 ) ;

%% plo t waveformf i g u r e (2) ;t =(0: l ength ( data )�1)/ f s ; % times o f sampling i n s t an t ssubplot (2 , 1 , 1 ) ;p l o t ( t , data ) ;l egend ( ’Wav���My� heart ’ ) ;x l ab e l ( ’Time� ( s ) ’ ) ;y l ab e l ( ’ Amplitude ’ ) ;%% do f o u r i e r transform of windowed s i g n a lY=f f t ( data .∗hamming( l ength ( data ) ) ) ;%% plo t spectrum of bottom 500Hzhz500=250∗ l ength (Y) / f s ;f =(0: hz500 ) ∗ f s / l ength (Y) ;subplot (2 , 1 , 2 ) ;p l o t ( f ,20∗ l og10 ( abs (Y( 1 : l ength ( f ) ) )+eps ) ) ;l egend ( ’FFT���My� heart ’ ) ;x l ab e l ( ’ Frequency� (Hz) ’ ) ;y l ab e l ( ’ Magnitude� (dB) ’ ) ;g r id on ;

79

Annexes