Over the holiday I looked at the logarithmic swept-sine/chirp technique for measuring distortion v. frequency and rattled up some Python3 code using scipy/matplotlib to play with this.
Recently I've tidied up this into two programs, one to generate a log chirp and one to analyze a log chirp. There's a Python library PySoundFile that makes reading/writing .wav files easy (and other filetypes I've haven't tried yet).
This allows offline analysis of captured responses. You just have to match the parameters between generation and analysis, namely Fs, sweep duration and min/max frequencies. Defaults are 96000, 10Hz, 24kHz and 20 seconds.
Then you can get a plot like:
(loopback through Focusrite Scarlett Solo 3)
or
(non-linear divider using 10k resistor and 10nF X7R ceramic cap)
I plot the fundamental as a frequency response with the 1kHz level as 0dB, and the harmonics as relative to the fundamental response, ie as distortion values. The black trace is the summed distortion of the harmonics.
The analysis is crude and assumes the frequency response is flat (or more precisely it identifies the chirp start based on the amplitude compared to max amplitude) Future work in making the chirp identification more smart and robust is possible.
Its in Python3 and requires numpy, scipy, matplotlib and PySoundFile
Recently I've tidied up this into two programs, one to generate a log chirp and one to analyze a log chirp. There's a Python library PySoundFile that makes reading/writing .wav files easy (and other filetypes I've haven't tried yet).
This allows offline analysis of captured responses. You just have to match the parameters between generation and analysis, namely Fs, sweep duration and min/max frequencies. Defaults are 96000, 10Hz, 24kHz and 20 seconds.
Then you can get a plot like:

(loopback through Focusrite Scarlett Solo 3)
or

(non-linear divider using 10k resistor and 10nF X7R ceramic cap)
I plot the fundamental as a frequency response with the 1kHz level as 0dB, and the harmonics as relative to the fundamental response, ie as distortion values. The black trace is the summed distortion of the harmonics.
The analysis is crude and assumes the frequency response is flat (or more precisely it identifies the chirp start based on the amplitude compared to max amplitude) Future work in making the chirp identification more smart and robust is possible.
Its in Python3 and requires numpy, scipy, matplotlib and PySoundFile
Attachments
Last edited:
Thanks a lot for sharing this. I'm trying to learn Python3 and not at a level yet to be able to write similar, but this will be very useful for studying how to do it. There are not too many audio DIY related sample code snippets out there.
You might find this helpful: Understanding Audio data, Fourier Transform, FFT and Spectrogram features for a Speech Recognition System