How do I write a frequency function?

Version: 4.1.3.2, English, Calc
Ubuntu 13.10, English
Hello,
I am working on some science fair stuff and I have respiration data that was taken by a relative pressure sensor that was connected to a bladder that was strapped around the test subjects’ stomachs. As they inhaled, they created pressure against the bladder raising the pressure readout and vice versa, which created a somewhat harmonic wave (I’ve attached a graphic). I need to write a function that will calculate the average frequency of troughs or breaths. Something that could perhaps take the frequency of two or so troughs in front and behind the one in question and average them to give a breath frequency. Does anyone know how to write such a thing?

Someone on another forum said this:
“I would approach this by creating a new pair of data columns that indicate each peak and trough point using basic less-than / greater-than comparisons of a prior value (or perhaps 3 prior readings for noise smoothing purposes). It should then be possible to determine each period and display these in another column. These periods can then be averaged as required in the moving 5-period manner indicated (again in a new column) and graphed as required.”

I didn’t understand that. I’ve attached a file of some sample data. Data Sample.ods Feel free to edit, alter and otherwise play with it if it helps. It will certainly help me if you can return a file that has an example of what you’re saying.

Thanks!

I guess, it would be doable with FFT (Fast Fourier Transform). But unfortunately LibreOffice has no build in solution for it.

Here another, somehow primitive solution:

You can observe the time points, when the curve increases. Then you build the difference of this time points to get the time from one up to the next up and last you make a average over this durations. In detail:

To get a time point for curve increases, you calculate moving average. You need to experiment with the span, for example 200 values, e.g. in D3 =AVERAGE(B3:B202), copy down. Next calculate the difference between average and value, e.g. in E3 =B3-D3, copy down. Now look, whether there is a switch from - to + ,e.g. in F3 =AND(E3<0;E4>0).

Now filter the data with criteria column F = true. Put the filter result into a different sheet, e.g. Sheet2.A3.

On this Sheet2 you do the next calculations. Build the difference of adjacent time points, e.g. in G4 =A4-A3. Copy down, but not too far. The last moving averages are not valid, because they span ranges with no data. This differences in column G tell you, how long it needs from one breath to the next.

Calculate the average of this differences.

Ask 2014-03-06 Frequency 13941180328547709 suggestion.ods

If you will show the whole data in the chart, you need to be patient, because it lasts some time to generate the points in the chart. LibreOffice does not hang, but it is very slow.