Normalizing the magnitude of Goertzel Filter c#
Your Goertzel code looks okay, the standard fare.

Regarding normalization and thresholds, if you're detecting 18kHz, you should calibrate your signal at different levels and establish a threshold from that data


Start with full-scale (1.0, 0dBFS) 18kHz tones, as those should give you the highest magnitude over the course of your buffer (4500 samples) and then
Repeat the Goertzel filter mag measurements on tones all the way down in level, as much as you care but I would measure at least 6dB.
Finally, run your Goertzel filter over non-tonal material, or buffers of audio that don't contain what you're looking for. This will give you an idea of what the filter will output in the non-tone case. In my application, environmental audio/speech can have incidental tones in the range I'm looking for (400-600Hz) and I want to make sure to understand what Goertzel magnitudes I would get versus Goertzel magnitudes in the presence of a real tone.