Skip to content

wavetool.py: add THD+N and RMS calculation for wave analysis - #524

Closed
aiChaoSONG wants to merge 2 commits into
thesofproject:mainfrom
aiChaoSONG:thdn
Closed

aiChaoSONG wants to merge 2 commits into
thesofproject:mainfrom
aiChaoSONG:thdn

Conversation

@aiChaoSONG

@aiChaoSONG aiChaoSONG commented Nov 18, 2020 •

Copy link
Copy Markdown

@keyonjie @keqiaozhang @xiulipan Please help to review, you can try this PR with any wave you have:
wavetool.py -a thdn -R your-wave-file-path

Signed-off-by: Amery Song <chao.song@intel.com>
Signed-off-by: Amery Song <chao.song@intel.com>
Comment thread tools/wavetool.py
Comment thread tools/wavetool.py
Comment thread tools/wavetool.py
Comment thread tools/wavetool.py
if cmd.analyze == 'wov':
analyze_wav_wov(wave, fs_wav)
if cmd.analyze == 'thdn':
analyze_wav_thdn(wave, fs_wav)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add DC offset calculation? Take average value of the clip to analyse and report as dBFS (repeat for every channel). You can omit the start transient. The fail criteria default should be > -60 dBFS. With 16 bit audio it should be normally around -90 dBFS.

Comment thread tools/wavetool.py
Comment thread tools/wavetool.py
filtered_cut = filtered[samples_skip:,:]
return 10 * np.log10(np.mean(np.power(filtered_cut, 2), axis=0))
filtered_cut = filtered[samples_skip:]
return 10 * np.log10(np.mean(np.power(filtered_cut, 2), axis=0) + eps)

@singalsu singalsu Nov 19, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should call this "THD+N ratio" since it was measured with sine wave input. Extracts from AES spec:

"The test signal shall be a sine wave. The analyzer shall include the standard low-pass filter (see 5.2.5). The total
signal level at the EUT output is measured and recorded. The fundamental component of the test signal present
in the output shall be removed with the standard notch filter (see 5.2.8), and the unweighted level of the residual
shall be measured. The THD+N ratio shall be the difference between the residual level and the total signal
level, expressed in dB."

and

"The test signal level shall be a sine wave at -1 dB relative to the maximum input level (see 6.2.1). "

So, the used sine level should be subtracted from the result. E.g. -81 - (-1) dB gives -80 dB.

Edit: Thinking more I think the "total signal level" above means the RMS level level of output (dBFS) with all the distortion and noise included, so it should be measured too in step. It's simpler to do since you don't need to pass or hard code it here.

@aiChaoSONG aiChaoSONG Nov 20, 2020 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test signal level shall be a sine wave at -1 dB relative to the maximum input level

I think we may not use the THD+N ratio here, because our test signal is not a standard -1 dB sine wave. our loopback wave varies in level, so an absolute value (thdn) is better than a relative value (thdn ratio)

I just realized that we may get a lower THD+N from a wave with lower level, the THD+N ratio is less impacted by this. Thanks.

@singalsu singalsu Nov 20, 2020 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem without ratio is that a muted / a lot attenuated test might achieve a really good THD+N value. You need to set the limit to such that an OK performing system passes it. I would never pass a result worse than -60 dB (equivalent to 10 bits performance - our implementation is 16/24/32 bits).

@aiChaoSONG aiChaoSONG Nov 24, 2020 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@singalsu For a good quality sine wave with -30dB level, and -80dB thdn, the THD+N ratio is on -50dB. it is hard to maintain a 0 dB volume control in our loopback route, how can we deal with this condition? maybe we should keep the calculation of thdn and thdn ratio, and let user to choose what they want to use?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With current test system (headphone out -> headset adapter mic in) I think it's not expected to get any better performance. Could the pass criteria be something like -48 dB until the CI hardware can be upgraded? Testing it is much better than nothing though small issues will be left unnoticed. The THD+N alone is not good because a broken system can get a good result.

@mengdonglin The -50 dB THD+N ratio is performance of a 80's C-cassette player. Please try to escalate the need for better audio validation hardware. We really should be able to use something like -70 to -80 dB THD+N ratio as automatic test pass/fail criteria.

@aiChaoSONG

Copy link
Copy Markdown
Author

This PR will need to wait #539 to be merged first, and also some clean up with wavetool.py, let's concentrate on #539, after cleaning up wavetool.py, this will be picked up.

@plbossart

Copy link
Copy Markdown
Member

@aiChaoSONG @singalsu is this still relevant or should we close this?

@aiChaoSONG

Copy link
Copy Markdown
Author

@plbossart we can close this first, no time to come back now

@aiChaoSONG aiChaoSONG closed this Jun 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants