Reply by Clyde September 29, 20072007-09-29
Randy Yates wrote:
> "mnentwig" <mnentwig@elisanet.fi> writes: > > >> It can be done without windowing, as Randy said. It can also be done with >> windowing, >> > To be honest, my response was probably a little knee-jerk. I was > thinking to myself, "Oh my, another abuse of windowing yet again." > Only in this application, I'll have to back-peddle and agree that, > under certain scenarios at least, windowing makes sense. > > Those scenarios are the ones in which there are not a lot of cycles of > signal captured for analysis. My thinking is that if there are a lot > of cycles captured (say, >100000) , then the energy of the main tone > is going to far outweigh any energy in the "splatter" due to > truncation at the ends. Alternately, as the number of cycles captured > drops, the relative percentage of the splatter goes up and at some > point becomes non-negligible. > > Here's an alternate approach (probably already done by someone out there): > "cancel" the tone instead of "notching" it. In other words, given that you > know the frequency f being used for test, estimate the parameters A and theta > in the signal model s = A*sin(2*pi*f*t + theta) to model the signal in the > captured signal+noise, and then subtract out the estimated signal. You probably > would get better results filtering the data prior to estimating the model > parameters, but the filter's amplitude and phase response would have to be > factored back into the actual modeled amplitude and phase. > > In practice, windowing may work just about as well and is a lot easier. > > Just my $0.02. >
Thanks to the both of you! Monday i'll compare the results from my algorithm with audio precision equipment. -- Clyde
Reply by Randy Yates September 27, 20072007-09-27
"mnentwig" <mnentwig@elisanet.fi> writes:

> It can be done without windowing, as Randy said. It can also be done with > windowing,
To be honest, my response was probably a little knee-jerk. I was thinking to myself, "Oh my, another abuse of windowing yet again." Only in this application, I'll have to back-peddle and agree that, under certain scenarios at least, windowing makes sense. Those scenarios are the ones in which there are not a lot of cycles of signal captured for analysis. My thinking is that if there are a lot of cycles captured (say, >100000) , then the energy of the main tone is going to far outweigh any energy in the "splatter" due to truncation at the ends. Alternately, as the number of cycles captured drops, the relative percentage of the splatter goes up and at some point becomes non-negligible. Here's an alternate approach (probably already done by someone out there): "cancel" the tone instead of "notching" it. In other words, given that you know the frequency f being used for test, estimate the parameters A and theta in the signal model s = A*sin(2*pi*f*t + theta) to model the signal in the captured signal+noise, and then subtract out the estimated signal. You probably would get better results filtering the data prior to estimating the model parameters, but the filter's amplitude and phase response would have to be factored back into the actual modeled amplitude and phase. In practice, windowing may work just about as well and is a lot easier. Just my $0.02. -- % Randy Yates % "My Shangri-la has gone away, fading like %% Fuquay-Varina, NC % the Beatles on 'Hey Jude'" %%% 919-577-9882 % %%%% <yates@ieee.org> % 'Shangri-La', *A New World Record*, ELO http://www.digitalsignallabs.com
Reply by mnentwig September 27, 20072007-09-27
It can be done without windowing, as Randy said. It can also be done with
windowing, but why make it more complicated.

I've got an example on my web page, that does a similar job. If you like,
have a look (below). The method is a bit more complicated, but you could
copy the general approach:

- Generate a test signal
- Measure the signal power, check that you get what you expect
- Add some noise
- Measure the noise power. Check that you get what you expect
- ... SNR

It also gives some idea about what accuracy you can expect. The example is
probably close to optimal (textbook case of a correlation receiver).
A signal buried under 30 dB of noise is measured with << 1 dB accuracy
within 60ksamples. 
If your results fluctuate much more, you should have a good explanation
for your customer :)

Cheers

Markus
http://www.elisanet.fi/mnentwig/webroot/SNR_FFT_correlation_example/index.html
Reply by Clyde September 27, 20072007-09-27
mnentwig wrote:

>>> You don't want to window a THD measurement. >>> > Well, I do. Unless I'm smart enough to figure out a full number of periods > from the known test tone frequency for the FFT filter :) >
I just tried that in matlab and i think it's better to window the signal, otherwise i obtain a filtered signal with a really high noise level To be clear: y = signal k = y * window thd+n = rms(notch(k)) / rms(k) * 100 = 0.0014% thd+n = rms(notch(y)) / rms(y) * 100 = 2.35 % with this signal: http://kinetrope.dyndns.org/FFT_Signal.png
> The numerator / denominator question depends on what I want to get: THD > increases, when the noise increases. Signal-to-noise ratio decreases, when > the noise increases. Feel free to take the inverse (or use a minus sign on > a dB scale). > > Now Wikipedia says THD+N is equal to SINAD, and if I blindly use equations > without understanding them you bet I'll get what I deserve...
I do not trust blindly wikipedia, it's just that i always read about thd+n expressed in that form rather than the inverse, and wikipedia was a quick reference :)
> Cheers > > Markus >
Now... if i'm right you suggest to do something like that: y = signal k = y * window thd+n = rms(notch(k)) / rms(k) * 100 am i right? -- Clyde
Reply by Randy Yates September 27, 20072007-09-27
Clyde <nospam@nospam.edu> writes:

> Randy Yates wrote: >> >> Neither one are correct. You don't want to window a THD measurement. >> >> The right answer would be >> >> thd+n = rms(y)/rms(notch(y)) * 100 >> > in that case, shouldn't that be > > thd+n = rms(notch(y)) / rms(y) * 100 ?
Yes. -- % Randy Yates % "She tells me that she likes me very much, %% Fuquay-Varina, NC % but when I try to touch, she makes it %%% 919-577-9882 % all too clear." %%%% <yates@ieee.org> % 'Yours Truly, 2095', *Time*, ELO http://www.digitalsignallabs.com
Reply by mnentwig September 27, 20072007-09-27
>> You don't want to window a THD measurement.
Well, I do. Unless I'm smart enough to figure out a full number of periods from the known test tone frequency for the FFT filter :) The numerator / denominator question depends on what I want to get: THD increases, when the noise increases. Signal-to-noise ratio decreases, when the noise increases. Feel free to take the inverse (or use a minus sign on a dB scale). Now Wikipedia says THD+N is equal to SINAD, and if I blindly use equations without understanding them you bet I'll get what I deserve... Cheers Markus
Reply by Clyde September 27, 20072007-09-27
Randy Yates wrote:
> > Neither one are correct. You don't want to window a THD measurement. > > The right answer would be > > thd+n = rms(y)/rms(notch(y)) * 100 >
in that case, shouldn't that be thd+n = rms(notch(y)) / rms(y) * 100 ? ( http://en.wikipedia.org/wiki/Total_harmonic_distortion#THD.2BN ) Thanks -- Clyde
Reply by Randy Yates September 27, 20072007-09-27
Clyde <nospam@nospam.edu> writes:

> Hi, > i wrote a little algorithm to measure the THD+N of a 1kHz sinus. > > The pattern i follwed is: > > y = original sinus; > k = y * blackman-harris window > z = notch(k) > > now, my question is: > what's the right value? > > is it > > thd+n = rms(z)/rms(y) * 100 > > or > > thd+n = rms(k)/rms(y) * 100 ? > > (the first one is about half of the second one in every test i did) > > Thanks!
Neither one are correct. You don't want to window a THD measurement. The right answer would be thd+n = rms(y)/rms(notch(y)) * 100 -- % Randy Yates % "...the answer lies within your soul %% Fuquay-Varina, NC % 'cause no one knows which side %%% 919-577-9882 % the coin will fall." %%%% <yates@ieee.org> % 'Big Wheels', *Out of the Blue*, ELO http://www.digitalsignallabs.com
Reply by Clyde September 27, 20072007-09-27
mnentwig wrote:
> The window causes a gain difference, so I cannot directly compare the power > in windowed and unwindowed data. > > -mn >
You mean the right answer is the first one? -- Clyde
Reply by mnentwig September 27, 20072007-09-27
The window causes a gain difference, so I cannot directly compare the power
in windowed and unwindowed data.

-mn