LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

slope calculation

I am an MSc student in medical electronics and physics, at the university of London, uk. my project is titled:computer control and analysis in whole body plethysmography. briefly, this involves acquiring 2 signals from a lung volume measurement system, using labVIEW 5.1 and DAQ board PCI-MIO-16XE-50.
These signals are displayed separately on a waveform chart and further combine them on an xy graph throgh an xy chart buffer. i have been able to do all that, in a big WHILE LOOP.

now to be able to go ahead, i need to calculate the LINE resulting from the xy combination. THIS NOT ACTUALLY A LINE, it is a LOOP(ellipse). This has been holding me for days and I have about 2 weeks left, although i have been writing up the thoritical stuff
.

I would be grateful if anyone could help me in that..

Hope to hear from you soon...

Victor..(vopoku@yahoo.co.uk)
0 Kudos
Message 1 of 11
(5,369 Views)
VICTOR wrote in message
news:5065000000080000006D250000-993342863000@exchange.ni.com...

> now to be able to go ahead, i need to calculate the LINE resulting
> from the xy combination. THIS NOT ACTUALLY A LINE, it is a
> LOOP(ellipse). This has been holding me for days and I have about 2
> weeks left, although i have been writing up the thoritical stuff.

There's a linear fit function supplied, if you have the full or professional
development kits. That takes an array of points and gives you the slope and
offset. I've never tried in on this type of data where you have two values
of Y for each value of X; it shouldn't be a problem, but if it is then
there's plenty of (simple) fixes we can go into.
Message 2 of 11
(5,371 Views)
Thank you Craig, but i don't think the linear fit will actually be good for my application. However, as you are in Lancaster and I'm in London i think you could be of help and would want to talk to you on phone if you wouldn't mind.
Could you get me your number? Mine is :02078827747(the lab) or 07759462023(mobile). Just give me a flash and i'll call back.
I attach a copy of the vi of what I've been trying to do as at now so you can advise.
Thank you.
VICTOR....
0 Kudos
Message 3 of 11
(5,371 Views)
VICTOR wrote in message
news:50650000000500000066370000-993342863000@exchange.ni.com...
> Thank you Craig, but i don't think the linear fit will actually be
> good for my application. However, as you are in Lancaster and I'm in
> London i think you could be of help and would want to talk to you on
> phone if you wouldn't mind.
> Could you get me your number? Mine is :02078827747(the lab) or
> 07759462023(mobile). Just give me a flash and i'll call back.
> I attach a copy of the vi of what I've been trying to do as at now so
> you can advise.
> Thank you.
> VICTOR....


Ok. Further to the brief telephone conversation, here's a function that is
essentially a drop-in replacement for the "Linear Fit" VI supplied by NI and
allows you to
wire your XY Graph data directly to it, returning the linear
fit to the data in your graph.

Check the "error" output; if it is non-zero then something has gone wrong.
All documentation is as for the NI version, which underlies this.

Note; I take no responsibility for any harm that may result from the use of
my code in a clinical environment and I've not tested this 🙂




[Attachment Linear Fit from XY Graph.vi, see below]
0 Kudos
Message 4 of 11
(5,371 Views)
Hi Craig,
I have recived the vi and it works on my aplication. Thanks very much for the gesture. I am very grateful. However, I still have a few questions and will need your help. On the issue of liability in clinical use, I want to inform you that this work is still in the simulation process and will go through a lot of testing before clinical use.
Some of my immediate problems are as follows:
1. I need to write my data to a spreadsheet and the to be able to replay it at any time.
2. since i'll use the value of the slope to further calculate lung volume, i'll need only one stable value and not to be varying at my sampling rate. so what i want to do is to take samples a number of times before getting the average slope and go ahead to calculate
lung vol. At the moment, because of the while loop, the slope and lung calculations are continuous until I stop it with the switch.

3. I need to "draw" a straight line to indicate the slope being calculated, for record and argument purposes (maybe using the output of the linear fit vi(slope & intercept)).

I hope I have made myself clear enough....hoping to hear from you soon..
I forgot to get either your phone number or email....

Thank you.
Victor
0 Kudos
Message 6 of 11
(5,371 Views)
VICTOR wrote in message
news:50650000000500000092370000-993342863000@exchange.ni.com...

> questions and will need your help. On the issue of liability in
> clinical use, I want to inform you that this work is still in the
> simulation process and will go through a lot of testing before
> clinical use.

That was a somewhat tongue in cheek comment 🙂

> Some of my immediate problems are as follows:

> 1. I need to write my data to a spreadsheet and the to be able to
> replay it at any time.

It would be quite a big task to take the code you posted and allow data to
be saved and loaded from disk for "offline" use as well as with the DAQ.
It's certainly possible, but I don't have the time to draft it, and given
that you have a very short length of time remaining on your project and you
don't seem incredibly adept at Labview coding, I'd suggest thinking
carefully about whether you can achieve this aim.

I can of course always be contracted but that would be using a sledgehammer
to crack a nut. 🙂

Is it really necessary in any case? Surely all that's important is the slope
of the graph. If the operator can go back and obtain whatever desired
numbers from the same initial dataset by tweaking front panel controls until
it looks right, there's something wrong with the idea of using this for
clinical diagnosis.

If it is really necessary to go ahead with the offline/online approach, I'd
suggest making a new sub-VI to replace the AI Acquire Waveforms.vi. The new
sub-VI should have the same inputs as the AI VI with the addition of a
filepath, an "initialise" boolean and a "mode" input. Inside the new VI is a
case structure controlled by the "mode" parameter. If you're in online mode,
you simply call the AI VI and the program is as it is now. In offline mode,
you have a while loop with a Boolean wired to the conditional such that it
only runs once. You use the "Read from Spreadsheet File" VI to retrieve one
row at a time from the input file, by wiring "1" to the number of rows. You
feed the optional "start of read offset" terminal from either the left
terminal of an uninitialised shift register, if "init" is false, or from a
zero constant if "init" is true, and you feed the "mark after read" to the
right terminal of the shift register. Do the appropriate checks for file not
found, end of file reached etc.

Saving the data initially is quite a bit easier; there's a function "Write
to Spreadsheet File" that takes an array and saves it to a file; if a
boolean input is true then it adds the new data as additional rows without
killing previous data. If you're going to use the approach I outline in the
previous paragraph you need in some way to squash your data into a 1D array
on each cycle, so you save a single row to the file on each pass round the
loop- shouldn't be a problem.

> 2. since i'll use the value of the slope to further calculate lung
> volume, i'll need only one stable value and not to be varying at my
> sampling rate. so what i want to do is to take samples a number of
> times before getting the average slope and go ahead to calculate lung
> vol. At the moment, because of the while loop, the slope and lung
> calculations are continuous until I stop it with the switch.

This is the nature of real data! It'll always vary; the fact it stops when
you press the "stop" button doesn't mean it's stopped varying. If you get
one reading per cycle, then simply have the program stop after a
predetermined number of cycles and take that final value. f you want to be
more "correct" then use the statistical functions to give mean and standard
deviation values for all of the cycles counted to date, updated on a
continuous basis. Or perhaps just of the past n cycles. You then have to
build the uncertainty in your measurement into your calculation of lung
volume to obtain an uncertainty in the lung volume.

> 3. I need to "draw" a straight line to indicate the slope being
> calculated, for record and argument purposes (maybe using the output
> of the linear fit vi(slope & intercept)).

There's a function vi/lib/Analysis/baseanly.llb/1D Linear Evaluation.vi that
will take the slope and offset and an array of X values and give you a
straight line.

However, I think the snippet I gave you has a "best fit" output array; this
holds the "y" values of the straight line corresponding to the "x" values
you feed into the function. Bundle these together and you get a single plot
of your line. At the moment you're feeding a single plot to the XY Graph; if
you look at the online help you'll see that you can also feed an array of
single plots to the terminal, and you get several lines plotted. So just
build an array of your two plots- data and fit- and wire that array to your
XY graph instead of the single data plot.
0 Kudos
Message 7 of 11
(5,371 Views)
Hi Craig,
Thanks for the message. I now have until 27/08/01 to submit the report, so I have decided to use a few intermediate and advanced vis for my application. I just started. you might have a look and advise me.
I'll go ahead and implement your suggestions.
attached is a copy of my new code(" still under developed"), and please comment on it and advise.......hoping to hear from you soon...

Victor
0 Kudos
Message 8 of 11
(5,371 Views)
Hi Craig,
Thanks for the message. I now have until 27/08/01 to submit the report, so I have decided to use a few intermediate and advanced vis for my application. I just started. you might have a look and advise me.
I'll go ahead and implement your suggestions.
attached is a copy of my new code(" still under developed"), and please comment on it and advise.......hoping to hear from you soon...

Victor
0 Kudos
Message 9 of 11
(5,371 Views)
VICTOR wrote in message
news:506500000005000000E6370000-993342863000@exchange.ni.com...
> Hi Craig,
> Thanks for the message. I now have until 27/08/01 to submit the
> report, so I have decided to use a few intermediate and advanced vis
> for my application. I just started. you might have a look and advise
> me.
> I'll go ahead and implement your suggestions.
> attached is a copy of my new code(" still under developed"), and
> please comment on it and advise.......hoping to hear from you soon...

I repeat that I recommend you make a lower level VI to get your data. If you
have one VI to initialise the data stream, one VI to obtain data from the
stream and one VI to close down the datastream at the end, and you handle
all the file I/O wi
thin these sub-VIs, then you'll find things much easier
to handle. You're going to end up in quite a mess the way you're going when
you come to adding the option of reading the data from file, rather than
from the hardware.
0 Kudos
Message 10 of 11
(5,371 Views)
Hello,

I am to acquiring signals from three (3) channels (volume, flow and pressure), but the system from which I'm getting the signal has a certain routine to follow. At the beginning a shutter is opened so we can measure flow (leaving out the pressure) and plot it against the volume on an xy graph to calculate the slope out of that.

After a while we close the shutter, manually, to measure the pressure (leaving out the flow), and plot pressure against the volume on an xy graph to calculate another slope out of that.

This means Volume is constant on the x-axis, while the other 2 channels (pressure and flow) would have to be acquired conditionally. The 2 slopes are used for different calculations.

I have developed a CODE that acquires 2 channels get
s the slope and goes ahead to make the calculations for TGV (which involves pressure against volume).

I believe the other channel will go through the same route, except the formula node, which will be different, because the flow will also be plotted against volume to get a slope.

My problem is how to develop my Code so that it acquires Flow and Volume when the shutter is open, display them on an xy graph and goes ahead with all relevant calculations (without interference from the pressure). And then when the shutter is closed, it switches from the Flow to Pressure measurement, plot it against Volume and goes ahead to do all the calculations with new slope.

What is in this code (VI) is measuring pressure and volume. This should be when the shutter is closed.

I would be grateful if any one could help me in that.

Hope to hear from you soon. Thanks.

Victor.
vopoku@yahoo.co.uk
0 Kudos
Message 11 of 11
(4,978 Views)