DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

FFT calculation...how it works (in DIAdem)?

Solved!
Go to solution

Hello Federico,

 

after looking to your example, I think the problem is in the formulas on wikipedia. The correct way is to divide to summation of the squared time values by N and not the summation of FFT-values. If you go to the talk part of the wikipedia article, you will find that someone proposed this in the year 2007. He wrote:

 

The discrete time Parseval's Theorem for a periodic function should have the 1/N term in the discrete time domain instead of in the frequency domain. I don't have a textbook to confirm this so I did not edit it in the article.

Here is the original (current) equation:

 \sum_{n=0}^{N-1} | x[n] |^2  =   \frac{1}{N} \sum_{k=0}^{N-1} | X[k] |^2

Here is what I beleive is correct:

 \frac{1}{N} \sum_{n=0}^{N-1} | x[n] |^2  =    \sum_{k=0}^{N-1} | X[k] |^2
Unfortunately, no change was made.

 

It is also not correct to multiply the FFT-values by 2 and the Abs() function is not needed because the values are squared.

 

The correct script part should be:

 

tempPower = 0

For n = 1 to ChnPropValGet("ParsevalTheorem/Signal", "length")
  tempPower = tempPower + (CHDX(n,cNO("Signal")))^2
Next
tempPower = sqrt(tempPower/nSamples)


rmsPower = 0

For n = 1 to ChnPropValGet("ParsevalTheorem/AmplitudeRMS", "length")
  rmsPower = rmsPower + (CHDX(n,cNO("AmplitudeRMS")))^2

computed by DIAdem
Next
rmsPower = sqrt(rmsPower)

The power of a sine of 1 (peak to peak) is always 0.707106781186543. (That is 1/sqrt(2)).

 

This works with different number of values and different sampling frequencies.

 

Regards

Ulrich Bierwisch

0 Kudos
Message 11 of 20
(4,705 Views)

Ulrich,

 

Thanks for your effort in finding a solution to my question.

I am quite sure that the wikipedia formula is correct (the one with 1/N on the X(k) side ). I attach the Parseval Theorem formula taken from the following textbook (find on google scholar):

"Digital Signal Processing: A Pratical Guide fo Engineers and Scientist", Steven W. Smith.

 

Apart the formula, I am not fully agree with your modifications in the code:

 

a- It is correct to taking the absolute values before squaring beacuse there should be complex values in the signal as well as in the FFT.

 

b- The number of frequency sample produced by the FFT in DIAdem is half the nuber of the time samples (N-->N/2), so it is mandatory to "virtually" dubling the power value by multiplying for 2. Of course this assumption is valid if DIAdem do not iclude this multiplication automatically inside the FFT computation, and this fall in the middle of my question...

 

Finally,why you take the sqrt() of the power? The rms of a unitary sinusoidal wave is 1/sqrt(2), not the power. The rms of a discrete signal x with N samples is: rms(x) = sqrt(sum(x^2)/N). I think that following your example one calculates the RMS not the power.

 

 

Regards,

 

Federico

0 Kudos
Message 12 of 20
(4,698 Views)

Hi Fedirico,

 

DIAdem 2012 and prior versions do not operate with complex values, because there are no complex data channels.  That is why in DIAdem the "abs" function is not required-- all the input data channel values are real only.  Where do you see your imaginary values in DIAdem?  Are they stored in a separate data channel?

 

Brad Turpin

DIAdem Product Support Engineer

National Instruments

0 Kudos
Message 13 of 20
(4,693 Views)

Hi Brad,

 

I know there are not complex values in DIAdem, however it is "formally" right taking the absolute value, at least in the case that we are speaking about. If one calculates the FFT with real and imaginary parts (it is possible in DIAdem by setting to 1 the parameter FFTcalc) the modulus of the complex value (real+immaginary) is necessary.

I don't know if there are other examples of imaginary values usage in DIAdem, as I said I am just a new user :-).

 

Thank you.

 

Regards,

 

Federico

 

 

0 Kudos
Message 14 of 20
(4,681 Views)

Hi Federico,

 

You are right.

The results in my example are the rms values. I'm sure they are correct for the time and the FFT-version.

 

I'm not sure what the correct power result should be. Is it just the power of the rms?

 

I cannot tell if the equations in your links are expecting the complex result of the FFT (real and imaginary part seen as a complex vector) or the calculated amplitudes as rms or peak values. I'm not sure if the FFT is expected as a one sided result or a two sided result but still going from 0 to N-1 with 0 Hz in the middle. N is used in some areas as the number of time values and the summation of the FFT values is running from 0 to N-1 (wikipedia). In you latest link the summation is running from 0 to N/2 and not N/2-1 but with a modified spectrum at 0 and N/2.

 

I know exactly what DIAdem is calculating and the results are almost exactly the same as in a number of other programs if the corresponding functions are used.

In some cases, there are additional FFT calculations giving complex results or the full two sided spectrum. DIAdem is not doing this, because this kind of results is usually not used directly. Those results are basic, raw results which are used in further calculations producing the results which are available in DIAdem in one step.

 

If you know what the expected result in your example is, it should be easy to change your script to get this result with time and FFT data. This script should then be correct for all kinds of data.

 

Regards

Ulrich Bierwisch

0 Kudos
Message 15 of 20
(4,674 Views)

Dear Ulrich and Brad,

 

Thank you once more for your time spent to help me in this question.

 

I decided to attach to this post an example of the results obtained with DIAdem and with Matlab in calculating FFT and power of a rectangular pulse.

I calculated the FFT spectra (real, imaginary and amplitude) in Diadem and Matlab, obtaining the figures attached.

 

The spectrum in the two case (Matlab and DIAdem) are similar in shape but very different in magnitude. This difference is evident once one calculates the signal power in time and frequency (parseval theorem, with the wikipedia equation).

 

As expected in Matlab one obtains the same power values in the time and in the frequency domain, that is 11.

 

In the DIAdem case one obtains the right power value in the time domain (i.e. 11) but not in the frequency domain, where the power is 0.004154. Incidentally, the ratio between power values in the two domains is about 50^2, i.e. the square of half of the number of time samples, i.e. (100/2)^2. Unfortunately, this "golden rule" is not perfect and change depending on the signal.

 

So, my question is again the same: why there is this difference in the power values? And, why the spectra are not the same of Matlab ones?

 

Regards,

 

Federico

 

 

 

0 Kudos
Message 16 of 20
(4,670 Views)

Hi Federico,

 

The spectrum in you matlab picture is definitely not a peak spectrum. With values up to 1 in the time domain you never get amplitudes above 10 in frequency domain. I don't understand what kind of a result this is. Is there a sampling frequency involved and there is some kind of a density calculated?

 

I also don't understand the scaling of the X-Axis in the graphs. If this is the number of the values, there should be no value above 50 in the spectrum if you use 100 values in time domain.

 

The shape of the spectrum is almost identical to the DIAdem-result but multiplied by 50. In addition DIAdem is dividing the first value by 2.

0 Kudos
Message 17 of 20
(4,645 Views)

Hello Ulrich,

 

As said in the text the time signal is a rectangular pulse with extension equal to 11, centered in the sample 50. For such a signal I didn't ever expect a frequency peak, instead the right FFT is a sinc function exactly as I have obtained (the graph shows the absolute value for comparison with DIAdem).

In time the x scaling is the numer of samples, with 100 samples from 1 to 100. The same is in frequency domain, from 1 to 51, 50 samples in total (Matlab produces 100 samples also for the FFT, I have cutted the first half, negative frequencies, for an easy comparison with DIAdem FFT).

After this explanation, I want discuss your most interesting comment: "The shape of the spectrum is almost identical to the DIAdem-result but multiplied by 50. In addition DIAdem is dividing the first value by 2."

Every person can see that the shape is almost the same, in fact this was not the question of this post. The problem is the difference between the two magnitudes. As I have already noticed there is a kind of "N/2 factor" (with N number of time samples) between the two spectra, but this is not a rule. If one go from easy signals to more complex ones (as it is my case of analysis) the "N/2 factor" doesn't hold.

 

 

So, once more again....why this difference?

 

Regards,

 

Federico

 

 

0 Kudos
Message 18 of 20
(4,616 Views)
Solution
Accepted by topic author FT16100

Hello Federico,

 

I realy don't know why there is this difference.

 

I'm sure the FFT-Amplitude-Peak of DIAdem is correct. The total RMS in Time-domain is identical to the total RMS in frequency domain. (We have seen this calculation some posts above).

The total RMS of a signal has to be the same in frequency and time domain. This is the case in DIAdem and this proves, that the DIAdem-result is correct.

 

The results in DIAdem are tested and compared to a lot of different programs for more than 20 years now. Unfortunatly I'm not able to test against matlab.

 

I don't know what kind of calculation you are doing in matlab. I'm sure that matlab is usually giving correct results. I don't think that this result is the peak magnitude. Instead I think there is some kind of misinterpretation what kind of results are calculated. My best guess at this moment is, that the matlab result is some kind of a density which means that the result is divided by dF or something.

 

Regards,

 

Ulrich

0 Kudos
Message 19 of 20
(4,595 Views)

Hi Ulrich,

 

It is far from me to say that DIAdem doesn't work well, I like this software. Just that... the spectra have the right shapes but too much lower values respect those I am expecting. In Matlab I have used the fft() function with the rectangular pulse as input. That's it. The "amplitude spectrum" in the figure is the modulus of the output samples.

 

In contrary to you, I think that both RMS and Peak FFT in DIAdem include a kind of division of each frequency samples for half the number of time samples. I don't know the reason, really. But this is clear.

I can say nothing about the descriptive statistics tool, I did not use it enough.

 

Anyway I consider closed this post, thanks to all of you that have helped me on this subject.

 

Regards,

 

Federico

0 Kudos
Message 20 of 20
(4,590 Views)