• 0

# impedance analyzer Getting Input Phase Programmatically

## Question

Hello Digilent Forums,

I have an Analog Discovery 2 + Impedance Analyzer board, and have been programmatically manipulating the board via the DWF library.

I am now trying to plot Input Phase (∠) programmatically.

The SDK for Python comes with a `dwfconstants.py`, which houses values of `c_int()`, corresponding with various measurement types.  For example, `DwfAnalogImpedanceImpedance` measurement type corresponds to `c_int(0)`.

I do not see a constant for Input Phase inside `dwfconstants.py`.  Is it possible to get Input Phase?

## Recommended Posts

• 1

You can use the FDwfAnalogImpedanceStatusInput(hdwf, 1, &gain2, &phase2)

The equivalent for the WF IA "input gain" when using IA adapter = gain2 - 1.0

##### Share on other sites
• 1
• I constantly see the prefix `rg` in your programs.  What is the meaning of `rg` prefix in all array namings?
This are so called Hungarian notations originating from physics, to help identifying variable kinds like: rg Array, sz String, i Index, c Count
• Why does the gain term = V_C1 / V_C#?  I would think it's the inverse... gain = output / input = V_C2 / V_C1
This is how the function returns it. You can convert it using 1.0/gain
• Does the formula you listed, M = gain2 - 1.0, come from a simplification of M = (V_C1 - V_C2) / (V_C2 - 0)?
Yes.
• Also, please see the attached image.  It's of input phase.  Note sometimes the points are flipped about 360°. My final question is, do you know why this might be happening?

The phase should be normalized to +/-PI. The next software version will correct this, but you can correct it in you script/application like this:
if phase2.value > math.pi :
phase2.value -= 2.0*math.pi
if phase2.value < -math.pi :
phase2.value += 2.0*math.pi

Thank you for the observation.

##### Share on other sites
• 1

See the following SDK example compared to WF app result:

```dwf.FDwfAnalogImpedanceStatusInput(hdwf, c_int(1), byref(gain2), byref(phase2)) # relative to Channel 1, C1/C#
rgGaC2[i] = 20.0*math.log10(abs(gain2.value-1.0))```

##### Share on other sites
• 0
Posted (edited)

Hi @attila,

Thank you again for your response.  I have several follow-up questions:

• I constantly see the prefix `rg` in your programs.  What is the meaning of `rg` prefix in all array namings?
• Why does the gain term = V_C1 / V_C#?  I would think it's the inverse... gain = output / input = V_C2 / V_C1
• Does the formula you listed, M = gain2 - 1.0, come from a simplification of M = (V_C1 - V_C2) / (V_C2 - 0)?

Also, please see the attached image.  It's of input phase.  Note sometimes the points are flipped about 360°. My final question is, do you know why this might be happening?

Edited by jamesbraza

##### Share on other sites
• 0
Posted (edited)

@attila okay thank you for answering all of my questions, your answers all makes sense!  Also, I was not previously aware of Hungarian notation.

So I implemented the code you suggested above:

On 7/23/2019 at 1:25 AM, attila said:

You﻿ can use the FDwfAnalogImpedanceStatusInput(hdwf, 1, &gain2, &phase2)

The equivalent for the WF IA "input gain" when using IA adapter = gain2 - 1.0

I ran the Impedance Status Input on a load of a 100 kΩ resistor and a 0.1 μF capacitor in series.  I found the formula `gain2 - 1.0` does not match what WaveForms is outputting.

Waveforms output, attached

My output (gain2 - 1.0), attached

These are slightly off, and I am trying to figure out why.  @attila do you know if WaveForms has some compensation done internally that a raw FDwfAnalogImpedanceStatusInput would not output?

Edited by jamesbraza

##### Share on other sites
• 0

Okay @attila, thank you for providing that script!  That cleared me up.

My mistake was thinking that FDwfAnalogImpedanceStatusInput returns a value with units = dB.  It seems the units were actually = V/V.  This is more desirable functionality.

One suggestion: maybe in future Waveforms versions, specify the units of gain returned by FDwfAnalogImpedanceStatusInput in the SDK documentation.

Again: thank you again for answering all of these questions!

##### Share on other sites
• 0

Thank you for the observation.
I've added a note for this in the manual.