# Minimization Over a Set of Size 1

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?

• Instead of using NMinimize[], just use MovingAverage[] on your data and take the position of the smallest member of the resulting list. – J. M. will be back soon Nov 8 '17 at 0:29
• 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). – Szabolcs Nov 8 '17 at 8:49
• You can use AudioLocalMeasurements and AudioIntervals to find your interesting thing – partida Nov 9 '17 at 10:36
• 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? – user90346 Nov 10 '17 at 12:12