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:
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 };
continue;
}
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:
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.

