• Welcome to ASR. There are many reviews of audio hardware and expert members to help answer your questions. Click here to have your audio equipment measured for free!

Some elementary Matlab programs to test your system.

Here's a first-generation Focusrite Scarlett 2i2:

Interestingly, the IRs look a little different.

That is mildly concerning. The "bulge" is very much in line with what I'd expect from that mixed filter, but I can't really explain which is which. I've used this method with (long) phase correction filters, and it appears to work, but it's hard to know. I'm also wondering slightly about Octave, but I find it kind of irritating to use. Once you have the probe signal, of course, you don't need the butter() thing any more.

I also wonder if perhaps the conjugate operation in octave is a touch weird. That would explain the tiny complex output from the ifft.

When I run this on matlab, the result is pure real.
 
Please ignore my ignorance but what is this exercise trying to achieve better than expert multi-platform realtime freeware like REW?

In REW you can use 4M full-frequency measurement sweeps but even better it is to use full-range periodic noise for FR details. With 4M FFT size and averaging you can get stable results down to the mB and µB ranges, exposing even the tiniest wiggles of combined DAC and ADC frequency response (both analog and digital filter functions). It's even showing the usual gain drifts properly in the run-to-run variations.

As usual, when long time constants are involved (DC filters engaged), you need a settling time of seconds if not minutes, that is start, the recording/analysis after the signal has been playing for at least several minutes or so if you want to have high precision near DC.
 
Please ignore my ignorance but what is this exercise trying to achieve better than expert multi-platform realtime freeware like REW?

In REW you can use 4M full-frequency measurement sweeps but even better it is to use full-range periodic noise for FR details. With 4M FFT size and averaging you can get stable results down to the mB and µB ranges, exposing even the tiniest wiggles of combined DAC and ADC frequency response (both analog and digital filter functions). It's even showing the usual gain drifts properly in the run-to-run variations.

As usual, when long time constants are involved (DC filters engaged), you need a settling time of seconds if not minutes, that is start, the recording/analysis after the signal has been playing for at least several minutes or so if you want to have high precision near DC.

Some of us like to play with SW we know better and that is customizable to our needs. REW is great but has a learning curve, as does Matlab (or Octave), and I have been using Matlab for decades while have barely used REW. Matlab is a general-purpose program that allows us to do other things as well (within and outside audio). This thread is just presenting some basic Matlab functions and exercises for those interested in using that tool. No worries if you want to use REW and it offers everything you need, then this thread is useless to you (except perhaps or the additional commentary and analysis from @j_j and other experts). No need to start a Matlab vs. REW debate here IMO.

For myself, it makes it easy to add known errors like random noise, DNL/INL errors, gain matching error among sub-blocks, and so forth to provide insight into their effects on the final output. It is also one of the tools I use to model various components of audio systems for the various "technical" threads linked in my signature to (hopefully) help explain some of the science and engineering behind measurements and other typical audio Q&A subjects (e.g. data conversion, the influence of amplifier damping factor and speaker wires on loudspeaker response, harmonic and intermodulation distortion, etc.)
 
Last edited:
Melts my head, but it's fascinating. It's one of the many things that lifts ASR above 'just' a review and gear forum. Lurking and learning. Thank you posters.
 
That is mildly concerning.
I was able to figure out the reason for the difference: REW oversamples the IR by default when measuring the normal way (i.e. via the "Measure" dialog in the program). If I do an offline measurement using an exported sweep stimulus or if I simply disable the IR oversampling, the resulting IR is effectively identical to what I get with your scripts.

I also tried using your calcimp.m script for the sweep stimulus and the result was again identical to REW.

Probably Octave is using single precision, and you're getting residual imaginary parts due to mantissa length.
It's double precision, but apparently Octave doesn't attempt to deduce whether the result "should" be real (or isn't as good at it as MATLAB). I checked the residual imaginary parts and found that they were all below machine epsilon for IEEE 754 64-bit floating point.
 
  • Like
Reactions: j_j
In REW you can use 4M full-frequency measurement sweeps but even better it is to use full-range periodic noise for FR details. With 4M FFT size and averaging you can get stable results down to the mB and µB ranges, exposing even the tiniest wiggles of combined DAC and ADC frequency response (both analog and digital filter functions). It's even showing the usual gain drifts properly in the run-to-run variations.

If it's periodic, its not noise. What this does is create a pseudo-all-pass sequence that can be deconvolved to the precision in your hardware. No idea what REW does, but I don't own it, and I don't want to have to write programs for yet another language, that is, if REW allows plugins. I dunno. I write my own software so I can see what happens.

Note: There will be some other signals and analysis tools upcoming. This is just a start.
 
It's double precision, but apparently Octave doesn't attempt to deduce whether the result "should" be real (or isn't as good at it as MATLAB). I checked the residual imaginary parts and found that they were all below machine epsilon for IEEE 754 64-bit floating point.

Last time I used octave we had to remake it to push it to double, it came from the "box" <as it were> running in single, which was not great at 1meg transform size. But, yes, finding those under machine epsilon results is a bug, alright.
 
Melts my head, but it's fascinating. It's one of the many things that lifts ASR above 'just' a review and gear forum. Lurking and learning. Thank you posters.
--------------------
A dimly lit room, the soft hum of computer fans filling the air. A faint glow from multiple monitors illuminates the space, casting eerie shadows against the walls. The air is thick with quiet intensity as a group of brilliant minds engage in an incomprehensible discussion.
---------------------
I push the door open just a crack, careful not to make a sound. Inside, a group of nerds is deep in conversation, their words a cryptic blend of jargon and symbols that might as well be an ancient language. Screens flicker with graphs and equations, their faces illuminated by the glow of knowledge far beyond my grasp.
At the far end of the room, a whiteboard stands like an artifact from another time, covered in markings that look less like mathematics and more like something of a lost civilization. Diagrams, arrows, greek letters.
Nobody notices me. They’re too engrossed, hands waving as they debate concepts that likely defy the very fabric of reality. I feel like an intruder in a temple of intellect, a mere mortal trespassing where gods of logic and reason convene.
Slowly, carefully, I step back. No sudden movements. I ease the door shut, sealing them within their world of thought, and leave them to their own fate, whether that be enlightenment… or madness.
 
--------------------
A dimly lit room, the soft hum of computer fans filling the air. A faint glow from multiple monitors illuminates the space, casting eerie shadows against the walls. The air is thick with quiet intensity as a group of brilliant minds engage in an incomprehensible discussion.
---------------------
I push the door open just a crack, careful not to make a sound. Inside, a group of nerds is deep in conversation, their words a cryptic blend of jargon and symbols that might as well be an ancient language. Screens flicker with graphs and equations, their faces illuminated by the glow of knowledge far beyond my grasp.
At the far end of the room, a whiteboard stands like an artifact from another time, covered in markings that look less like mathematics and more like something of a lost civilization. Diagrams, arrows, greek letters.
Nobody notices me. They’re too engrossed, hands waving as they debate concepts that likely defy the very fabric of reality. I feel like an intruder in a temple of intellect, a mere mortal trespassing where gods of logic and reason convene.
Slowly, carefully, I step back. No sudden movements. I ease the door shut, sealing them within their world of thought, and leave them to their own fate, whether that be enlightenment… or madness.

Just as the door closes, it creaks, and suddenly they all look at you suspiciously and start to chuckle evilly. :D
 
If it's periodic, its not noise. What this does is create a pseudo-all-pass sequence that can be deconvolved to the precision in your hardware. No idea what REW does, but I don't own it, and I don't want to have to write programs for yet another language, that is, if REW allows plugins. I dunno. I write my own software so I can see what happens.

Note: There will be some other signals and analysis tools upcoming. This is just a start.
Thanks for the reply... but, you know, I'm really interested in these kind of topics but fail to see even a short summary of what this stuff is going to be about. The thread title is very generic and for me the whole thread has a weird marketing smell to it, in German it's called "Salamitaktik" (piecemeal strategy).

So I kindly ask you to give us a short summary of the problems/issues under investigation and what the solutions are (in digestible language for laypeople, that is, not in bare-bone math but rather outlining the principles).

As for REW, it sort of became the #1 measurement and analysis suite for audio stuff, both in realtime and offline (but not limited to audio. Its FFT analyzer alone is world-class). It is very well respected in the professional engineering world were it often replaces overpriced limited-capability Windows-only commercial software.
 
--------------------
A dimly lit room, the soft hum of computer fans filling the air. A faint glow from multiple monitors illuminates the space, casting eerie shadows against the walls. The air is thick with quiet intensity as a group of brilliant minds engage in an incomprehensible discussion.
---------------------
I push the door open just a crack, careful not to make a sound. Inside, a group of nerds is deep in conversation, their words a cryptic blend of jargon and symbols that might as well be an ancient language. Screens flicker with graphs and equations, their faces illuminated by the glow of knowledge far beyond my grasp.
At the far end of the room, a whiteboard stands like an artifact from another time, covered in markings that look less like mathematics and more like something of a lost civilization. Diagrams, arrows, greek letters.
Nobody notices me. They’re too engrossed, hands waving as they debate concepts that likely defy the very fabric of reality. I feel like an intruder in a temple of intellect, a mere mortal trespassing where gods of logic and reason convene.
Slowly, carefully, I step back. No sudden movements. I ease the door shut, sealing them within their world of thought, and leave them to their own fate, whether that be enlightenment… or madness.
Just as the door closes, it creaks, and suddenly they all look at you suspiciously and start to chuckle evilly. :D
Reminds me of that old (non-Matlab) joke: If you feel you are alone, dim all the lights and watch a horror movie in the dark. Soon you will feel the presence of others.
 
Thanks for the reply... but, you know, I'm really interested in these kind of topics but fail to see even a short summary of what this stuff is going to be about.
Actually the title is exactly precise. Obviously, you MUST be interested, if not, you'd simply move on, so what's the beef?

Your nonsensical rambling about "weird marketing smell" lives in your own mind.

Ok, you're NOT INTERESTED. So don't read it.

So I kindly ask you to give us a short summary of the problems/issues under investigation and what the solutions are (in digestible language for laypeople, that is, not in bare-bone math but rather outlining the principles).

It's as stated in the OP. It is bare-bones math. Live with that, because that's what it is. Again, if you're not interested, DON'T READ IT.

As for REW, it sort of became the #1 measurement and analysis suite for audio stuff, both in realtime and offline (but not limited to audio. Its FFT analyzer alone is world-class). It is very well respected in the professional engineering world were it often replaces overpriced limited-capability Windows-only commercial software.

Then use REW. Nobody is forcing you to read this thread, and it appears to me that you're the one with some agenda. So, go. Use REW. Enjoy it. You don't have to read this thread, unless somebody is paying you to read every thread here and participate. Are they? (Note, that's half-sarcastic, I don't really expect that.)

As to your "windows" crack , Matlab is available on windows, MAC, and at least some flavors of linux. No, I don't sell Matlab, or work at MathWorks, either. Octave is a GNU resource, again "not windows".

Again, if you're not interested, don't read the thread. What makes you so upset about having some freeware posted, anyhow? This is all math from before the flood, so to speak, anyhow, that was understood in some places before digital equipment existed.
 
As for REW, it sort of became the #1 measurement and analysis suite for audio stuff, both in realtime and offline (but not limited to audio. Its FFT analyzer alone is world-class). It is very well respected in the professional engineering world were it often replaces overpriced limited-capability Windows-only commercial software.
I am sure you know this but REW is not matlab. You can't write your own programs and experiment which is what JJ is offering. Matlab is the de-facto standard for simulation of signal processing. REW has no capability in that regard.
 
This is a quick script to write out the horrid "buzz tone" I mentioned elsewhere a long time ago. Using this you can choose your own frequency(s) for bot L and R signals, as well as the stride used. The stride used will determine where the IMD will show up (in this case 499.xx Hz), which is why the two input channels are both around 250. Because of the way it's created and lengthened, you play this, capture the result, then take ***EXACTLY 32768 samples from somewhere in the middle, and analyze it using ***NO WINDOW*** with an analysis length of exactly 32768. It is using this synchronous processing to make resulting crud maximally obvious in a spectrum calculation.

Edited to add: You can change the frequency range of the various tones separately from the distance (in frequency) between them. So, for instance, you can set it up to start at 10kHz, if you want to see what kind of high frequency distortions you get, for instance. You can limit both the ends of the set of tones if you like. For some older transistor amplifiers, started at 12kHz caused, um, "interesting" effects. If you attempt that, please, PLEASE start at low signal input levels. Oh, and you could attempt this kind of measure on a tape deck, watch your levels carefully (and keep them low) and be prepared for some major "WTF was that" experiences.

Again, this is more basic mathematics. I don't mind explaining how all of this works at some level, if you ask nicely, at least.

clc
clear all
close all

pl=primes(255); %255 is a magic number, want the two closest to 250, one above and one below

lfreq=pl(end-1);
rfreq=pl(end);
fs=48000;

len=32768;
rng('shuffle');

ilf=round(len/fs*lfreq-1);
irf=round(len/fs*rfreq-1);
istride=round(len/fs*500);%yes, this partially obviates the use of primes above, but useful as we shall see

xt(1:len,1)=0;
xt(ilf:istride:(len/2), 1)=1;
xt(irf:istride:(len/2), 2)=1;
for(ii=2:len/2)
t=rand()*2*pi;
xt(ii,1:2)=xt(ii,1:2)*(cos(t) + i*sin(t)); %reduce peak to rms ratio more or less
end

xt(len:-1:(len/2+2),1:2)=conj(xt(2:(len/2), 1:2));

x=ifft(xt);


t=max(max(abs(x)));
x=x/t*.9;

plot(x)

for ii=1:6 %increase length by catenation (hence the fft use for glitchfree outcome)
x=[x; x];
end


audiowrite('dontlistentome.wav',x,fs,'BitsPerSample',24);

Note, the name of this file is self-documenting. DO NOT LISTEN TO IT, and if you MUST, turn the level WAY the h311 down first. IT IS A SIGNAL FOR DAC/ADC/ELECTRONICS. DO NOT PUT THIS INTO A LOUDSPEAKER AT ANY LEVEL. NEVER, for your sake and the tweeter's. Just don't. You are formally warned. DO NOT PLAY INTO LOUDSPEAKERS THAT IS NOT WHAT THIS IS FOR.
 
Last edited:
Actually the title is exactly precise. Obviously, you MUST be interested, if not, you'd simply move on, so what's the beef?

Your nonsensical rambling about "weird marketing smell" lives in your own mind.

Ok, you're NOT INTERESTED. So don't read it.



It's as stated in the OP. It is bare-bones math. Live with that, because that's what it is. Again, if you're not interested, DON'T READ IT.



Then use REW. Nobody is forcing you to read this thread, and it appears to me that you're the one with some agenda. So, go. Use REW. Enjoy it. You don't have to read this thread, unless somebody is paying you to read every thread here and participate. Are they? (Note, that's half-sarcastic, I don't really expect that.)

As to your "windows" crack , Matlab is available on windows, MAC, and at least some flavors of linux. No, I don't sell Matlab, or work at MathWorks, either. Octave is a GNU resource, again "not windows".

Again, if you're not interested, don't read the thread. What makes you so upset about having some freeware posted, anyhow? This is all math from before the flood, so to speak, anyhow, that was understood in some places before digital equipment existed.
I believe he was asking for an explanation of what these test tones offer that is either better or different from what we already use in REW.
 
I believe he was asking for an explanation of what these test tones offer that is either better or different from what we already use in REW.

It's kind of strange to ask that via making claims of weird marketing approaches.

There's very little different, other than the actual mathematical functions used. Using something that will always assure "no zeros in the transform" is very useful in that it allows very precise, quick calculations. "spreading out" a pulse (which is in effect what the signal generation does for the first signal) ensures a happy peak to RMS ratio, ensuring a good SNR of the final measurement. Using a chirp or a sweep (almost the same thing) has almost the same properties, it has a bit more noise immunity, but also can have some 'gotcha' issues in weird situations.

The second signal is purely for IMD testing, it will show up IMD with a very visible low frequency tone that did not exist in the input at all. It will also throw all the first IMD lines into the first distortion line, and so on (i.e. lines at 499.xx * n for integer 'n' distanced IM products. It's rather a very visual way of showing the errors.

Just asking that would have been simple, no? (not addressing that to you)

And of course, octave and this code are all free for non-commercial use.
 
It's kind of strange to ask that via making claims of weird marketing approaches.

There's very little different, other than the actual mathematical functions used. Using something that will always assure "no zeros in the transform" is very useful in that it allows very precise, quick calculations. "spreading out" a pulse (which is in effect what the signal generation does for the first signal) ensures a happy peak to RMS ratio, ensuring a good SNR of the final measurement. Using a chirp or a sweep (almost the same thing) has almost the same properties, it has a bit more noise immunity, but also can have some 'gotcha' issues in weird situations.

The second signal is purely for IMD testing, it will show up IMD with a very visible low frequency tone that did not exist in the input at all. It will also throw all the first IMD lines into the first distortion line, and so on (i.e. lines at 499.xx * n for integer 'n' distanced IM products. It's rather a very visual way of showing the errors.

Just asking that would have been simple, no? (not addressing that to you)

And of course, octave and this code are all free for non-commercial use.
Thanks for the explanation.
 
Using a chirp or a sweep (almost the same thing) has almost the same properties, it has a bit more noise immunity, but also can have some 'gotcha' issues in weird situations.
Thanks; I was wondering whether the "whoosh" had any particular advantage. Would you mind expanding on where it might work better than a sweep?

As to your "windows" crack [...]
FWIW, I don't think that was directed at MATLAB or Octave.
 
Thanks; I was wondering whether the "whoosh" had any particular advantage. Would you mind expanding on where it might work better than a sweep?

Well, aside from avoiding a wicky sickit of conflicting patent claims,and avoiding issues around DC values, which are assured with this particular setup, and an assured very, very small condition number for direct deconvolution that does not require a system to settle to "steady state", not a lot. It's the modern take straight out of the very old Heyser methods. https://en.wikipedia.org/wiki/Condition_number (yes, these are all at their heart matrix operations, although FFT's can help by a few orders of magnitude or 6)

It also can be used, say, for timing detection, with very short bursts (you have to massage the 2 coefficients once you sent the length) to get very, very good time resolution even in extremely noisy situations. You can make a set of these (I have done this before, but since they are somebody else's now, I'd have to make a set of coefficients) and have a set of signals of length power of 2 and just use them safely. Note that the script does not take the direct transform of the signal, it takes the transform of TWICE the length. Since an allpass sequence mathematically has to be infinite in length, these (or sweeps, etc) can not be, but they can come really, really close, without being reduced to an impulse. Measuring the response with an equal stretch of zeros after it shows any extremes that result from taking the signal out of a circular space (FFT's are circular, remember, so the last sample is next to the first in a circle in time, it's not just a stand-alone signal) and into a "one shot" use, with the resulting less-than-perfect-flatness, which can be measured and plotted just to be sure one did not stumble into some very particularly unusual situation. With a bit of optimzation, it's even possible (watch your CPU spin all night) maximize both flatness (with the 2x length with zeros attached, or even better the signal padded with 3 times zeros, before or after does not matter) and "width" of the resulting signal. In the past for fixed applications I've done that, but what is here is pretty good indeed, it's 99% of the result at .05% of the work, just check first.

In short, when you're attempting to deconvolve by it, you'll always get a good condition number, without zeros, etc. That should be true with sweeps, but it's, um, 'interesting' sometimes.

In addition, sometimes when using sweeps, especially longer ones, on real equipment, having the entire energy focused in time at one small set of frequencies can have "interesting" results (excite physical resonances for instance). With something that has less energy spread over a wide time frame, you will see the resonance, but not see potential nonlinear results. (none the less yeah, you should "fix that" when you find it,but it's cheaper that way sometimes) :)

FWIW, I don't think that was directed at MATLAB or Octave.
What was the intended subject? In any case, if the other poster is happy, great. If not, I was not volunteering, here, at this time and place, to give a full mathematical tutorial, and to me the design, code, and intent are, well, obvious.

I will say that getting octave (or buying the home Matlab, although I don't generally tell people to spend money) and trying these scripts, playing with them, etc, can help you discover all sorts of handy-dandy things that you can't do otherwise. So if you're curious, give it a try. If not, well, ok, you don't have to care, and that's ok.

I started to give out some very elementary tools, and somehow this turns into an argument. I have no problems with somebody using REW, what I don't understand is why someone would object to some other methods that allow pretty much total control over what you get, at, yes, a much more limited ability to graph without writing some of the code yourself. Nobody has to care in this instance.
 
Last edited:
Back
Top Bottom