Git Product home page Git Product logo

Comments (4)

miemiemie666 avatar miemiemie666 commented on August 22, 2024

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;

}

from arduino-ad5933.

miemiemie666 avatar miemiemie666 commented on August 22, 2024

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

from arduino-ad5933.

eliecampa avatar eliecampa commented on August 22, 2024

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

from arduino-ad5933.

WheeSci avatar WheeSci commented on August 22, 2024

To get around the problem with the phase being defined as an int, I added two new floats and converted the phase to degrees.
Also, why delete the arrays once you have them? We want to use the phase when measuring unknown impedances.
code:
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];
float faze, R;

// 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));
	R = float(imag[i])/real[i];
	faze = atan(R);     // page 19 of datasheet
	phase[i] = degrees(faze);
    // TODO: phase
}

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

from arduino-ad5933.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.