Some Python for swept-sine analysis

Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.
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_sweep.png

(loopback through Focusrite Scarlett Solo 3)
or

ceramic_cap_sweep.png

(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

  • sweep_analysis.zip
    5.5 KB · Views: 260
Last edited:
Status
This old topic is closed. If you want to reopen this topic, contact a moderator using the "Report Post" button.