I ended up exporting the data out to CSV to inspect it and it seems there were zeros in there.
using DelimitedFiles
writedlm( "FileName.csv", data, ',')
I had forgotten that when I originally exported the data using Audacity they were [inf] data points, which I had corrected manually. That’s why it was working up to the squaring step, but not the log step, because obviously log10(0) is undefined.
So the solution is:
dataRead, fs = wavread("FileName.wav")
data = dataRead[:]
dataLength = length(data)
for i in 1:dataLength
if data[i] != 0
data[i] = 10*(log10(data[i]^2)) #converts to dB
#dataTop[i] = 20*log10(abs(data[i])) #alternative way to convert to dB, see upthread
else data[i] = 0 #zeros are okay in the dB data for me
end
end
That should work as expected now.