# Measure harmonics: Hammerstein vs stepped tones

DSP, Plug-in and Host development discussion.
plusfer
KVRist
61 posts since 1 Apr, 2016
I have been using plugindoctor::hammerstein to analyze harmonic content, but I've noticed that harmonic response is different from measuring tone by tone.
By "tone by tone" I mean sending tones at different frequencies and measuring the amplitude of each harmonic to finally draw a curve joining the different points in the spectrum.

obviously I am misunderstanding , since I was convinced that the result should coincide with "tone by tone" method.

Why do these give different results?
Thanks!

BertKoor
KVRAF
13346 posts since 8 Mar, 2005 from Utrecht, Holland
Is your "tone" a pure sine wave?
We are the KVR collective. Resistance is futile. You will be assimilated.
My MusicCalc is served over https!!

kippertoffee
KVRist
271 posts since 3 Mar, 2004 from Denmark
How does the "hammerstein" method work? With an exponential sine sweep?

plusfer
KVRist

Topic Starter

61 posts since 1 Apr, 2016
BertKoor wrote:
Mon Nov 29, 2021 11:32 pm
Is your "tone" a pure sine wave?
Yes
kippertoffee wrote:
Tue Nov 30, 2021 4:43 am
How does the "hammerstein" method work? With an exponential sine sweep?
Yes, and from what I've seen, it has a length of 12 seconds.

plusfer
KVRist

Topic Starter

61 posts since 1 Apr, 2016
BertKoor wrote:
Mon Nov 29, 2021 11:32 pm
Is your "tone" a pure sine wave?
I think I'm understanding what is happening. Being an exponential sweep sine, the low frequencies will have more predominance, so it will have more distortion.
Perhaps the correct way to analyze it is by sending a linear sweep sine.

urosh
KVRist
339 posts since 4 Oct, 2002
kippertoffee wrote:
Tue Nov 30, 2021 4:43 am
How does the "hammerstein" method work? With an exponential sine sweep?
Based on quick search it seems that hammerstein is system model, where you model nonlinear system as sum(Gn(x^n)) where Gn is some linear filter. If plugindoctor displays these estimated filters, it is not the same as for example Farina's approach (where you have spectrum per harmonic), especially for higher order harmonics.

kippertoffee
KVRist
271 posts since 3 Mar, 2004 from Denmark
plusfer wrote:
Tue Nov 30, 2021 7:10 am
I think I'm understanding what is happening. Being an exponential sweep sine, the low frequencies will have more predominance, so it will have more distortion.
Perhaps the correct way to analyze it is by sending a linear sweep sine.
The Decorrelation process accounts for the additional time spent at low frequencies. If done properly. I did a bit of work with using exp sine sweeps for measuring nonlinearities and if done right it should come out with the same results as tonal analysis. But without actually knowing what's going on under the hood in plugindoctor it's hard to say more.

I don't think you can decorrelate the higher order "impulse responses" when using a linear sweep. It's one of the nice properties of a exponential sweep that you can do that.

kippertoffee
KVRist
271 posts since 3 Mar, 2004 from Denmark
urosh wrote:
Wed Dec 01, 2021 4:48 am
Based on quick search it seems that hammerstein is system model, where you model nonlinear system as sum(Gn(x^n)) where Gn is some linear filter. If plugindoctor displays these estimated filters, it is not the same as for example Farina's approach (where you have spectrum per harmonic), especially for higher order harmonics.
It's possible to extract the filters from sweep measurements. This references papers demonstrating how:

https://se.mathworks.com/matlabcentral/ ... in-toolbox

It does assume a certain model of nonlinearity though.

urosh
KVRist
339 posts since 4 Oct, 2002
kippertoffee wrote:
Wed Dec 01, 2021 5:48 am
It's possible to extract the filters from sweep measurements.
It is extracted via sweep, but these filters are not the same as "harmonic spectrums". x^3 for sine input will contain first and third harmonic, estimated filter for this will not be the same as spectrum of third harmonic alone.

_tweak_
KVRer
5 posts since 19 May, 2020
Can someone please point me to some resources on how to read or interpret the Hammerstein visualization in PluginDoctor?
The manual does not really cover that topic at all. So I‘m not quite sure what I‘m looking at.

Googling it did not help a lot sadly, I’m just more confused about this.

As far as I understand we are looking at the harmonic content of a specific frequency, right?

kippertoffee
KVRist
271 posts since 3 Mar, 2004 from Denmark
urosh wrote:
Wed Dec 01, 2021 5:56 am
It is extracted via sweep, but these filters are not the same as "harmonic spectrums". x^3 for sine input will contain first and third harmonic, estimated filter for this will not be the same as spectrum of third harmonic alone.
I agree with you, I think we were just using different terms. The link I provided gives a method for separating the actual "harmonic spectrums" from the higher order sweep IRs. So separating out first and third, etc.

docdued
KVRian
668 posts since 2 Apr, 2005 from out there
Maybe to clarify this a bit: the peaks in a pure-tone harmonic analysis and in the Hammerstein graph are usually not the same. For instance, if you have a waveshaper like y = x + 0.1*x*x, in the Hammerstein graph you will see one contribution (flat over all frequencies) at 0 dB which comes from the "x" part, and one flat contribution at -20 dB that comes from 0.1*x*x (as you would expect it, because dB = 20*log10(volt)). In the Harmonic Analysis tab, you will see the two peaks, of course, but due to sin^2(x) = 1/2*(1 - cos(2*x)), the contribution at the 2nd harmonic will be at about -26 dB due to the "1/2" factor. You can use the excellent free FuncShaper by RS-MET (if you are on Windows) to experiment with different waveshaping functions and see what they do. It becomes even more complicated with higher terms, as there are contributions of the 2nd harmonic in the 4th harmonic, and so on.
Generally, Plugindoctor follows the approach shown at https://ant-novak.com/pages/sss/ very closely, for those who really want to dive into the mathematical details.

kippertoffee
KVRist
271 posts since 3 Mar, 2004 from Denmark
docdued wrote:
Fri Dec 03, 2021 8:33 am
Generally, Plugindoctor follows the approach shown at https://ant-novak.com/pages/sss/ very closely, for those who really want to dive into the mathematical details.
Unless I'm mistaken, this part of the example code from that link adjusts for the 2nd order harmonic amplitude effect you are describing - and for higher order examples as well...

Code: Select all

``````%% Estimation of filters Gm of Generalized Hammerstein model (Diagonal Volterra Kernels)
% Coefficients A of the transform between the Hm and Gm
A(N,N) = 0;
for n = 1:N
for m = 1:N
if ( (n>=m) && (mod(n+m,2)==0) )
% Eq. (48) of [Novak et al. (2010)]
A(n,m) = (((-1)^(2*n+(1-m)/2))/(2^(n-1)))*nchoosek(n,(n-m)/2) ;
end
end
end

% tranform the HHFR Hm to filters Gm
Gm = Hm/A;
``````

kippertoffee
KVRist
271 posts since 3 Mar, 2004 from Denmark
Oh no, just realised what a load of shit I'm talking

Right you are!