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 < inputSamples.Count; m++)
            if (inputTime.ElementAt(m) < 0)
                dFTsamples[m] = new DFTsample() { Abs = 0, Angle = 0, Re = 0, Im = 0 };

            if(inputTime.ElementAt(m) >= 0)
                dFTsamples[m] = new DFTsample();
                double Re = 0;
                double Im = 0;
                for (int n = 0; n < 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.

  • $\begingroup$ Your pictures appear to be behind a pay wall. At least I can't see them $\endgroup$
    – Hilmar
    Dec 10, 2022 at 9:08
  • $\begingroup$ @Hilmar Thank you for noticing. I've changed links, hope they'll work well $\endgroup$
    – sakayevas
    Dec 11, 2022 at 1:14
  • $\begingroup$ 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$$ $\endgroup$ Dec 11, 2022 at 4:39
  • $\begingroup$ And you wanna changed $\arctan(\cdot)$ to $\arg\{\}$. get all four quadrants. $\endgroup$ Dec 11, 2022 at 4:44
  • $\begingroup$ 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. $\endgroup$ Dec 11, 2022 at 4:53


Your Answer

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

Browse other questions tagged or ask your own question.