0
$\begingroup$

Set

f[c_?NumericQ] := Module[{data},
  data = AudioData[AudioNormalize[Import["myfile.wav"]]];
  Mean[Take[data, {c, c + 400}]]]

and then apply

NMinimize[{f[x], x \[Element] Integers && x > 0 && x < 2}, x]

to find the audio segment with the minimum mean. The answer is obviously 1 but Mathematica goes away and doesn't come back. What candidate solutions are being considered?

$\endgroup$
  • 1
    $\begingroup$ Instead of using NMinimize[], just use MovingAverage[] on your data and take the position of the smallest member of the resulting list. $\endgroup$ – J. M. will be back soon Nov 8 '17 at 0:29
  • $\begingroup$ This is a misuse of NMinimize. It is meant for smooth mathematical functions, which this is not. It also calls f many times. Since f uses Import on each call, it is entirely expected that this would be unusably slow. If you have a list of values, it is almost always best to process them as such (and not try to treat them as a function). $\endgroup$ – Szabolcs Nov 8 '17 at 8:49
  • $\begingroup$ You can use AudioLocalMeasurements and AudioIntervals to find your interesting thing $\endgroup$ – partida Nov 9 '17 at 10:36
  • $\begingroup$ The function is continuous and has derivatives of all orders on its domain of definition. It couldn't be smoother. Furthermore, I don't see why f should be called more than once given the constraint. What values other than 1 is f being called with for all these many invocations? $\endgroup$ – user90346 Nov 10 '17 at 12:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.