Introduction: Fast Hartley Transform Spectral Stethoscope

Picture of Fast Hartley Transform Spectral Stethoscope

In this instructable you will learn how to make a spectral stethoscope using the fast hartley transform. This can be used to visualize heart and lung sounds.

Step 1: Materials

1.8” LCD Screen ($7.50 on Amazon)

Arduino Uno or Equivalent ($7.00 on Gearbest)

Electret Amplifier ($6.95 on Adafruit)

100 µF Capacitor ($0.79)

Wire and Jumpers ($4.00)

3.5mm Stereo Jack ($1.50)

10kOhm Potentiometer ($2.00)

Momentary Switch ($1.50)

Step 2: Tools

Soldering Iron

Hot Glue Gun

3D Printer...or a friend with a 3D printer (Possible to make with cardboard as well)

Wire Cutter

Breadboard

Step 3: 3D Printing

The first is to 3D print the .stl files attached to this step. I printed both files using the following material/settings:

Material: PLA

Layer Height: 0.1mm

Wall/Top/Bottom Thickness: 0.8mm

Printing Temperature: 200⁰C

Bed Temperature: 60⁰C

Support Enabled @ 10%

Step 4: Construct Circuit

Using the components in the materials section, build the circuit. I always put the circuit together on a breadboard first to make sure it’s working properly before touching the soldering iron.

Step 5: LCD Wiring

Picture of LCD Wiring

Using the figure attached to this step, solder wires to seven of the eight pins on the LCD screen. These wires will need to be about 3 feet in length, except for the ground and +5V pins (these only need to be 2-3 inches)

Step 6: Mic/Amplifier Wiring

Picture of Mic/Amplifier Wiring

Using the figure attached to this step solder three wires to the +5V, Ground, and Out pins on the Adafruit microphone/amplifier. These only need to be about 2-3 inches in length.

Step 7: Momentary Switch Wiring

Wire one 2-3 inch wire to each of the two lugs on the momentary switch.

Step 8: Potentiometer Wiring

Using the figure in step 6, solder three wires about 2-3 inches in length to the three lugs of the potentiometer.

Step 9: Headphone Jack Wiring

Solder three wires to the ring, tip, and sleeve lugs of the headphone jack. I used a jack out of a metronome that was already wired. If you do not know what the ring, tip, and sleeve lugs are, just google it there are a lot of good images about wiring stereo jacks.

Step 10: Microphone/Amplifier Output

After soldering the wires on the mic/amp, potentiometer, and headphone jack, solder one wire about three feet in length to the "out" wire of the microphone amplifier. This wire will later be connected to the A0 pin of the arduino.

Step 11: Microphone/Amplifier Output Continued

Solder a second wire to the "out" wire of the mic/amplifier. This wire needs to be soldered to a 100 microFarad capacitor. If you're using an electrolytic capacitor, make sure the positive side is connected to this wire.

Step 12: Components in Enclosure

Picture of Components in Enclosure

After all the wires are soldered on the components, place the components in there respective places following the figures attached to this step. I used hot glue to secure the microphone and headphone jack in place.

Step 13: In-Enclosure-Soldering

After all the components are secured in the enclosure, solder the all the ground wires together. There should be one from the LCD, one from the mic/amp, and one from the sleeve of the headphone jack. Also solder the +5V wires together and one wire from the momentary switch. Again there should be one from the LCD, one from the mic/amplifier, and one on the momentary switch.

Step 14: +5V, GND Extended Wires

Now cut two pieces of wire about 3 feet in length. Solder one to the cluster of ground wires and solder the other to the open wire on the momentary switch.

Step 15: Slip Long Wires Through Enclosure Hole

Picture of Slip Long Wires Through Enclosure Hole

Now, you should have a total of eight wires about 3 feet in length. Place these through the unfilled hole in the enclosure. See the figure attached to this step

Step 16: Heat Shrink

After all soldering is complete, make sure the exposed wires are covered up. I used heat shrink tubing, but electrical tape also works fine.

Step 17: Seal Enclosure

Picture of Seal Enclosure

Take the half of the enclosure containing the LCD screen and slip it over the other half of the enclosure containing the other components. While pushing the two pieces together, hot glue them to secure the enclosure together.

Step 18: Connect to Arduino

The eight, long, wires remaining are connected directly to their respective Arduino pins outlined in the circuit schematics. Make sure that every time you solder one of those long 3ft wires into the circuit that you put a piece of tape on the other end indicating what Arduino pin it goes to!

Step 19: Arduino IDE/Libraries

You will need to download the Arduino IDE. For this sketch, I used three different libraries: FHT.h, SPI.h, and TFT.h. If you do not know how to download Arduino libraries, please see https://www.arduino.cc/en/Guide/Libraries. The FHT.h library was downloaded from openmusiclabs.com. The other two were downloaded on GitHub.

Step 20: Arduino Sketch

The code uses the Fast Hartley Transform (FHT) to change the time domain to a frequency domain. This can also be done using the Fast Fourier Transform (FFT), but the FHT is much faster. The FFT and FHT are very fundamental ideas in signal processing and very fun to learn about. I suggest doing some reading yourself, if you’re interested see. The FHT example code I copied from the Open Music Labs website was initially outputting the amplitude of each frequency bin as a logarithmic or decibel output. I changed this to output the frequency bins on a linear scale. This is because the linear scale is a better visual representation of how humans hear sound. The for() loop at the end is for drawing the amplitude of each frequency bin on the LCD screen. The full FHT spectrum would encompass all frequency bins from i=0 to i<128. You will notice that my for() loop is from i=5 to i<40, this is because the frequencies important for diagnosing lung conditions are typically between 150Hz and 3.5khz, I decided to go up to about 4kHz. That can be adjusted if you want to show the full frequency spectrum.

[code]

//Digital Stethoscope Code

//Fast Hartley Transform library downloaded from openmusiclabs

#define LIN_OUT 1 //set FHT to produce linear output

#define LOG_OUT 0 //turn off FHT logarithmic output

#define FHT_N 256 //FHT sample number

#include //include FHT library

#include //include TFT library

#include //include SPI library

#define cs 10 //set lcd cs pin to arduino pin 10

#define dc 9 //set lcd dc pin to arduino pin 9

#define rst 8 //set lcd reset pin to arduino pin 8

TFT myScreen = TFT(cs, dc, rst);//declare name of TFT screen

void setup() {

//Serial.begin(9600);//set sampling rate

myScreen.begin();//initialize TFT screen

myScreen.background(0, 0, 0);//set background to black

ADCSRA=0xe5;//set adc to free running mode

ADMUX=0x40;//use adc0

}

void loop() {

while(1){ // reduces jitter cli(); // UDRE interrupt slows this way down on arduino1.0

for (int i = 0 ; i < FHT_N ; i++) { // save 256 samples

while(!(ADCSRA & 0x10)); // wait for adc to be ready

ADCSRA = 0xf5; // restart adc byte

m = ADCL; // fetch adc data byte

j = ADCH; int k = (j << 8) | m; // form into an int

k -= 0x0200; // form into a signed int

k <<= 6; // form into a 16b signed int

fht_input[i] = k; // put real data into bins

}

fht_window(); // window the data for better frequency response

fht_reorder(); // reorder the data before doing the fht

fht_run(); // process the data in the fht

fht_mag_lin(); // take the output of the fht

sei();

for (int i=5;i<40;i++){

myScreen.stroke(255,255,255);

myScreen.fill(255,255,255);

int drawHeight=map(fht_lin_out[i],10,255,10,myScreen.height());

int ypos=myScreen.height()-drawHeight-8; myScreen.rect((4*i)+8,ypos,3,drawHeight);

}

myScreen.background(0,0,0);

}

}

[/code]

Step 21: Test It Out!

Picture of Test It Out!

I used an online tone generator (http://www.szynalski.com/tone-generator/) to confirm the code was working properly. After confirming it works, press the bell of the stethoscope up to your chest, take a deep breathe and see what frequencies are present!!

Step 22: Future Work

**Note: I am a chemist, not an engineer or computer scientist**. There will likely be mistakes and improvements to the design and code. That being said, I think it’s a good start to something that can end up being very useful and inexpensive. The following bullets are future improvements I would like to make and I hope some of you also try to improve it!

· Make the device mobile. I don’t have extensive experience with CPUs or other microcontrollers, but it would need to have enough memory to store the entire FHT library on, or possibly Bluetooth.

· Introduce some statistical analysis calculations into the code. For example, typically a wheeze has a fundamental frequency equal or greater than 400 Hz and lasts for at least 250 ms. Rhonchi occur at a fundamental frequency of about 200 Hz or less and lasts for at least 250 ms. Many other pulmonary sounds are defined and indicative of health conditions (http://commongiant.github.io/iSonea-Physicians/assets/publications/7_ISN-charbonneau-Euro-resp-Jour-1995-1942-full.pdf). I think that is something that can be checked for in the code by comparing the signal of the frequency bins after a certain number of cycles through the FHT and then running the millis() function to see how long it was present for, then comparing it to the noise floor of the FHT calculation. I’m confident these things can be done!

I hope you all had fun with this project and if you have any questions please comment and I will respond as soon as I can! I look forward to seeing comments.

Comments

TechKiwiGadgets (author)2017-05-27

nice work. lots of potential with this idea.

Thank you very much! If you have any questions I would love to answer them!

DIY Hacks and How Tos (author)2017-04-27

Great tutorial. Thanks for sharing with the community.

About This Instructable

285views

5favorites

License:

Bio: Work as a chemist. Passionate about engineering.
More by JordanL74:Fast Hartley Transform Spectral Stethoscope
Add instructable to: