0
$\begingroup$

I will take two sine waves i) 0.1 AMPLITUDE with no phase shift ii)0.4 amplitude with some phase shift 20 degree (Considering Both same frequency).

In time domain - If i divide signal 1 by signal 2 by taking RMS value,it was nearly 0.25
In frequency domain - I took fft of both the signals and divided signal 1 by signal 2, i got the result in real and imaginary part.

If i take the RMS value of frequency domain output(real and imaginary), i am not able to get the same result as time domain.

So what should i do to get the same result in both the case.

Thanks

$\endgroup$
2
  • $\begingroup$ When you said " RMS value of frequency domain output(real and imaginary)" does that mean you did separate RMS calculations and simply added them? $\endgroup$ Commented Mar 27, 2018 at 12:40
  • 1
    $\begingroup$ Why dont you share your code with us, this way the question and the problem become easier to understand. $\endgroup$ Commented Mar 27, 2018 at 12:42

2 Answers 2

1
$\begingroup$

Here is one way to do it properly:

import numpy as np

#=======================================================================
def main():

        t = np.arange( 0, 200 )  
        N = len( t )

        signal1 = 0.1 * np.sin( .1 * t )
        signal2 = 0.4 * np.sin( .1 * t + .35 )

        rms_time1 = np.sqrt( np.sum( signal1 * signal1 ) / N )
        rms_time2 = np.sqrt( np.sum( signal2 * signal2 ) / N )
        q_time = rms_time1 / rms_time2

        print q_time, rms_time1, rms_time2

        dft1 = np.fft.fft( signal1 )
        dft2 = np.fft.fft( signal2 )

        dft1_real = np.real( dft1 )
        dft1_imag = np.imag( dft1 )
        dft2_real = np.real( dft2 )
        dft2_imag = np.imag( dft2 )

        rms_freq_real1 = np.sqrt( np.sum( dft1_real * dft1_real ) / N )
        rms_freq_imag1 = np.sqrt( np.sum( dft1_imag * dft1_imag ) / N )
        rms_freq_real2 = np.sqrt( np.sum( dft2_real * dft2_real ) / N )
        rms_freq_imag2 = np.sqrt( np.sum( dft2_imag * dft2_imag ) / N )

        rms_freq1 = np.sqrt( rms_freq_real1 * rms_freq_real1 \
                           + rms_freq_imag1 * rms_freq_imag1 )

        rms_freq2 = np.sqrt( rms_freq_real2 * rms_freq_real2 \
                           + rms_freq_imag2 * rms_freq_imag2 )

        q_freq = rms_freq1 / rms_freq2

        print q_freq, rms_freq1, rms_freq2

        print rms_freq1 / rms_time1
        print rms_freq2 / rms_time2
        print np.sqrt( 200 )

#=======================================================================
main()

The output is:

0.246138603222 0.0699023232816 0.283995774603
0.246138603222 0.988568136262 4.016306761
14.1421356237
14.1421356237
14.1421356237

Followup:

This is a more straightforward way to calculate the RMS of the DFT bins. I coded the sample above to more closely align with how I thought the OP was doing it.

        sumsquares1 = np.real( np.sum( dft1 * dft1.conjugate() ) )
        sumsquares2 = np.real( np.sum( dft2 * dft2.conjugate() ) )

        rms_freq1 = np.sqrt( sumsquares1 / N )
        rms_freq2 = np.sqrt( sumsquares2 / N )

        q_freq = rms_freq1 / rms_freq2

        print q_freq, rms_freq1, rms_freq2
$\endgroup$
3
  • $\begingroup$ And one more thing i need to clarify, After dividing dft1 and dft2 we will get real and imaginary parts, By using these real and imaginary parts can i get the same value as in time domain. $\endgroup$
    – sk gowda
    Commented Mar 27, 2018 at 16:24
  • 1
    $\begingroup$ @sk gowda, The key here is Parseval's Theorem which says the sum of the squares will be preserved for a properly normalized DFT, i.e. 1/sqrt(N) which makes the transform unitary. Since your signal is real valued, the magnitude squared of each sample is the value of the sample squared. For your bin values (a+bi) the magnitude squared is a^2+b^2. The RMS calculation sums the squares first. In my sample code I simply summed all the a^2 values and b^2 values and then added them using Pythagorean theorem. The final three prints are to demonstrate the rescaling factor for proper normalization. $\endgroup$ Commented Mar 27, 2018 at 16:34
  • $\begingroup$ @sk gowda, I added a followup. $\endgroup$ Commented Mar 27, 2018 at 17:20
1
$\begingroup$

Can you please make more clear what you mean by "divide signal 1 by signal 2". Is it $z[n] = x[n] / y[n] = x[n] \times y^{-1}[n] $ what you mean?

It doesn't make much sense to me such a non-linear operation. What is the purpose of this? For example, if $ y[n] = 0 $ for some $n$, what do you expect as your result? Maybe I can help you if you make this more clear.

Besides, applying a division in the time domain does not match division in the frequency domain. I don't see why you expect to obtain the same result.

$\endgroup$
2
  • $\begingroup$ Firstly thank you......As per RLC circuit , Z =sqrt(R^2 + X^2). so i considered one signal 0.1 amplitude as voltage with some phase shift 20 degree and another signal 0.4 as current. As per my knowledge , Zrs=Vrms/Irms . and Zrs= sqrt(R^2 + x^2) , Here i considered real part as Resistance and X as reactance. so both Zrs may be same. correct me if i am wrong. $\endgroup$
    – sk gowda
    Commented Mar 27, 2018 at 16:12
  • $\begingroup$ My bad, I didn't read carefully your question. Of course, if your refer to RMS values, my comment before is out of place. And the answer of @Cedron Dawg is the right one. $\endgroup$ Commented Mar 28, 2018 at 13:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.