Python Forum

Full Version: Real-time processing
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I've just started programming with Python.
I have to write a code trough which I have to process two different signals: ECG and respiration. I need to process them real-time but I have no idea how to do that. The code should analyze respiratory's signal first, find the expiration phase and then analyze ECG and find R-peak. Any suggestion? Thank you
Quote:I have to write a code ... but I have no idea how to do that
was this not covered in your course?
what you are talking about can be easy if the interfaces to the devices are simple data reads, or quite difficult if you need to issue commands to control the instrumentation.
You do not provide enough details here to know.
Device models, how the data is obtained, etc.
Let me explain: at first I do not have possibility to acquire signals (but the code should work online) so I have to use pre-recorded signals. The question is: how can I simulate a real-time recording basing on these pre-recorded data? How can I treat these data on Python as if they were acquired x samples by second?
Usually recorded data have time stamps.

Which information do you have? Is there a sleep time between measurements of recorded data?
If yes, is this always the same. If yes, then you have your time delta.
If not, then it's a guessing game.

Without any sample of your data, for us it's also a guessing game too.
please show your code.
My signal is a breath's signal (cycles of a sort of sinusoid) sampled at 100Hz. I've got a signal 22296 samples long. My task is to evaluate it as if it was real-time as a continuous stream of data sensed by a sensor but in this case I've got it already recorded, how can I simulate a real-time acquisition starting from this pre-recorded signal?. I thougth about using a while True cycle to get 1 sample at time and getting data I already have from a csv file (this file in each row the value measured by the sensor according to the sample frequency chosen). Does it make sense?
The objective is then set a treshold, calculated as the mean value of the signal above a window of 20s, and then use this value to make a choice: if sample>treshold -> inspiration phase, if sample<treshold ->expiration phase. If the last condition is met I have to find a way to detect the end of expiration phase which corresponds to the minimum of the curve. In order to find it I need to make a comparison between one sample and the successive sample (using diff), but I also need to take into account unavoided artifacts that can induce me to consider one sample as the minimum because the difference is negative while next one difference is positive. The treshold needs to be refreshed too after a set time.