Measurement of distortion factor using WaveSpectra


I have summarized the restrictions and precautions when measuring the distortion factor (THD, THD + N) by combining WaveSpectra (hereinafter WS), sister software WaveGene (hereinafter WG), and an external oscillator.



If you are in a hurry, skip the explanation and refer to the summary

If you measure the distortion factor normally with WS, it will be as follows.
(1) THD is measured smaller than the original value.
(2) With THD + N, it is measured larger than the original value.

There are two possible causes for these measurement errors.
The effect of the window function and the frequency resolution during FFT.

I will investigate with the signal created by WG.
* Since the Wave file created by WG is calculated directly by WS as an input signal, the performance of the sound device itself is irrelevant even when playing it on the sound device at that time.
(It is different from the case of inputting an external signal to the sound device and measuring)

(1) In the case of THD

Create the following two Wave files at 48000Hz, 16bit, which is common in WG. (Wave file length is appropriate) The
first is a mixture of
 Wave1: 1000Hz sine wave, -3dB Wave2: 2000Hz
 sine wave, and -63dB
.
And the second is a mix of Wave1: 1000Hz
 sine wave, -3dB
 Wave3: 3000Hz sine wave, -63dB
.
The two should be 1kHz signals with a distortion factor of 0.1%, with only the 2nd and 3rd harmonics, respectively.

Let's play back the created signal with WS and see the distortion factor (THD).


* Set WS to measurement mode and set the THD and RMS buttons to On.
 (Also, set the number of FFT sample data of WS to 4096 in the setting dialog.)

THD is the numerical value on the upper side of the display part of THD, + N.

Table 1

Window function 1kHz + 2kHz 1kHz + 3kHz
Hanning image image
Blackman-Harris image image
Flat top image image
None (rectangle) image image

You can see that there is a difference depending on the window function. (Especially without the window function (rectangular window), of course, it is terrible.)
Furthermore, you can see that there is a difference between 1kHz + 2kHz and 1kHz + 3kHz.

The THD measurement of WS usually displays the ratio of the fundamental wave component (the maximum component unless otherwise specified) and the component at an integral multiple of the frequency and the RMS value is taken. increase.

Except for the case of a rectangular window where many distortion components different from the original are calculated due to the influence of the frequency response of the window function, both are around 0.08% at 1kHz + 2kHz, which is less than the original value of 0.1%. It is a value.
At 1kHz + 3kHz, the value is even lower, but of course the original value is 0.1%.

However, the Flat top window gives results close to the original value.

These are due to the influence of the window function, as well as the more fundamental reasons:

Imagine that the maximum dB value of Max in each figure is not the original -3dB (except for the Flat top window), and it is slightly different depending on the window function, and the frequency is 996.1Hz instead of 1000Hz. As you can see, the frequency resolution during FFT has an effect.

In the above case, 48000Hz sampling and 4096 points FFT, so the frequency resolution is 48000/4096 = 11.71875Hz.
Therefore, the frequency component of the 85th 11.71875 * 85 = 996.09375Hz is the maximum value when the 1000Hz signal is counted with the direct current as the 0th.
(The next 86th 1007.8125Hz is also closer to 1000Hz, but 996.09375Hz is closer to 1000Hz, so the 85th is the maximum value.)

That is, the low frequency component about 4Hz away from the original 1000Hz. Considering that the value of the frequency component is the amount passed through the bandpass filter with the width of the resolution, you can see that the dB value of Max in each figure above differs depending on the window function. ..
There is a (negative) error due to the difference in the shape of the frequency response near the center of the window function.

Furthermore, for the harmonic components, you can see that the (negative) error increases further by collecting the components at positions that are integral multiples of 996.09375Hz.

For example:
At double 2000Hz, 85 * second 11.71875 * 170 = 1992.1875Hz (deviation of about 8Hz)
At 3000Hz, which is tripled, 85 * 3rd 11.71875 * 255 = 2988.28125Hz (deviation of about 12Hz)
...etc., and the deviation from 2000Hz and 3000Hz naturally increases as the higher harmonics increase. In other words, the THD will be measured smaller than the original value

Because the values ​​that are deviated from the peak of the original frequency component and dropped will be collected . (This is the reason why the higher harmonics are measured lower than the original value.) By the way, in the above case, the double component is actually the 171st instead of the 170th of 85 * 2. 2003.906 It is maximal at 25Hz, and the triple component is maximal at exactly 3000Hz at the 256th instead of the 255th of 85 * 3. In other words, the center that becomes the maximum is deviated from the integral multiple of the fundamental wave. For the time being, using a Flat top window with a flat frequency response near the center will reduce the drop, but the easiest way to obtain accurate values ​​is to do the following when measuring in combination with the WG.


From the above, conversely, if the measurement frequency matches (is in the center) an integral multiple of the resolution of the FFT, it can be measured accurately.
In other words, it is sufficient to measure at a frequency that matches an integral multiple of the resolution from the beginning.
In other words, the sample length of the FFT is equal to exactly an integral multiple of the period of the measured signal.
In this case, the waveforms are connected at the beginning and end of the cut out part, and there is no error for that point no matter where you cut out.
(This is the case where the best result is obtained when no window function (rectangular window) is used.)

Create a Wave file in the WG as follows.
The WG has a function to easily make the frequency an integral multiple of the resolution of the FFT for such a case, and the "optimize for FFT" function, so I will use this. (Refer to the WG help for details.) The
first is a mix of
 Wave1: 996.09375Hz sine wave, -3dB Wave2: 1992.187
 5Hz sine wave, and -63dB
.
The second is a mix of
 Wave1: 996.09375Hz sine wave, -3dB
 Wave3: 2988.281 25Hz sine wave, and -63dB
.
The two should be 1kHz signals with a distortion factor of 0.1%, which have only the second and third harmonics, respectively, as in the first.

* Wave 1: 996.09375Hz sine wave is automatically converted by first setting the frequency setting combo box of Wave1 to 1000, then right-clicking the mouse and selecting "Optimize for FFT (F)". increase.
Be sure to first select 4096 by right-clicking "FFT sample count (T)" as well. (Match to FFT length in WS)

* Wave2: 1992.187 For 875Hz sine wave, right-click the mouse on the frequency setting combo box of Wave2 and select "x 2" in "Multiple of Wave1 (W)". , Will be converted automatically.

* Wave 3: 2988.28 125Hz sine wave is automatically converted by right-clicking the mouse on the Wave3 frequency setting combo box and selecting "x 3" for "Multiple of Wave1 (W)".

Since these are not automatically linked, if you change the frequency of Wave1, you need to repeat the settings of Wave2 and 3 again.

Let's play the created signal with WS and see the distortion factor.

Table 2

Window function 996.09375Hz + 1992.1875kHz 996.09375Hz + 2988.28125Hz
Hanning image image
Blackman-Harris image image
Flat top image image
None (rectangle) image image
Now you can see that the values ​​are correct.

(This time, it is "optimized for FFT", and since the sample length of FFT is equal to exactly an integral multiple of the period of the measurement signal, there is no effect of data clipping, and the measurement is originally correct when "no window function". ← There is only one spectrum of each component)


Let's also look at the case where the fundamental frequency is lower.
It was investigated in the same way for the case of 100Hz.

Table 3

Window function 100Hz + 200Hz 100Hz + 300Hz
Hanning image image
Blackman-Harris image image
Flat top image image
None (rectangle) image image
You can see that the difference due to the window function is larger than in the case of 1kHz.
The Flat top window seems to give results close to the original value.


Let's also look at the case of "optimized for FFT".

Table 4

Window function 100Hz + 200Hz 100Hz + 300Hz
Hanning image image
Blackman-Harris image image
Flat top image image
None (rectangle) image image

You can see that the values ​​are correct.


(2) In the case of THD + N

In the case of THD + N, it should be easier to see that the window function has a large effect.

First, look at the figure below.
image
This is the spectrum of his 1kHz 0dB signal when the Hanning window is hung (4096 points FFT as before), but you can see that the base is widened by the characteristics of the window function.

When calculating THD + N from now on, even if the fundamental wave takes only one frequency component at the position of the maximum value, the problem is where to collect other noise components, that is, where to collect as a part other than the fundamental wave. You should see that
If you include all the base parts, you can imagine that the value will be much larger than it should be. (Actually so)
This is because it is an apparent component of the cutout part of the FFT sample and the window function, and it does not exist in the signal itself.

For the sake of clarity, in the figure above he is displaying S N instead of THD + N, so it should be about 96dB.
As you can see, it is about 95 dB, which is almost the correct value, so on the contrary, you may think that.
However, this is because a part of the range (both sides) near the fundamental wave is excluded from the noise component so that it is almost correct.
(The amount of range to be excluded was determined by experiment.)

When the same signal is displayed with 2048 point FFT so that the base is wider, it becomes as follows, which is also about 88 dB. You can see that it is increasing and the influence of the window function is coming out. (Because the base has expanded more, it cannot be excluded. You can see that it has expanded to 2kHz)
image

If the number of samples is 4096 points or more, there is not much difference in the effect of exclusion.

By the way, if you set it to 996.09375Hz instead of 1000Hz and "optimize for FFT" to eliminate the influence of the base of the window function, you can imagine that good results will be obtained, but that is the following figure.
As you can imagine, it is about 96 dB. (4096 points FFT Hanning window)
image

Next, returning to THD + N and focusing on the harmonic components (and noise) when the window function is used, the base of each harmonic also expands due to the window function, so it is as it is. If all are collected as noise components, they will be larger than the original value for the same reason as above.
Unlike the fundamental wave, the harmonics are not excluded near the center, so all the base components are added and the value becomes large.

For the same reason, THD + N is larger than THD in Table 2 of (1).
Only in the case of "no window function" where each spectrum has only one spectrum and the base does not widen, you can see that both are almost the same 0.1%, which is the correct value.

Therefore, in the case of THD + N, it will be measured larger than the original value .
(Furthermore, you can see that the larger the value of the distortion component and the larger the number of such distortions, the greater the increase due to the influence of the base).
Finally, check with the sine wave + noise signal.

Create a Wave file in the WG as follows.
 Wave1: 1000Hz sine wave, -3dB
 Wave2: White noise, -55.1dB
This should give you a signal of almost 0.1% when measured at THD + N.

(If you look at the FFT of the two components separately as shown below, you can see that the ratio of the RMS value is 60 dB, that is, THD + N is 0.1%.)

1000Hz -3dB only (RMS value -6.01dB) White noise only (RMS value -66.01dB)
image image


For further comparison, I also measured THD + N with a signal of 996.09375Hz -3dB with 1000Hz "optimized for FFT".

THD + N is the value below the THD, + N display.

Table 5

Window function 1kHz + white noise (-60dB) 996.09375Hz + white noise (-60dB)
Hanning image image
Blackman-Harris image image
Flat top image image
None (rectangle) image image

* In general cases where the measurement frequency is not "optimized for FFT", it is still larger than the original THD + N value of 0.1%. (Is the Hanning window the least error?)



* If the measurement frequency is "optimized for FFT", there is no difference that it is larger than the original value, but all are improved and the error is reduced.

In this case, the correct measurement should be possible without the window function, but it is about 0.096%, which is smaller than the original value of 0.1%.
This is because, as explained a little above, a part of the range near the fundamental wave is excluded from the noise component, so the noise component is conversely smaller by that amount.
In the case of "optimized for FFT" and no window function, it was originally excluded because it had no base (only one spectrum) and it was not necessary to exclude it.
In the future, we may not exclude this if there is no window function.
(In the case of no window function, only the measurement frequency whose measurement frequency is "optimized for FFT" is synchronized with the window, and the other noise components are not synchronized, so there is an error due to cutting out by the rectangular window. It should come out. However, in the general case where the noise component is not so large, it should not be a problem.)

(3) Number of FFT sample data

I summarized the difference depending on the number of FFT sample data.



As before, when the fundamental frequency is 1kHz, there is almost no difference as shown below.

The window function is the Hanning window. THD 0.1% is the correct value.

Table 6

number of samples 1kHz + 2kHz 1kHz + 3kHz
4096 image image
16384 image image
65536 image image


However, note that it will be different if the fundamental frequency is lower.
Below is a similar study for the 100Hz case.
You can see that the harmonics cannot be separated unless the number of sample data is increased.
However, even if it is increased, it can be seen that the THD value is not so correct due to the reason (1). (THD 0.1% is the correct value)

Table 7

number of samples 100Hz + 200Hz 100Hz + 300Hz
4096 image image
16384 image image
65536 image image

If "optimized for FFT", 4096 points will be correct.

Table 8

number of samples 105.46875Hz + 210.9375Hz 105.46875Hz + 316.40625Hz
4096 image image
16384 image image
65536 image image



summary

I have summarized what you should be careful about when measuring the distortion factor with WS.

  1. Pay attention to the measurement frequency setting.

    Specifically, WG is used as a signal source instead of an external oscillator as much as possible, and the frequency of the measured signal is "optimized for FFT" on the WG side according to the FFT sample data length of WS, and the frequency is the resolution of FFT. Make sure it matches an integral multiple of.
    This will reduce the measurement error.

  2. Also pay attention to the window function used.

    In the case of THD only, if you "optimize for FFT" as in 1., any window function should not change much, but originally no window function (rectangular window) should be good.
    If you do not want to "optimize for FFT" (such as when using an external oscillator, you cannot optimize), it is better to use the Flat top window.
    It also seems better to use a Flat top window when the fundamental frequency is low.

    For THD + N, also "optimize for FFT" and no Hanning window or window function (rectangular window).
    Note that in the case of Hanning window, the value is slightly higher, and in the case of no window function (rectangular window), the value is slightly smaller at present.

  3. Also pay attention to the number of FFT sample data.

    If "optimized for FFT" does not have much effect, but if "optimized for FFT" is not performed (when optimization is not possible, such as when using an external oscillator), the second harmonics can be reliably separated. Make sure that the data length is about the same.
    If it is too much indiscriminately, the error will increase due to the reason (1).

  4. As the sound device that operates WG and WS, use a sound device that can record and play back at the same time (all double operations are possible).

    If different sound devices are used, such as when using different PCs for playback recording only, the clocks between the two will not be completely synchronized, so even if "Optimize for FFT" in 1. is performed, accurate measurements will not be possible. ..
    (Even if it is a crystal oscillator, even if there is a slight difference in such applications, it is useless.
     As you can see, the width of the spectrum changes steadily.)

  5. Check the distortion characteristics of the sound device itself in advance with your own loop connection.

    Of course, the measurement accuracy depends on the performance of the sound device used.
    Since the measurement result will be the one to which the distortion and noise of the device itself are added, please understand in advance what kind of distortion and noise characteristics the device has.

    Please note that some devices will distort sharply when inputting to around 0 dB, and it may be necessary to limit the input to -2 to 3 dB. (Some of Sound Blaster cards, etc.)

image