Obtain heartbeat sound from pulse sensor

Hello all, my recent project is for an artist who has sculpted heart and lungs. my task is to use a pulse sensor which will grab the pulse and output through LED’s to light up the art along with mimicking the heartbeat sound and send it out a piezo speaker. I already have the LEDs working accordingly however I am stuck converting this analog reading to an actual heartbeat sound, my instructor said it can be done and explained to use the fast Fourier transform (FFT) library. I have the library already I just have no idea where to start. Any info would be greatly appreciated. This is also my first time with Arduino so I’m still learning the basics.

Code so far…

#include <FFT.h>
//  Variables
int PulseSensorPurplePin = 0; // Pulse Sensor PURPLE WIRE connected to ANALOG PIN 0
int LED = 13; //  The on-board Arduion LED
int SPEAKER = 9;// Pin for speaker.
int Signal; // holds the incoming raw data. Signal value can range from 0-1024
int Threshold = 150; // Determine which Signal to "count as a beat", and which to ingore. 
// The SetUp Function
void setup() 
{   
   pinMode(LED,OUTPUT); // pin that will provide output for blinking LED(s).
   Serial.begin(9600); // Set's up Serial Communication at certain speed.    
}
// The Main Loop Function
void loop() 
{
   Signal = analogRead(PulseSensorPurplePin);  // Read the PulseSensor's value. 
                                              // Assign this value to the "Signal" variable  
   float signalSe = (float(Signal) * 255.0) / 1024.0;
   
   Serial.println(signalSe); // Send the Signal value to Serial Plotter.

   if(signalSe > Threshold)
   {                           
     digitalWrite(LED,HIGH); // If the signal is above "150", then "turn-on" LEDs.          
   }   
   else 
   {
     digitalWrite(LED,LOW); //  Else, the sigal must be below "150", so "turn-off" LEDs.
   }
}

Anyone?? Here is some additional code which does need some slight modification…

#define LOG_OUT 1 // use the log output function
#define FFT_N 256 // set to 256 point fft

#include <FFT.h> // include the library

//#include <VirtualWire.h>

//boolean P[] = {false, false, false, false}; // states
//long tstart[] = {0, 0, 0, 0};   // start times
//long et[] = {0, 0, 0, 0};  // elapsed times
//long TT[] = {15000, 15000, 15000, 15000};  // Total times = Period*Duration   saves 16 bytes

//float thr[] = {1.2, 1.4, 1.6, 1.8};  // thresholds   saves 16 bytes

void setup()
{
  Serial.begin(9600);  // for debugging
  ADCSRA = 0xe5; // set the adc to free running mode
  ADMUX = 0x40; // use adc0
  DIDR0 = 0x01; // turn off the digital input for adc0
}
void loop()
{
    int i;
    for (i = 0 ; i < 512 ; i += 2) { // 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
      fft_input[i] = k; // put real data into even bins
      fft_input[i+1] = 0; // set odd bins to 0
      delay(1);  // dt = 5ms
    } // close for
     //for (i = 0 ; i < 127 ; i++) {  //Prints inputs 
       //  Serial.println(fft_input[2*i]); // send out the data
    //} 
   // duration = millis()-duration;
   // Serial.println(duration);

   // with N=256 and dt=5ms our sample duration is T=1.283=9/7 seconds
   // and so our frequency axis is chopped into pieces of size 
   // dw = 1/T = 7/9 Hz, so the alpha band of 8 to 13 Hz
   // will reside in bin numbers 10 through 17 while the beta band of
   // 18 to 25 Hz will reside in bins 23 through 33
    
    fft_window(); // window the data for better frequency response
    fft_reorder(); // reorder the data before doing the fft
    fft_run(); // process the data in the fft
    fft_mag_log(); // take the output of the fft
      sei();
    for (i = 0 ; i < 127 ; i++) { 
      if (i < 20)
      {
        Serial.println(0); // send out the data
        }
        else{  
         Serial.println(fft_log_out[i]); // send out the data
        }
    }

}  // close main loop

Please explain exactly what information you are supplying the FFT library and what information you expect it to return.

Paul

What constitutes a "heart beat sound" and what would be acceptable for the project?

Are you thinking of the sounds that are used in movies, or have you listened to a heartbeat using a stethoscope?

I suggest to work with the artist to play whatever sound he/she thinks is appropriate, using an MP3 module or similar.

The strictly mathematical operation known as the Fast Fourier Transform will not help in that regard, guaranteed.

I don't really understand what you're trying to do.

So you're trying to hook it up to some artwork, that's rather clear.

rogernm001: grab the pulse

What/whose pulse? How exactly do you plan to grab it - which sensor?

If from the artwork - why not link up with whatever produces the pulse inside the artwork?

Anyway, all you really need is the timing of the pulse, when it happens. Based on that you can play any sound or flash any lights as you see fit. One thing you have to work around is that you can hear the pulse only as it happens, so the lights/sounds are always a bit delayed. Whether that's an issue depends on your artwork. If that is an issue you have to predict when the next pulse happens based on the previous two pulses, and work with that.