(Total) Harmonic Distortion Measurements in Max/MSP
Dear all,
is anyone aware of any input/output related THD measurements in Max/MSP - either using native objects or externals? Either way would be interesting for an initial test.
Thank you,
Max
It is entirely depends on the object you're talking about, how it has been designed and built, and the context withing which it is used, as well as stuff like your dac, sample rate etc. It's like saying "what is the numerical accuracy of programming in C?", it depends whether you use ints or floats or longs etc, and what operating system and hardware is used. Some objects are built to intentionally distort anyway. One could say Max is THD agnostic?
Thank you for your answer, Floating Point.
I am very aware of everything you are pointing out of your comment. I think there was a missunderstanding.
What I am looking for is resources or hints if anybody has implemented a THD measurement procedure so far - either using Max/MSP objects or an external. If not I will know that I have to build it myself.
For my actual application I am doing measurements on outboard equipment. For some tests I simply use the "HISSTools Impulse Response Toolbox". It's great for general convolution tasks, such as retrieving the Magnitude and Phase response of a system.
This toolbox does not include any tools for automated THD measurements though. The [spectrumdraw~] object enables me to do this manually by plotting poth the excitation signal and the return from the DUT (device under test). Since this is tedious and I have some other projects running right now I was looking for an automated way to do this, i.e. automatically do peak-picking, measure the magnitude of each peak and run a continuous calculation for the THD.
I have some colleagues less versed in Max/MSP and DSP so anything that is already done will help me. Otherwise I will implement this as soon as I have more time on my hands again later next year and share it to the community.
Cheers
OK, my apologies! I completely misunderstood your question; off the top of my head I don't know of any, but then that's not the kind of thing I do. The only thing that comes to mind that might help you make your own tool in max is some of the utility objects in the zsa package which can do spectral peak detection etc. But others on this forum would be more knowledgeable. It would be a good project well suited to be made in max, and useful to the community!
I got quite far using [zsa.freqpeak~] and [spectrumdraw~] to indicate the peaks - there is only one step left that I only see complex workarounds for so far:
How do I read a magnitude value from a specific frequency?
I hope this is implemented in [spectrumdraw~] somehow - as it already has the functionality to take in the mouse location and return the magnitude values - but is there a way to poll it through a message or list?
So something like [getmagnitude 500 100 200] (in Hz) which returns something like: [-7. -12.5 -16.3].
Otherwise I will have to iterate over each peak that was found using the [select min max] message. Or simulate mouse movements on the plot...
Any ideas?
for some reason the spectrumdraw is crashing my max-- my package needs updating-- but it's not necessary. the output of zsa.freqpeak has a list of freq-magnitude pairs, so I'd do something like this:
could be expanded on-- might be worth looking at the javascript list-processing examples, and adapt them to get more sophisticated and automated output
Thanks Floating Point,
Ah right! We already get the amplitude values from the [zsa.freqpeak~].
Problem here is it sometimes misses or adds the fundamental, which is required to do the THD calculation either by calculating the delta (delta_n_dBc = F_0_dB - F_n_dB with n being the harmonics/peaks other then F_0
) or by doing the "regular" calculation of summing all partials and then dividing by the fundamental (Ref: https://www.youtube.com/watch?v=s_cVP5gu4SY).
So ideally I want to first collect all the peaks, visually represent them in the spectrum so that the user can do a visual inspection before saving the values, since peaktracking never works perfectly.
Next I take said list of frequency values (fundamental + harmonic peaks) and do the magnitude lookup and trigger the calculation for the THD(+N%).
But as an intermediate solution that should work.
Ideally we would also want to check the "final" frequency list for duplicates because in an ideal case this whole process could run automatically across various fundamental frequencies:
1. Set F0 and output to DUT
2. Find peaks in return (measurement)
3. Calculate THD% for current F0 and add to list [F0, THD%] (maybe plot)
4. Repeat 1 to 4 for desired frequency range
Cheers,
M.
I've made a javascript file to do what you want with the zsa peak freq output list; you need to nominate the fundamental frequency in the js object's 2nd inlet, which should coincide (within a 1% margin of error) with the first frequency in the list input for it to work.
Very cool! Thanks a lot for taking the time to work on this, Floating Point.
I also continued working on the patch yesterday for a bit by saving the peaks to a coll value (enables saving of the raw data for each amplitude & frequency step), defining the signal conditioning of the I/O and drafting a GUI.
If I get the time I'll try to integrate your script and publish it here so we or the community can continue refining it.
Best wishes,
M.
No worries, I'm glad it's of use. Having an intermediate step with the coll is a good idea. If you use my js make sure to check the maths I used to calculate the thd... I'm not 100% sure that aspect is correct.