Program for calculating total harmonic distortion (THD)


   Once again, I hesitated whether to make this program available for download, because (even though I did all I could) it's probably not perfect, but in finally, I decided to make it available.

   This time, program is not in form of executable file, but it is readable source text, intended for GNU Octave environment. I chose Octave environment because it is significantly faster for calculating harmonic distortion (Fourier transform FFT) than Visual Basic in MS Visual Studio, in which I also tried to program FFT, and unlike VB, it has a lot of functions already built in (including FFT), and drawing graphic curves is also much better solved and produces better-looking graphs. Disadvantage is that there is no simple way (at least I don't know how) to create an executable file, so potential users will have to install Octave on their computers (if they don't already have it installed) in order to run this program. On the other hand, it can be advantageous to have a readable source text, i.e. for those who would like to work with it further (or correct what they don't like or what doesn't work in my approach).

   Program allows calculation of total harmonic distortion (THD) from measurements of alternating periodic signals from digital oscilloscopes, stored in csv or txt files. So far, it can process data from HANTEK DSO 4102 C oscilloscope (and others with the same data) and from OWON ADS802A oscilloscope (and again others with the same data). – I assume that a program could process data from entire ADS 800/900 series, but I have no way of testing this. 

   For my part, I declare that I have not built any bugs or sniffers into it; I cannot do more than that. Furthermore, anyone can check what program does by reading its code.

   Following is an example of output from program for measuring harmonic distortion of (slightly) powerful low frequency amplifier with signal from generator (how else), I would like to point out that this is total harmonic distortion of system consisting of generator + amplifier + oscilloscope. To determine THD of amplifier alone, it is necessary to measure distortion of system consisting only of generator + oscilloscope in the same way and subtract it from the previous distortion.


Example_of_THD_calculation_from_LF_amplifier_measurement.jpg

   More details about program operation, control, input file format, GNU Octave installation (including a link to download it), and other examples can be found in the file " Description of THD calculation program.pdf" (it is divided into two files due to Mozello's 5 MB limit per file in "free" version).

Program description can be downloaded here:  Description of THD calculation program pp 1 - 14.pdf
                                                                                                Description of THD calculation program pp 15 - 22.pdf

Program in format that can be run in Octave can be downloaded here: Calculation_DFT.m

And program in pdf format (backup and safeguard against changes) can be downloaded here: Calculation_DFT.pdf

   As an example for testing this program, here is file from OWON ADS802A oscilloscope. It is direct measurement of 1 kHz signal from OWON DGE1030 generator, total approx. 19 cycles, acquire depth was 100k, i.e. 100 000 data points.
File can be downloaded here: OSCgen_1000_Hz_20260131132727.csv