[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y ] [Home]
4chanarchives logo
Arduino Peak Detection
Images are sometimes not shown due to bandwidth/network limitations. Refreshing the page usually helps.

You are currently reading a thread in /diy/ - Do It yourself

Thread replies: 12
Thread images: 1
Hey /diy/, I want to write a simple code for arduino which will detect local peaks and troughs. I am working on simple blood pressure circuit to enhance my electronics skills.

What I have right now is a pulse similar to the one in pic, with around 120mV and 80mV for the systolic and diastolic peaks. I would like to sample a pulse or two using the analog input pins, and return the peak values so I can print them onto an LCD.

I have tried simply googling it to no avail, and while I am interested in programming, my knowledge is somewhat limited. If anyone could recommend even a procedure I might use to solve this, let me know.
>>
in the simplest terms - you observe the sample and compare it to the previous one, you will also need a variable signalling the current state.

so, you asume that the value is going up, and keep substracting last value from the current one until the result is negative (which means current sample was lower than the last one).

this is the simplest method and will likely not work very well - it would be worth doing some sort of low-pass filtering on the signal because it is very lkely that noise wil locally make the signal go the other way, if you filter most of it will go away.
even something like moving window averagig is very efficient in filtering
>>
>code for arduino
this is what's wrong with the arduino ecosystem in a nutshell. once you've got the data, the algorithms will be the same regardless of the platform. do consider that when looking for tips.
that said, i vouch for this >>961210
rolling average, then check for step difference
>>
>>961210
Ok, thank you! I will try the simpler method first, and do some reading on how I might impliment an averaging filter.
>>
>>961225
are the samples integer or floating point?
>>
Sounds like this thread has the right idea. If you don't want to do the filtering then you may just consider comparing your sampled value with the last 5 or 6 sampled values. If it is lower than all of them, go back and find the max value from your last 6 values and call that the peak. This will help get rid of some of the noise, but not all. Basically, it's an intermediate step between analyzing raw data and doing proper filtering.
>>
>>961230
Doesn't matter to me, it doesn't have to be too precise. The input signal is only going to have around a 40 mV range, so I'm not sure which data type would be more appropriate.

>>961234
I like this idea lol, quicker and dirtier is definitely my style :p
>>
>>961275
>it doesn't have to be too precise
Don't worry, AVR's ADC + 40mV signal isn't going to be too precise.
On a more serious note, you should consider amplifying the signal a bit before feeding it to Arduino. And the data will come out as unsigned integers from the ADC.
>>
>>961288
Lol, I figured as much.

I thought I may also have to boost the signal. I'll probably just use a high quality OP amp with a gain of 100
>>
>>961288
Also, I did math it out. The arduino will accept 0-5V DC and the ADC has a range of 0-1024 steps.

If I use an amp with a gain of 10 (sorry last post said 100). Then I'll have a range of 0.8 to 1.2V and using analogRead it should return values from 164 to 246 (based on an ideal 120/80mmHg blood pressure signal.... not that mine is that good lol)
>>
>>961199
You should not be using an arduino for calculations since it's a microcontroller, not a microprocessor.

You should be using the arduino solely to collect data and send it to an actual computer like a Raspberry Pi minimum or else the arduino may slow down since calculations take time. This is not even considering the very limited storage space in an arduino by default.
>>
>>961474
Fair enough, I've just written some code and it compiles / uploads to the arduino fine.

I ended up with a simple design using a couple of arrays. According to the compiler I'm only using about 6% of memory storage. Currently, it only ever needs to hold a total of 10 sampled values at any given time.

Hopefully it works, I'l be testing it out using a function generator tomorrow. If it can somewhat reliably tell me the local peaks and troughs of the signal, I'll be happy.
Thread replies: 12
Thread images: 1

banner
banner
[Boards: 3 / a / aco / adv / an / asp / b / biz / c / cgl / ck / cm / co / d / diy / e / fa / fit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mu / n / news / o / out / p / po / pol / qa / r / r9k / s / s4s / sci / soc / sp / t / tg / toy / trash / trv / tv / u / v / vg / vp / vr / w / wg / wsg / wsr / x / y] [Home]

All trademarks and copyrights on this page are owned by their respective parties. Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
If a post contains personal/copyrighted/illegal content you can contact me at [email protected] with that post and thread number and it will be removed as soon as possible.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com, send takedown notices to them.
This is a 4chan archive - all of the content originated from them. If you need IP information for a Poster - you need to contact them. This website shows only archived content.