Sunday, January 15, 2017

fft - Is it only me or matlab's periodogram's function is confusing?


I am really confused with matlab's periodogram.


First of all, it says in the documentation that its unit is "dB per unit frequency". What does that really mean? I just don't quite get it.


Second of all, I'm trying to evaluate an ADC. I tried to measure its linearity but that won't work because when I reduce the level of the input signal by ,let's say, -3dB I excpect to see -3dB reduction in the highest peak of the spectrum, but that's not the case.


Last but not least, with this "dB per unit frequency" when is the highest peak actually 0 dB? It should reach that at a point, right? Because as far as I know dB is always a ratio of some kind. How can I modify it as to give me the values in dBFs for example? so I could get a sense of what my data look like.


Sorry for the long post, Mathworks' Periodogram just doesn't say it clear.


Thank you all.



Answer



As the documentation states, periodogram provides a power spectral density estimate pxx:



[pxx, w] = periodogram(x);

meaning that it shows how the total variance of the signal, var(x), is distributed over the frequency w. This implies that the integral of the estimated spectral density over the frequency axis


trapz(w, pxx)

should correspond to that total variance.


This also means that the psd is not normalized, neither to a total variance of 1, nor to a maximum peak of 1 (= 0 dB). That the result is plotted (not computed!) in dB merely means that the vertical axis shows $10 \, \log_{10}($ pxx $)$, not that it shows a ratio. There is therefore no reason to expect a peak to align with 0 dB; depending on the range of values of the signal it can be both much higher and much lower.


To produce a plot from pxx and w, use


plot(w, 10 * log10(pxx))
xlabel('normalized frequency [rad / sample]')

ylabel('power spectral density [(rad/sample)^{-1}] in dB')

Reducing the level of the total signal by 3 dB means to divide the signal x by a factor of 2. If you do this numerically


periodogram(x)
hold all
periodogram(x / 2)

you will see that the second psd estimate has exactly the same shape as the first, it's just 3 dB lower. If this is not what you find with your measurement data, then this means that either your volume regulation or your ADC do not work correctly.




If you are really sure you want a normalized spectrum, do the following: First, compute the psd estimate:



[pxx, w] = periodogram(x);

Then, normalize the psd, e.g. with respect to the highest peak:


npxx = pxx / max(pxx);

You can then plot the normalized psd on a logarithmic scale like this:


plot(w, 10 * log10(npxx))
xlabel('normalized frequency [rad / sample]')
ylabel('normalized power spectral density')


Note that npxx does not have a unit.




A note about units: The unit of numbers returned as pxx by periodogram & friends depends on the units of the input signal x. Let's say these are dimensionless numbers; then the unit of the numbers in the pxx output is $\rm \frac{1}{rad / sample}$, because it is a density over w which is in units of $\rm rad / sample$. Or let's say these are voltage measurements coming from a calibrated ADC, so that the numbers in x are in volts. Then the unit of the numbers in the pxx output is $\rm \frac{V^2}{rad / sample}$.


If you additionally specify the sampling frequency in the call to periodogram:


[pxx, f] = periodogram(x, [], [], fs);

and fs is in Hz, the pxx is a density over frequency f, and its unit is $\rm \frac{V^2}{Hz}$.


Now if pxx is plotted, it is often plotted logarithmically, like stated above. If the function $10 \log_{10}$ is used, then it is said that the result is in decibel, dB. Then sometimes the unit of 10 * log10(pxx) is written as $\rm \frac{dB}{rad / sample}$. Strictly speaking, this expression doesn't make sense because dB is not just a unit (a different measurement stick) but denotes the use of a different quantity: the logarithm. That's why above I wrote the unit as [(rad/sample)^{-1}] in dB.


No comments:

Post a Comment

periodic trends - Comparing radii in lithium, beryllium, magnesium, aluminium and sodium ions

Apparently the of last four, $\ce{Mg^2+}$ is closest in radius to $\ce{Li+}$. Is this true, and if so, why would a whole larger shell ($\ce{...