I am using my own software and a PicoScope 2204A to calculate THD.
I am very close to getting it right, but I am missing something. Please bare with me as this is my first time working with transforms and THD, so I am a little confused by the whole thing.
I am currently applying a 1khz signal. 0.707V PK (.5V RMS) and collecting 10000 samples.
I am using the FFTW open source library to do the Fourier transform. I am using a real to real transform.
I calculate the distortion of each of my harmonics from 2k to 10k and get the THD.
If I apply a 1khz sine wave, my calculated THD almost always matches the PicoScope 6 software result with some fluctuation.
PicoScope gives me -52 dBc while my code gives me around -55 dBc or so, with +/-5dBc variation (and then some every now and then)
If I change it to a triangle wave, however, I do not get the correct result at all.
PicoScope6 gives me -18.5 dBc while my calculation is coming up -11.14 dBc with a LOT of variation.
My PicoScope is configured as follows in fast streaming mode:
#define BUFFER_SIZE 10000
ps2000_run_streaming_ns(picoscope, 1, PS2000_US, BUFFER_SIZE, TRUE, 1, 50000);
Delay(1); //Wait for streaming to fill the buffer
ps2000_get_streaming_last_values (picoscope, ps2000FastStreamingReady);
ps2000_overview_buffer_status (picoscope, &overrun);
no_of_samples = ps2000_get_streaming_values_no_aggregation (picoscope,
&starttime, // get samples from the beginning
values_a, // set buffer for channel A
values_b, // set buffer for channel B
I need the 1 second delay to verify my buffer is full.
My FFTW plan is:
plan = fftw_plan_r2r_1d(BUFFER_SIZE, cha_in, cha_out, FFTW_R2HC, FFTW_ESTIMATE);
I am confident my THD calculations from the FFTW results are correct. But I cannot understand what is causing a variation in my output.
Basically I have a few concerns:
Do I need to convert my sine wave to RMS before doing the transform, or do I keep the peak voltages?
What can I do to smooth my results? It's not uncommon for me to get a 10% variation in the number (10% to 20%THD for example) with an occasional outlier.
Does triggering have anything to do with this?
If anyone who can give me some advice I would be grateful.