1

I have the sample set of ideal and real secondary current during CT saturation, need to apply the DFT analysis to samples and estimate the fundamental phasor (magnitude and phase angle) of samples:

enter image description here

I am far from digital signal processing but I suppose the main idea is to perform computation at each sample $m$ on the basis of $N$ historical samples. I've been trying to apply the following expressions: $$I_{k}(m)=\sqrt{I_{RE}^2(m)+I_{IM}^2(m)}$$ $$\varphi(m)=\arctan\lgroup\frac{I_{IM}(m)}{I_{RE}(m)}\rgroup$$ $$I_{RE}(m)=\frac{2}{N}\sum_{n=0}^{N-1}i(m-n)\cdot \cos\lgroup\frac{2\pi k n}{N}\rgroup$$ $$I_{IM}(m)=\frac{2}{N}\sum_{n=0}^{N-1}i(m-n)\cdot \sin\lgroup\frac{2\pi k n}{N}\rgroup$$ where:
$m$ is the current sample
$n$ is the sample number in a cycle (window)
$k$ is the harmonic number $I_{k}(m)$ is the output sample for harmonic $k$
$i(m-n)$ is the input sample set (stored samples)
$N$ is the number of samples in cycle (window)

Here is my c# code:

private DFTsample[] FourierAnalysis(List<double> inputSamples, List<double> inputTime, int k)
    {
        DFTsample[] dFTsamples = new DFTsample[inputSamples.Count];
    for (int m = 0; m &lt; inputSamples.Count; m++)
    {
        if (inputTime.ElementAt(m) &lt; 0)
        {
            dFTsamples[m] = new DFTsample() { Abs = 0, Angle = 0, Re = 0, Im = 0 };
            continue;
        }

        if(inputTime.ElementAt(m) &gt;= 0)
        {
            dFTsamples[m] = new DFTsample();
            double Re = 0;
            double Im = 0;
            for (int n = 0; n &lt; N; n++)
            {
                Re += 2 / N * inputSamples[m - n] * Math.Cos(2 * Math.PI * k * n / N);
                Im += 2 / N * inputSamples[m - n] * Math.Sin(2 * Math.PI * k * n / N);
            }
            dFTsamples[m].Re = Re;
            dFTsamples[m].Im = Im;
            dFTsamples[m].Abs = Math.Sqrt(Math.Pow(Re, 2) + Math.Pow(Im, 2));
            dFTsamples[m].Angle = Math.Atan2(Re, Im) * 180 / Math.PI; 
        }
    }
    return dFTsamples;
}

My result doesn't seem right, something went wrong:

My result

I'd really appreciate it if you'd let me know how to use the DFT and compute the magnitude and phase angle of the secondary current.

Peter K.
  • 25,714
  • 9
  • 46
  • 91
sakayevas
  • 21
  • 2
  • Your pictures appear to be behind a pay wall. At least I can't see them – Hilmar Dec 10 '22 at 09:08
  • @Hilmar Thank you for noticing. I've changed links, hope they'll work well – sakayevas Dec 11 '22 at 01:14
  • Don't you have the $\sin(\cdot)$ and $\cos(\cdot)$ swapped? $$I_{RE}(m)=\frac{2}{N}\sum_{n=0}^{N-1}i(m-n)\cdot \cos\lgroup\frac{2\pi k n}{N}\rgroup$$ $$I_{IM}(m)=\frac{2}{N}\sum_{n=0}^{N-1}i(m-n)\cdot \sin\lgroup\frac{2\pi k n}{N}\rgroup$$ – robert bristow-johnson Dec 11 '22 at 04:39
  • And you wanna changed $\arctan(\cdot)$ to $\arg{}$. get all four quadrants. – robert bristow-johnson Dec 11 '22 at 04:44
  • If you do this right, and use sliding DFTs for each $X[k]$, you can minimize computations, assuming $N$ is a few K. Now, if you do that, your sin and cos will stay synchronous with the harmonics as $m$ increases. That will change the definition of $\varphi(m)$ into a more lowpass form. Like an envelope. – robert bristow-johnson Dec 11 '22 at 04:53
  • Here is exactly the math. Let the hop $H=1$. Also your window would be rectangular, not a Hann (unless you did something very tricky with TIIR filters). – robert bristow-johnson Dec 11 '22 at 05:13
  • @robertbristow-johnson You're totally right. I've updated the code according to your equations, but it still looks pretty terrible. I need to learn more about sliding DFT. I've just thought I can estimate the magnitude and phase angle using a relatively simple algorithm – sakayevas Dec 11 '22 at 14:34
  • The sliding DFT is a like the moving sum or moving average. each new sample is added to the summation and the old sample that falls offa the edge is subtracted from the summation. – robert bristow-johnson Dec 11 '22 at 20:40

0 Answers0