2
$\begingroup$

This is for a research project on meditation. A music-type person composed for me an audio for paced breathing, which consists of some undulating tones. I would like to convert it to a smooth function for data analysis, where I will compare the function to some laboratory measurements, like heart rate. Here is a link to the audio file: Here is my code.

audio = Audio[File["BPM 8.wav"]];
selectData = MovingAverage[selectData, 20020]; 
ListLinePlot[selectData, PlotRange -> All, AspectRatio -> 1/10]

Here is the result

If I increase the moving average window, it loses its features. If I decrease the window, the result obviously gets noisier. I can't seem to a get a smooth function that has the features of this very regular tone.

$\endgroup$
2
  • 1
    $\begingroup$ hmm...what features do you want to extract? volume? pitch? If you take an average of a sound wave, you'll have a lot of cancellation in each of the pitch components (imagine the average of a sine wave over a long time). If you want to represent the volume, maybe take the root mean square over a certain window, or the maximum value over a certain window? But first you've got to decide on the abstract features you want before implementing them! :) $\endgroup$
    – thorimur
    Commented Dec 2, 2022 at 2:56
  • $\begingroup$ I don't really care what feature I extract. I just want to correlate the audio with some laboratory measurements (HRV, if you've heard of that) in meditators. But anyway, after I posted the above question, I realized that I really need to take the absolute value of the data file. Your idea of the root mean squared is probably even better. So thanks for that! $\endgroup$
    – Chris
    Commented Dec 2, 2022 at 22:34

1 Answer 1

1
$\begingroup$

I'd suggest looking at the Audio* functionality for maximum efficiency. I'd do something like:

a = Audio["/Users/carlogico/Downloads/BPM 8.wav"];

AudioPlot[a]
Spectrogram[a]

AudioLocalMeasurements[a, "RMSAmplitude", 
  PartitionGranularity -> {Quantity[0.2, "Seconds"], 
    Quantity[0.1, "Seconds"]}] // ListLinePlot

Some pages to look at:

$\endgroup$
1
  • $\begingroup$ This looks like the answer I'm looking for. I will try to implement your suggestion in coming days, and if it works I'll remember to attribute the answer to you. thanks. $\endgroup$
    – Chris
    Commented Dec 7, 2022 at 16:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.