Pulse analysis with a PIC

Started by Jason Hsu July 27, 2009
Page 2 of the following document shows two pulses that I need a PIC to analyze:
http://www.phoenix.tc-ieee.org/0001_Bibliography/2007-05-24%20EMB%20Presentation/2-Carl-Sensors_20070520_Phoenix%20Sensor2.ppt

Basically, there are two pulses from two sensors. The systolic blood pressure we're measuring is a function of the time difference between the peaks of the two pulses. The diastolic blood pressure we're measuring is a function of the time difference between the troughs of the two pulses.

I have never before used a PIC to analyze a pulse. I'm trying to think of the best way to do this. If you forced me to try something right now, here is how I would do it:
1. Use the A/D converters to obtain voltage measurements, one from pulse 1 and one from pulse 2.
2. Save these voltage measurements in variables.
3. Repeat steps 1-2 many times until data has been collected for at least a full cycle.
4. Go through the set of pulse 1 measurements and pulse 2 measurements. Use a counter to keep track.
5. Identify the variables representing the peaks and troughs.
6. Compare the timing of the peaks and troughs in the two pulses.
7. Use the timing data obtained in the previous step to calculate the blood pressure numbers.

What do you think? Is this a good way, or is there a much better way?

Are there examples of PIC programs that analyze pulses that I can look at? It would help me tremendously to look at examples of pulse analysis programs.

--
Jason Hsu
http://www.jasonhsu.com/swrwatt.html
http://www.jasonhsu.com/swrwatt-c.txt
http://www.jasonhsu.com/swrwatt-asm.txt

Hi Jason.

I am not an expert in PIC's, but have identified some issues below
that occured to me.

2009/7/27 Jason Hsu :
> Page 2 of the following document shows two pulses that I need a PIC to
> analyze:
> http://www.phoenix.tc-ieee.org/0001_Bibliography/2007-05-24%20EMB%20Presentation/2-Carl-Sensors_20070520_Phoenix%20Sensor2.ppt
>
> Basically, there are two pulses from two sensors. The systolic blood
> pressure we're measuring is a function of the time difference between the
> peaks of the two pulses. The diastolic blood pressure we're measuring is a
> function of the time difference between the troughs of the two pulses.
>
> I have never before used a PIC to analyze a pulse. I'm trying to think of
> the best way to do this. If you forced me to try something right now, here
> is how I would do it:
> 1. Use the A/D converters to obtain voltage measurements, one from pulse 1
> and one from pulse 2.

Be careful how you set this up. Remember that the trigger time of
each of the ADC's will affect your measurement.
i.e. if you trigger ADC1 first then ADC2, the first will be 1
instruction cycle earlier that the second. I stand corrected, as you
may be able to trigger the sample and hold simultaneously.

> 2. Save these voltage measurements in variables.

Check how long it takes to write the voltage measurement to memory &
the precision with which you want to do this. Depending on your
sample rate, you may be limited in how much you can write to memory &
how quickly you have to write. This also affects which memory in the
PIC you can use.

> 3. Repeat steps 1-2 many times until data has been collected for at least a
> full cycle.
> 4. Go through the set of pulse 1 measurements and pulse 2 measurements. Use
> a counter to keep track.
> 5. Identify the variables representing the peaks and troughs.

I am interested to see what method you use for this. I would assume
you need to check for noise on the signal and perform some sort of
filtering to avoid detecting false troughs / peaks.

> 6. Compare the timing of the peaks and troughs in the two pulses.

> 7. Use the timing data obtained in the previous step to calculate the blood
> pressure numbers.
>
> What do you think? Is this a good way, or is there a much better way?
>
> Are there examples of PIC programs that analyze pulses that I can look at?
> It would help me tremendously to look at examples of pulse analysis
> programs.

You may want to look at examples of digital osciliscopes. They
generally do some sort of waveform analysis to capture and hold a
repetitve waveform.

>
> --
> Jason Hsu
> http://www.jasonhsu.com/swrwatt.html
> http://www.jasonhsu.com/swrwatt-c.txt
> http://www.jasonhsu.com/swrwatt-asm.txt

Regards,

William
Jason

To solve this problem, is it possible to use the principle used by HP3575A
Phasemeter ( http://www.hpl.hp.com/hpjournal/pdfs/IssuePDFs/1972-05.pdf ) so
that time between two pulses is measured as phase using an external; "noise
immune" phasemeter hardware ?

Of course one of the channels of the phasemeter input amplifier could be
used to measure the period using PIC 16F688's "external timer gate". Then
one can use a moving average algorithm to filter the period and convert to
frequency. Please see
http://www.codeproject.com/KB/recipes/SimpleMovingAverage.aspx beside many
others..

What do you think ?

Regards

M

----- Original Message -----
From: William Gebers
To: p...
Sent: Monday, July 27, 2009 4:19 AM
Subject: Re: [piclist] Pulse analysis with a PIC
Hi Jason.

I am not an expert in PIC's, but have identified some issues below
that occured to me.

2009/7/27 Jason Hsu :
> Page 2 of the following document shows two pulses that I need a PIC to
> analyze:
>
http://www.phoenix.tc-ieee.org/0001_Bibliography/2007-05-24%20EMB%20Presentation/2-Carl-Sensors_20070520_Phoenix%20Sensor2.ppt
>
> Basically, there are two pulses from two sensors. The systolic blood
> pressure we're measuring is a function of the time difference between the
> peaks of the two pulses. The diastolic blood pressure we're measuring is a
> function of the time difference between the troughs of the two pulses.
>
> I have never before used a PIC to analyze a pulse. I'm trying to think of
> the best way to do this. If you forced me to try something right now, here
> is how I would do it:
> 1. Use the A/D converters to obtain voltage measurements, one from pulse 1
> and one from pulse 2.

Be careful how you set this up. Remember that the trigger time of
each of the ADC's will affect your measurement.
i.e. if you trigger ADC1 first then ADC2, the first will be 1
instruction cycle earlier that the second. I stand corrected, as you
may be able to trigger the sample and hold simultaneously.

> 2. Save these voltage measurements in variables.

Check how long it takes to write the voltage measurement to memory &
the precision with which you want to do this. Depending on your
sample rate, you may be limited in how much you can write to memory &
how quickly you have to write. This also affects which memory in the
PIC you can use.

> 3. Repeat steps 1-2 many times until data has been collected for at least
a
> full cycle.
> 4. Go through the set of pulse 1 measurements and pulse 2 measurements.
Use
> a counter to keep track.
> 5. Identify the variables representing the peaks and troughs.

I am interested to see what method you use for this. I would assume
you need to check for noise on the signal and perform some sort of
filtering to avoid detecting false troughs / peaks.

> 6. Compare the timing of the peaks and troughs in the two pulses.

> 7. Use the timing data obtained in the previous step to calculate the
blood
> pressure numbers.
>
> What do you think? Is this a good way, or is there a much better way?
>
> Are there examples of PIC programs that analyze pulses that I can look at?
> It would help me tremendously to look at examples of pulse analysis
> programs.

You may want to look at examples of digital osciliscopes. They
generally do some sort of waveform analysis to capture and hold a
repetitve waveform.

>
> --
> Jason Hsu
> http://www.jasonhsu.com/swrwatt.html
> http://www.jasonhsu.com/swrwatt-c.txt
> http://www.jasonhsu.com/swrwatt-asm.txt

Regards,

William
To sample the waveform, you need to determine that highest frequency in the signal. The Nyquist-Shannon sampling theorem deals with that:

http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem

So, first you need to know what the highest frequency is! One way to do this is to perform a fast Fourier transform of samples of the signal. These samples need to be taken at a much higher rate - but only once for testing. http://en.wikipedia.org/wiki/Nyquist%E2%80%93Shannon_sampling_theorem

Once you know the sample rate required of the A/D converters you can then figure out how to program the PIC.

The problem I have is that I don't know what kind of time delays are involved.

Anyway, after you capture both waveforms to arrays then you just wander through the data looking for max and min values and their associated timestamps (may be implicit from the sample number).

Actually, you can keep track simultaneously of the max and min sample timestamps and you don't even need to store the data.

At some point you will be able to figure out whether the PIC is a good choice.

Richard
If these are just digital pulses and you are trying to measure the time between two events, feed the pulses into two "capture" inputs. Set each capture to cause an interrupt. Using the interrupt service routine for each capture interrupt, record the "time" between interrupts. For example, when one of the pulses occurs, reset the timer to 0. Then when the other pulse occurs, read the value of the timer (actually you can set the capture to "capture" value of the timer when the pulse comes in). Probably the timer will overflow multiple times during this period, so you will have to count overflows in an interrupt service routine. Each overflow will represent a certain amount of time, plus the current timer value.
BasicPoke
--- In p..., "Jason Hsu" wrote:
>
> Page 2 of the following document shows two pulses that I need a PIC to analyze:
> http://www.phoenix.tc-ieee.org/0001_Bibliography/2007-05-24%20EMB%20Presentation/2-Carl-Sensors_20070520_Phoenix%20Sensor2.ppt
>
> Basically, there are two pulses from two sensors. The systolic blood pressure we're measuring is a function of the time difference between the peaks of the two pulses. The diastolic blood pressure we're measuring is a function of the time difference between the troughs of the two pulses.
>
> I have never before used a PIC to analyze a pulse. I'm trying to think of the best way to do this. If you forced me to try something right now, here is how I would do it:
> 1. Use the A/D converters to obtain voltage measurements, one from pulse 1 and one from pulse 2.
> 2. Save these voltage measurements in variables.
> 3. Repeat steps 1-2 many times until data has been collected for at least a full cycle.
> 4. Go through the set of pulse 1 measurements and pulse 2 measurements. Use a counter to keep track.
> 5. Identify the variables representing the peaks and troughs.
> 6. Compare the timing of the peaks and troughs in the two pulses.
> 7. Use the timing data obtained in the previous step to calculate the blood pressure numbers.
>
> What do you think? Is this a good way, or is there a much better way?
>
> Are there examples of PIC programs that analyze pulses that I can look at? It would help me tremendously to look at examples of pulse analysis programs.
>
> --
> Jason Hsu
> http://www.jasonhsu.com/swrwatt.html
> http://www.jasonhsu.com/swrwatt-c.txt
> http://www.jasonhsu.com/swrwatt-asm.txt
>