Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Has anyone implemented a phase measurement yet? #26

Open
miemiemie666 opened this issue Mar 15, 2023 · 3 comments
Open

Has anyone implemented a phase measurement yet? #26

miemiemie666 opened this issue Mar 15, 2023 · 3 comments

Comments

@miemiemie666
Copy link

First of all, thank the author for sharing.
Has anyone figured out the phase? The true resistance and reactance values cannot be calculated without calculating the phase.
I tried several methods, but none of them worked out the phase.

@miemiemie666
Copy link
Author

bool AD5933::calibrate(double gain[], int phase[], int ref, int n) {
// We need arrays to hold the real and imaginary values temporarily
int *real = new int[n];
int *imag = new int[n];

// Perform the frequency sweep
if (!frequencySweep(real, imag, n)) {
    delete [] real;
    delete [] imag;
    return false;
}

// For each point in the sweep, calculate the gain factor and phase
for (int i = 0; i < n; i++) {
    gain[i] = (double)(1.0/ref)/sqrt(pow(real[i], 2) + pow(imag[i], 2));
    // TODO: phase
    ///////////////////////mie 20230305
    //Serial.print("real[i] = ");
    //Serial.println(real[i]);
    //Serial.print("imag[i] = ");
    //Serial.println(imag[i]);
    phase[i] = atan2(imag[i], real[i])*180/PI;
    //Serial.print("phase[i] = ");
    //Serial.println(phase[i]);
    ////////////////////////////////////
}

delete [] real;
delete [] imag;
return true;

}

@miemiemie666
Copy link
Author

The problem has been solved, just modify the library file as above, but int will cause errors, you need to further modify the int phase in the library to float phase type

@eliecampa
Copy link

Dear all,
If someone is interested I wrote an example of using the AD5933 with a kind of command line using my own library (called Generic_MEAS) so you can easily add new command with int, float or long parameters. My example has a command called "FREQ, frequency (float)" so you can select the initial frequency and do the calibration (using some #define statement in the header file. After this FREQ command you can enter a ACQ command (without parameters) and got the results with phase correction based on calibration. The original has been modified an use a float as a frequency parameter and use mainly one frequency with a null frequency increment so the gain[I] is the mean gain and only valid for i=0. You can easily change the behavior of the software, for example the command FREQ can handle the start frequency, the increment frequency and the number of increments.
Let me know if you want to get the code.
Raymond

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants