'How should I handle negative an infinite numbers after applying a Fourier transform?

Having put a signal through a DCT with a hanging window, I look to create decibels for the frequencies.

var timeDomainBuffer: [Float] = .init(repeating: 0.0, count: signal.count)

vDSP.multiply(signal, hanningWindow!, result: &timeDomainBuffer)

var frequencies: [Float] = .init(repeating: 0.0, count: frequencyCount)
dct!.transform(timeDomainBuffer, result: &frequencies)
        
vDSP.absolute(frequencies, result: &amplitudes)
vDSP.convert(amplitude: amplitudes, toDecibels: &decibels, zeroReference: Float(frequencyCount))
vDSP.add(120, decibels, result: &decibels)

I observe several things:

  • occasionally the decibels come through as -inf.
  • sometimes there are negative numbers.

Given I render these and inf and negative don't render well, what processing should I do?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source