Peak Area in 2022

Recommended Posts

Every now and then I return to this question. Is there a way to calculate the height and area of peaks once you have acquired sensor data. For a long time I have shared DAQ factory, and have gotten people to buy it, but the issue has always been, how do I post process the data that I have collected. My data is sensor versus time. I have peaks generated by chromatography or flow analysis. I love being able to control every instrument that comes along, but I hate having to purchase another solution to process my data. It also makes it tough to generate a universal solution that would enable me to share with my friends. It is tough to believe that we are this far  along without this capacity being available. (please correct me if my information is dates!)

Link to comment
Share on other sites

It is a little of a "do you want one tool that does everything not very well, or several tools that do their particular thing quite well?"  DAQFactory can actually do a fair bit of post processing, especially if you don't mind using script.  In fact, in script you can do just about anything, including things that simple data analysis tools might not be able to do (Excel especially, if you want to call it a data analysis tool).  But, we chose awhile ago not to try and recreate the wheel on the analysis side and make DAQFactory both a data acquisition tool AND a data analysis tool.  MatLab and Igor I know tried to do this, adding data acquisition features to their rather powerful data analysis tools and in my opinion it works marginally, mostly because they are experts in analyzing data, not hardware and acquiring it.

OK, now to the question at hand.  First, you can use the peak markers of a graph and it will give you a center of mass peak find along with an area between the markers with a linear baseline stretching between them.  This is pretty basic but quick.  

Getting more advanced, the trick really is figuring out where the peaks are, and where the bases of said peaks are. DAQFactory doesn't have a built in peak finding algorithm so you'd have to script your own.  How hard this is really depends on how noisy your signal is.  Most true analysis tools will do a curve fit, then find the peak of the curve.  DAQFactory doesn't have a built in curve fit, so you'd either need to roll your own in script, or use smooth() to iron out the noise.

Once you have the peak location and base points, it is really easy to calculate height and area.  Area is just sum(), while peak height is just the Y value for the peak.  I'm assuming no baseline, but if you can do a baseline as well, either by simply subtracting out a baseline measurement, or calculating one based on the peak base points (which is what the peak markers do).  

Now with area, the trick is to incorporate X into it.  If your measurements are spaced evenly in X, then the expression is simply sum(y) * dx where dx is the total difference in x between start and stop of the peak.  If not, then it becomes more like: sum(y*dx) where dx is the difference between consecutive Y points.  If X is time, you can calculate dx from the time part of the channel.

So, let's say you have a channel called "Chromo" and you figure out that the start time of the peak is at a variable you called "st", while the end time is at "et".  You can subset "Chromo" to just get the data from the peak by doing:

private peakData = Chromo[st,et]

Here we are subsetting by time, meaning DAQFactory is getting all the data in Chromo with a timestamp between st and et.  You can also, of course, subset by data point number, which is what we do when we do [0].

Now that we have the peakData, the area assuming the measurements are NOT equally spaced in time is:

sum(peakData * (peakData.time[1,100000] - peakData.time[0,100000]))

Note that 100000 is just some arbitrarily big number so that I get all the time data.  Note how the first one is [1, ...], while the second is [0,....].  That whole part in parenthesis is basically creating an array of deltaT's which we then multiply by each data point in peakData, then finally sum it.

I can go on and on.  As I said, you can do A LOT of data analysis in DAQFactory using scripting, it just requires some knowhow on data analysis and some scripting.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.