 # Phasor Estiamation with DFT algoridhm

Sir i am traying to implement DFT algoridhm for calculation of phasor magnitude and angle, but it is not working. I have generated arrey of sine wave in code itself so without analog input we can check that it is working or not. Please help

a.ino (1.36 KB)

erkngajjar: Sir i am traying to implement DFT algoridhm for calculation of phasor magnitude and angle, but it is not working. I have generated arrey of sine wave in code itself so without analog input we can check that it is working or not. Please help

This is not an Apple site... "Sir i am traying to..."

You are not correctly calculating the entire DFT of the input, just one term.

Since the number of points is a power of two, just use the FFT. http://wiki.openmusiclabs.com/wiki/ArduinoFFT

Your a[] waveform and your sin/cos frequency are different, so you're not going to see anything meaningful, especially as you're not using a sample window function like Blackman or Hanning.

You can only resolve at the same frequency as the signal.

And this is not really a DFT, the transform converts time-domain to frequency-domain keeping all the information, here you are picking out one complex frequency component.

Sir here the frequency of a waveform if 50hz and the frequency of sin/cos terms are also changed to 50 but nothing is happening again.

Also i have tried FFT library but it only gives magnitude with frequency, but my requirement is to take only 50hz signal and calculate its magnitude and phase angle. I want to measure phase angle between voltage and current vector later which is of 50hz.

Also i have prepared a code for taking analog samples withe 3.2kHz sampling frequency so every cycle of sine wave can have 64 samples. Both the codes are attached here with.

Thank you Mr. MarkT, Mr. Jremington and Mr. GarryP for replaying. I am also thankful to all who have tried to help.

3.2khz_sampler.ino (655 Bytes)

a.ino (1.72 KB)

Please post your code in code tags so we can see it easily.

Here is first code which is for phasor estimation..

``````int i=0;
int N=64;
float a;
float t;
float   p_m_1;
float   p_a_1;
float Xr_1 = 0;
float Xi_1 = 0;
float Xr_1_1 = 0;
float Xi_1_1 = 0;
float Phasor_Magnitude_1 = 0;
float Phasor_Angle_1 = 0;
float Phasor_Angle_Degree_1= 0;

void setup() {

Serial.begin(9600);

}

void loop() {

for (i=0; i``````
``` Here is second code which is for taking analog samples at 3.2khz sampling frequency #include int i; unsigned long ts; unsigned long t; int r; boolean sampling_done; void setup() {   // put your setup code here, to run once:   Serial.begin(115200);   i = 0; Timer1.initialize(312); Timer1.attachInterrupt(aquire); ts = micros(); } void loop() {   if (i == 63){     t = micros() - ts;     noInterrupts();     Serial.println("AB");     Serial.print("Time is");     Serial.println((float)t/(float)1000000);     sampling_done = true;     if (sampling_done = true){       i = 0;       interrupts();       ts = micros();     }   } } void aquire(){   r[i] = analogRead(A0);   r[i] = analogRead(A1);   i += 1;   } ```
``` ```
``` MarkT March 1, 2019, 6:26pm #8 Your phasor code is populating a with 325 sin (0.09817 i), then correlating it with sine and cosine of (100π/64) i 100π/64 is very different from 0.9817 100π/64 is also over the Nyquist limit. ```
``` Home Categories FAQ/Guidelines Terms of Service Privacy Policy Powered by Discourse, best viewed with JavaScript enabled ```