Life Science

cancel
Showing results for 
Search instead for 
Did you mean: 

Processing acquired data for a medical application (Epilepsy)

Hello!!
the project :I am a student working on a bio-feedback application which 'know' how to identify pulse seizures on mice brain   slices(epilepsy), and if a seizure have been identified another pulse is sent automatically to depress it!
 
the problem : Basically the application showing good results, but with one major problem:
 When i recognize a seizure i have to immediately react and try to depress it .
 That's mean that if each trace contains(for example) 500 scans , and the 'seizure' have been identified on scan
 number 250 , i need the application to react on scan number 250 and not to wait for the end of the trace.
 Right now the application reacts only after all the specific  trace scans are completed wasting precious time.
 My application first do the 'acquire phase' for all the scans and only afterwards it starts to examine each 
 scan in the trace -  this i know. But how can i avoid it?
 
info about the attachment : in the attachment you can see the main vi(combaineallthree.vi), which is based on an example
called- 'acquire N mutidigital trig.vi' , and includes the acquire part of the application. Inside  a sub vi called   'artifact 4.vi'   where i deal with the identification and reaction to the seizure .
 
additional info : right now i am working with traditional NI-DAQ.
                            Lab View 7.1, PCI 6014
 
 I'll be REALLY happy if someone can help me, it's very important for me.
I'll be happy to try and add more info if needed.
Good daySmiley Happy    
jonathan (student 16)                                   

Message Edited by student 16 on 01-01-2006 07:59 AM

Download All
0 Kudos
Message 1 of 14
(10,268 Views)
Jonathon,

Sounds like an interesting project!

It is somewhat difficult to completely evaluate your VIs because not all of the subVIs are included. Do a Save with Options... Development Distribution... That will save your VI and all the custom subVIs to a .llb (library file), which can then be attached.

I have done something similar to what you are trying to do: Run an acquisition, analyze the data for a particular pattern, and generate a response based on the analysis. The solution is to do things in parallel. Have an acquisiton loop which acquires small "chunks" of data and passes them to the analysis loop. The analysis loop receives the data, analyzes it, and passes the "pattern found" result to the response loop. The response loop waits for the triggering signal from the analysis loop, sends the response and then goes back to waiting.

The most widely used structure to implement something like this seems to be the state machine. Look at examples with LV and in the Forum archives for "State Machine" or "Producer/Consumer". The data is passed between loops via queues or functional globals.

Some comments on your program:

Most experienced LabVIEW programmers avoid the use of global variables and property nodes for the purpose of changing the values of controls or indicators. Direct wiring is faster and more memory efficient. Similarly, the use of sequence structures is largely eliminated by the state machine.

You initialize the serial port in the main VI and again in the artifact4.vi, but only close it in the main VI. If both Read and Write are false when you start the main vi, it is likely that the port will be initialized and then closed without ever writing or reading since that part of the program is not inside a loop.

The artifact4.vi has a for loop which only executes once. It can be removed.

Wiring from left to right is much easier to read and debug.

Bytes at port is usually followed by a case stucture so that if zero bytes are available, no read is attempted. Also, putting the bytes at port and Read inside a loop with the data going into a shift register is a good way to be sure that you get all the data being sent. If you execute the bytes at port in your method before all the data has arrived, some data will be missed. Terminate the loop when the specified number of bytes has been received or when the termination character, if specified, is received.

I prefer to put the error cluster into a shift register, so that if an error occurs on the kth iteration of the loop, it will be detected and handled promptly.

Lynn
Message 2 of 14
(10,243 Views)

Adding to Lynn's excellent comments;

Give us some timing paramaeters. How often is the data coming in and how long do you have to react?

These values can dictate IF and (if true) how this should be done.

Ben

Retired Senior Automation Systems Architect with Data Science Automation LabVIEW Champion Knight of NI and Prepper LinkedIn Profile YouTube Channel
Message 3 of 14
(10,245 Views)

Ben wrote: Adding to Lynn's excellent comments;

Adding to Lynn's and Ben's excellent comments, here are a few more notes on programming flaws. I don't have the VI analyzer, but it will probably find a few more. 😉

  1. Can you explain the purpose of the outer FOR loop in "artifact4.vi"? It runs exactly once and there are no shift registers. You might as well delete it and replace the iteration terminal with a zero diagram constant. (I just noticed that Lynn pointed that out too).
  2. That small while loop on the main diagram (containing only "Write data" and "Proceed") serves little purpose.
    • The loop has no data dependency inputs, thus will execute in parallel with the main loop.
    • If proceed is FALSE at the start of the program, this loop will run immediately, then exit. You might as well delete it. Even if you would change "write data" during program execution, you'll get the stale value at the case structure because the terminal will never get read again once the program starts
    • If proceed is TRUE at the start of the program, this loop will spin as fast as it can, gobbling up all CPU and severly impacting other loops because it will grab attention for 55ms at a time before your main loop gets another slice of the pie.
    • Labeling a while loop termination control as "proceed" but set the loop set to "continue if true" is confusing. If proceed is true, the while loop will continue spinning. Sounds backwards. 😉
  3. Your section dealing with the serial port only runs once immediately after program start, reading the FP buttons in their respective default states. Later (e.g. during the VI run), the buttons are dead, they are never read again. Is that what you want?
Message 4 of 14
(10,204 Views)
Hi again -
Thank you all for your great comments, its really important for me to solve this problem as soon as possible and you helped me a lot.
 
I've learned a lot from the  comments you sent me  and i'll fix them. Some of the problems derives from the fact that the application is still  "under construction'' (ofcourse there is no use for the single iteration..)
 
Right now i have to create a suitable bio-feedback loop  with minimal time delay in order to  initialiaze the lab experiments, later on i'll improve the rest. 
 
regarding my main problem -
I believe, as you suggested, that  the produce/consumer pattern or the state machine is suitable here(parallel is the key word) -
This way i can 'consume' the data recieved  with a reasonable delay( hopefully..) .
 
I am also sending  the full llb - i'll be greatfull if someone can help me synchronize my application with one of this methods.
 
Later i will also send some relevant information regarding the timing issue.
 
again, thanks a lot -
the student(Jonathan):smileyhappy:
 
 
0 Kudos
Message 5 of 14
(10,169 Views)
Hi again -
I have some more information about time parameters.
1) The total trace time ( the time including all the the scans) should be quite long because an epileptic field takes about 100 ms , so the total trace time should be around 500 ms.
 
The time between  the ' epileptic signal '  has been discovered until the response has reached my external hardware should be fastest as possible, i can't say exactly how fast but surley not longer then few ms ( it's crucial to stop the seizure from spreading to other cortex areas), clearly that is my major problem.
 
The time i need to stimulate the cells after the 'pattern found" is very short, about 1*10^-3 to 1*10^-4 sec.
 
2)I have a general question regarding timing parametes i need to calculate for the whole bio-feedback cycle :
 I am trying to calculate the total cycle time : from acquiring the data, thru analyzing it until  the response signal has reached the external hardware , for doing that there i have some open questions :
* How much time it takes the data to reach from my external hardware to the A/D (using a BNC cable)?
* How much time it takes the data to reach the computer from the A/D ?
* Is there any way i can measure the time it took the computer to analyze the data?
 
I hope that the data i supplied here is enough, but if any other info needed please let me know and i will get it.
 
I'll be grateful if someone can help me solving my problem.
 
thanks a lot,
Good morning(from the mails i 've got i believe  it's morning now for you...)
Jonathan
 

Message Edited by student 16 on 01-02-2006 10:30 AM

0 Kudos
Message 6 of 14
(10,153 Views)

Hi-

I aplogize for writing again, but i really need some help here...

If someone(Lynn , Ben, Altenbach, someone else...) can assist me to synchronize my application with the producer-consumer pattern, or a different solution, i'll be greatfull .

I would like to explain a bit why i need to work things out as soon as possible - The thing is that the prof. i am working with found( or to me more accurate- probably found) a way to depress epileptic seizures by using electrical pulses(ofcourse it is much more complicated then that..). To check that assumptiom first thing we have to do is  get some preliminary results (using my application..) in order to see whether we should  proceed further at all, and if we do to design an appropriate expermental procedure, and eventually to check it out with human beings.

Thanks again ,

Jonathan (student 16)

p.s - I've attached the llb to one of my messages.

0 Kudos
Message 7 of 14
(10,003 Views)

Hi-

I aplogize for writing again, but i really need some help ...

If you can assist me to synchronize my application with the producer-consumer pattern, or a different solution, i'll be greatfull .

I would like to explain a bit why i need to work things out as soon as possible - The thing is that the prof. i am working with found( or to me more accurate- probably found) a way to depress epileptic seizures by using electrical pulses(ofcourse it is much more complicated then that..). To check that assumptiom first thing we have to do is  get some preliminary results (using my application..) in order to see whether we should  proceed further at all, and if we do to design an appropriate expermental procedure, and eventually to check it out with human beings.

I've learned a lot from the  comments you sent me  and i'll fix them. Some of the problems derives from the fact that the application is still  "under construction'' (ofcourse there is no use for the single iteration..)
 
Right now i have to create a suitable bio-feedback loop  with minimal time delay in order to  initialiaze the lab experiments, later on i'll improve the rest. 
I have some more information regarding time parameters.
1) The total trace time ( the time including all the the scans) should be quite long because an epileptic field takes about 100 ms , so the total trace time should be around 500 ms.
 
The time between  the ' epileptic signal '  has been discovered until the response has reached my external hardware should be fastest as possible, i can't say exactly how fast but surley not longer then few ms ( it's crucial to stop the seizure from spreading to other cortex areas), clearly that is my major problem.
 
The time i need to stimulate the cells after the 'pattern found" is very short, about 1*10^-3 to 1*10^-4 sec.
 
2)I have a general question regarding timing parametes i need to calculate for the whole bio-feedback cycle :
 I am trying to calculate the total cycle time : from acquiring the data, thru analyzing it until  the response signal has reached the external hardware , for doing that there i have some open questions :
* How much time it takes the data to reach from my external hardware to the A/D (using a BNC cable)?
* How much time it takes the data to reach the computer from the A/D ?
* Is there any way i can measure the time it took the computer to analyze the data?
 
I hope that the data i supplied here is enough, but if any other info needed please let me know and i will get it.
Please let me know you've recieved my post.
 
thanks a lot,
Good day-Jonathan
I am also sending  the full llb - i'll be greatfull if you can help me synchronize my application with one of this methods.

 

0 Kudos
Message 8 of 14
(10,044 Views)
Hello Jonathan,

In a non-realtime system there is no way to guarantee the response time from when the data is acquired to when it is done being analyzed and when it will be output.  However, the parallel architecure Lynn mentioned sounds like a great idea for your application.  You can find more about how to implement a consumer/producer architecture in this article.

I would recommend that in your consumer loop you read all available samples from the DAQ board OR do a hardware-timed single-point acquisition.  This is important because it will give you the most recent sample acquired for every iteration of the loop.
Eric
DE For Life!
Message 9 of 14
(10,026 Views)
 
0 Kudos
Message 10 of 14
(10,000 Views)