Heart rate sensor MAX30102


Closed Thread
Results 1 to 40 of 85

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    but maybe you could back off on the filter settings for a clearer reading.
    i have tried many variations , the added aggressiveness of the filter is an attempt to remove the unwanted "little" peaks
    what looks like a nice picture of on a graph does not mean peak detection is easier.
    some of the lp filtering is just added in with excel also, even tried using trend lines in attempt at detecting pos and neg zero crossings
    that's still not 100% effective. dsp is not my forte, dc drift in the readings can be neg or pos going or both or zero.
    fft was a failure because i cannot remove the dc component effectively. i need a better method i have no effective strategy
    Warning I'm not a teacher

  2. #2
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    Here is a Filter algorithm that has served me well with several projects. For the moment I'm going to assume your code serves 2 main functions: read the heart rate MAX30102 and report the results. This means the processor execution time can be maximized for these 2 functions.

    Reporting process is what it is. That's whatever protocol (UART, SPI, I2C, or LCDOUT etc) you have chosen to make use of the processed data.

    As for reading and filtering the MAX30102 data, the first stage is to take multiple ADC reads (or appropriately retrieve the latest data report) each Subroutine CALL and average them. The result gets fed into a circular buffer, where the average is the last X readings, and what you shoot out in your report. It looks something like this:

    Somewhere a CALL (GOSUB) is made to check the input from the MAX30102 sensor. Within the Subroutine, you do this 4X and average the results. The average result is fed into a [4] BYTE/WORD circular buffer. An Accumulator adds all buffer entries and divides the result by the number of entries (calculates an average). The value reported is the average of the circular buffer -- buffered value. With me so far? Let's take it for a test drive, shall we?
    Code:
    b0 VAR BYTE ;Used for FOR/LOOP
    HrVal VAR BYTE ;if using 8-bit ADC, ...VAR WORD for 10-bit, or whatever protocol demands
    HrValBuf VAR BYTE[4] ;again, WORD for 10-bit, this is your 4 immediate ADC (MAX30102 input) reads Buffer
    HrValCir VAR BYTE[4] ;again, WORD for 10-bit, this is your 4 entry Circular Buffer
    HrBufAcc VAR WORD ;Total of all 4 HrValBuf readings
    HrCirAcc Var WORD ;Total of all 4 HrCirBuf readings
    HeartRate VAR BYTE ;again, WORD for 10-bit, End Filtered Result to be Reported or Processed
    
    ...  ;from Somewhere in Code:
    GOSUB Get_HeartRate
    GOSUB Send_HeartRate ;Do something with the HeartRate Value Acquired & Filtered
    ...  ;then Continue Code...
    
    Get_Heartrate:
     HrValCir[3] = HrValCir[2]  ;Rotate the Circular Buffer
     HrValCir[2] = HrValCir[1]
     HrValCir[1] = HrValCir[0]
     FOR b0 = 0 TO 3
      ADCIN MAX30102,HrVal ;or I2CREAD or SPIREAD -- Retrieve a Current Value
      HrValBuf[b0] = HrVal
     NEXT b0
     HrBufAcc = HrValBuf[3] + HrValBuf[2] + HrValBuf[1] + HrValBuf[0] ;Add All 4 Readings...
     HrValCir[0] = HrBufAcc >> 2 ;Same as HrValCir[0] = HrBufAcc / 4 -- Places the Latest Averaged Value into the Circular Buffer
     HrCirAcc = HrValCir[3] + HrValCir[2] + HrValCir[1] + HrValCir[0] ;Totals the Circular Buffer
     HeartRate = HrCirAcc >> 2 ;Same as HeartRate = HrCirAcc / 4, Averages the Circular Buffer
    RETURN
    To change the impact of the filter, you can increase or decrease the size of the HrValBuf[4] buffer and/or the HrValCir[4] buffer. If too jumpy, add more entries for either/both buffer(s). Conversely, to economize, try reducing buffer sizes and see if you still like the results. Changes would have to be reflected in Get_Heartrate:. No, of course this isn't the absolute most efficient code to accomplish the goal, and it is too abbreviated to actually work, but I hope it illustrates an effective filter that has served me well over many projects.
    Last edited by mpgmike; - 15th January 2022 at 01:52.

  3. #3
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    the filter is not really the issue, its the variability of the data that is problematical, every 128 sample is subtly different.
    light leakage, finger pressure and position and even finger compression time lead to wildly variable readings. my max30102 housing is probable not ideal either
    i use for this filter
    fv = fv*x + nv*(y)

    where x+y = 1, fv = average nv = new value

    in pbp terms x y
    ave = (ave ** 60000) + (buffer[index] ** 5535 ) ;60000 + 5535 = 65535
    or
    ave = (ave */ 250) + (buffer[index] */ 5 ) ;250+ 5 = 255

    depending on finesse required, the introduced phase shift has no bearing on the result either.
    it may not be as fast as your method but has better control and in this case speed is of no importance
    Last edited by richard; - 15th January 2022 at 04:49.
    Warning I'm not a teacher

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    well my sensor was not 5v tolerant its now a random number generator , in the bin
    i give up
    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    Richard which sensor did you have? Could you please let us know? for avoiding it in the future.

    Based on cardiovascular medical graph, the post #44 and post #49 looks fine.

    I think #49 it is a bit better which doesnt mean the in #44 the graph is not acceptable.

  6. #6
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    my module was clearly marked as 3.3v its the one with slots in the board to tie it on your finger
    the code has little if any effect on the graphical result. the result depends on your finger and its placement
    ambient light etc, my holder is a little tight it constricts circulation a bit and i need to change fingers every 10 minutes to get good data
    i found a spare [must have bought 2] i will be more careful with this one.

    i still cannot get a algo to find the right peaks. on a graph it looks so obvious even in the crappy reads beats are distinctive, by the absolute shits computers are stupid. breaking the search into 32 sample blocks gets me the block highest highs and lowest lows but there is no guarantee the high in a block is actually a peak or whether continues to ramp up into the next block
    Warning I'm not a teacher

  7. #7
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    I guess you have this one

    Name:  max30102 image.png
Views: 3647
Size:  393.0 KB

    https://www.teachmemicro.com/max3010...r-for-arduino/

    I also have 2 of those, but in the schematic the input voltage is 3.3V to 5V.

    Name:  max30102 image 2.png
Views: 3744
Size:  535.1 KB

    or you are talking about the logic level? So i also need to take care about it and supply the PIC with 3.3V.

  8. #8
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    I think the LPF should not be so aggressive.
    if you want automatic pulse measurement that remains to be seen, a pretty picture is a different story


    you can adjust filter as you see fit


    Quote Originally Posted by richard View Post
    the filter is not really the issue, its the variability of the data that is problematical, every 128 sample is subtly different.
    light leakage, finger pressure and position and even finger compression time lead to wildly variable readings. my max30102 housing is probable not ideal either
    i use for this filter
    fv = fv*x + nv*(y)

    where x+y = 1, fv = average nv = new value

    in pbp terms x y
    ave = (ave ** 60000) + (buffer[index] ** 5535 ) ;60000 + 5535 = 65535

    or
    ave = (ave */ 250) + (buffer[index] */ 5 ) ;250+ 5 = 255

    depending on finesse required, the introduced phase shift has no bearing on the result either.
    it may not be as fast as your method but has better control and in this case speed is of no importance



    @ PutMulResult?D _average ;RED AVERAGE
    ave = DIV32 128 ;RED AVERAGE
    reg = OVF_COUNTER
    i2cread sda,scl,ADDR,reg,[reg ]
    DEBUG 13,10,"OverFlows ",DEC reg,9,dec ave,9,hex ave
    FOR index = 0 TO 255 step 2
    ave = (ave ** 57000) + (buffer[index] ** 8535 )
    lpfdata[index>>1]=ave
    ;.....lpf..;;;;----red-----;;;;======-ir-========
    DEBUG 13,10,dec ave,9,dec buffer[index],9,dec buffer[index+1]

    NEXT
    ' RETURN
    Warning I'm not a teacher

  9. #9
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    sorry for my late response. I was really busy these days.

    thanks for the info. I will do some changes and tests.

  10. #10
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    4,115


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    I do not know if it is suitable for this project, but I had good results with Darrels Taylor ADC oversampling routines (http://dt.picbasic.co.uk/CODEX/AnalogueOverSampling).

    Also Kalman filters maybe of use. I find them difficult to implement though.

    Ioannis

  11. #11
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    no amount of low pass filtering will remove the dc component, ultimately it just makes it worse.
    the dc component needs to be removed to make detection of the beat peaks reliable.
    there is plenty of raw data posted, you can always ask for more. feel free to have a go
    Warning I'm not a teacher

  12. #12
    Join Date
    May 2013
    Location
    australia
    Posts
    2,631


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    I think Richard is eluding to a process called Fast Fourier Transform
    been there done that.

    Quote Originally Posted by richard View Post
    post#53 i have tried many variations , the added aggressiveness of the filter is an attempt to remove the unwanted "little" peaks
    what looks like a nice picture of on a graph does not mean peak detection is easier.
    some of the lp filtering is just added in with excel also, even tried using trend lines in attempt at detecting pos and neg zero crossings
    that's still not 100% effective. dsp is not my forte, dc drift in the readings can be neg or pos going or both or zero.
    fft was a failure because i cannot remove the dc component effectively. i need a better method i have no effective strategy
    The one that is like Example #1 in the textbooks is simply:
    there is plenty of raw data posted, you can always ask for more. feel free to have a go
    Last edited by richard; - 19th January 2022 at 22:22.
    Warning I'm not a teacher

  13. #13
    Join Date
    Apr 2014
    Location
    OK
    Posts
    557


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    Quote Originally Posted by richard
    there is plenty of raw data posted, you can always ask for more. feel free to have a go
    Quote Originally Posted by mpgmike
    I've looked into it briefly, just enough to get an idea of what it's about, but not enough to actually use it effectively.
    Thanks for the generous offer

  14. #14
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: Heart rate sensor MAX30102

    I did an other test on a different person. Those info are from a woman.

    Richard have done a very good job up to now. I think the LPF should not be so aggressive.

    Name:  woman result.png
Views: 3267
Size:  21.7 KB

    Code:
    LPF	RED	IR
    7278	7275	7077
    7277	7266	7038
    7275	7252	7048
    7273	7242	7018
    7270	7233	7012
    7268	7247	7003
    7266	7243	6991
    7264	7248	6987
    7263	7264	7005
    7260	7231	7002
    7257	7239	7008
    7256	7242	7025
    7256	7264	7015
    7255	7249	7039
    7255	7262	7037
    7255	7267	7062
    7254	7258	7047
    7255	7286	7075
    7255	7274	7086
    7256	7289	7082
    7257	7289	7096
    7257	7281	7083
    7257	7280	7105
    7258	7284	7089
    7259	7293	7124
    7260	7291	7150
    7260	7299	7122
    7260	7299	7144
    7261	7303	7143
    7263	7329	7164
    7264	7308	7173
    7265	7307	7183
    7266	7313	7163
    7268	7322	7167
    7269	7317	7171
    7270	7317	7193
    7273	7343	7198
    7275	7329	7205
    7277	7332	7194
    7279	7330	7224
    7281	7333	7201
    7281	7318	7166
    7280	7282	7125
    7278	7265	7068
    7276	7245	7029
    7273	7240	7003
    7270	7226	7016
    7267	7234	6989
    7263	7210	6988
    7259	7209	6977
    7257	7239	6970
    7254	7221	6966
    7252	7227	6977
    7249	7214	6998
    7247	7223	6998
    7245	7233	6996
    7243	7238	6996
    7241	7239	7010
    7239	7241	6995
    7238	7233	7028
    7237	7228	7036
    7237	7261	7039
    7236	7240	7049
    7237	7262	7052
    7237	7248	7062
    7238	7265	7085
    7239	7278	7108
    7241	7286	7106
    7242	7294	7136
    7243	7286	7141
    7244	7299	7148
    7246	7302	7182
    7248	7309	7159
    7250	7318	7173
    7252	7306	7192
    7255	7331	7192
    7256	7296	7212
    7259	7329	7187
    7261	7308	7226
    7263	7338	7212
    7265	7323	7224
    7267	7327	7225
    7269	7341	7225
    7270	7305	7198
    7270	7294	7140
    7268	7256	7103
    7266	7243	7041
    7263	7241	7053
    7260	7240	7029
    7257	7234	7023
    7255	7229	7021
    7254	7245	7008
    7251	7217	7044
    7250	7243	7013
    7248	7237	7033
    7247	7245	7045
    7247	7265	7060
    7246	7255	7066
    7246	7263	7070
    7246	7265	7096
    7246	7272	7075
    7245	7260	7100
    7245	7281	7103
    7246	7287	7113
    7246	7281	7131
    7247	7288	7130
    7248	7282	7159
    7250	7306	7147
    7251	7296	7171
    7253	7319	7173
    7255	7314	7190
    7257	7314	7191
    7260	7324	7204
    7261	7302	7234
    7263	7331	7204
    7265	7323	7222
    7266	7316	7215
    7268	7329	7238
    7269	7305	7243
    7271	7339	7232
    7273	7335	7243
    7276	7348	7232
    7278	7333	7257
    7280	7325	7248
    7281	7325	7229
    7279	7278	7144
    7277	7259	7086
    7275	7244	7065

Similar Threads

  1. New PIC failure rate
    By timmers in forum General
    Replies: 5
    Last Post: - 26th March 2009, 12:11
  2. Rf module baud rate
    By tazntex in forum Serial
    Replies: 4
    Last Post: - 5th August 2008, 18:47
  3. Replies: 6
    Last Post: - 18th January 2008, 08:17
  4. SHIFTOUT Clock rate
    By Brock in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 8th July 2006, 23:42
  5. Detect baud rate
    By Dick M in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 2nd July 2005, 21:10

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts