I have a fully functioning setup using the Diligent impedance analyzer module PmodIA. I don't understand how I am supposed to calibrate the device to measure an unknown impedance. My program below will calculate the correct impedance of any resistor over any frequency range if I first calibrate that resistor and use the gain factor at each frequency step to calculate the impedance. If however I calibrate with one resistor and try and use the calculated gain to measure another I don't get what I expect. I don't think this is a programming problem per se but more a better understanding of the steps is required. I repeated the steps below after changing the output voltage to 200mV p-p and the results were similar. Thanks.

Calibrated, measured, and impedance calculated with 200K resistor from1-11KHz:

1.0KHz A=0.00000000029628510475 R=-16841 I=1065 |Z|=200011.81

2.0KHz A=0.00000001781990432739 R=279 I=-37 |Z|=199390.57

3.0KHz A=0.00000003652457952499 R=136 I=-28 |Z|=197179.28

4.0KHz A=0.00000009405544281005 R=51 I=-15 |Z|=200000.00

5.0KHz A=0.00000020244407653808 R=25 I=-10 |Z|=183453.46

6.0KHz A=0.00000018306301116943 R=25 I=-11 |Z|=200000.00

7.0KHz A=0.00000015103051662445 R=27 I=-16 |Z|=210968.28

8.0KHz A=0.00000035355334281921 R=12 I=-10 |Z|=181071.48

9.0KHz A=0.00000047036037445068 R=7 I=-6 |Z|=230600.23

10.0KHz A=0.00000039043440818786 R=9 I=-8 |Z|=212700.21

11.0KHz A=0.00000028261671066284 R=13 I=-12 |Z|=200000.00

Calibrated, measured, and impedance calculated with 120K resistor from1-11KHz:

1.0KHz A=0.00000000049383964538 R=-16842 I=1065 |Z|=119992.46

2.0KHz A=0.00000002969984054565 R=278 I=-37 |Z|=120057.21

3.0KHz A=0.00000006035161972045 R=136 I=-28 |Z|=119332.17

4.0KHz A=0.00000015873737335205 R=51 I=-15 |Z|=118504.47

5.0KHz A=0.00000034483580589294 R=20 I=-10 |Z|=129688.86

6.0KHz A=0.00000030050773620605 R=25 I=-12 |Z|=120000.00

7.0KHz A=0.00000026552205085754 R=29 I=-16 |Z|=113709.32

8.0KHz A=0.00000058202528953552 R=14 I=-6 |Z|=112801.33

9.0KHz A=0.00000078393406867980 R=7 I=-8 |Z|=120000.00

10.0KHz A=0.00000065072393417358 R=11 I=-8 |Z|=112984.09

11.0KHz A=0.00000047102785110473 R=13 I=-12 |Z|=120000.00

Measured only (120K "unknown") and impedance calculated using gain from first (200K) calibration:

1.0KHz A=0.00000000029628515243 R=-16841 I=1065 |Z|=200011.79

2.0KHz A=0.00000001781990432739 R=278 I=-38 |Z|=200000.00

3.0KHz A=0.00000003652457952499 R=135 I=-28 |Z|=198579.85

4.0KHz A=0.00000009405544281005 R=50 I=-17 |Z|=201322.25

5.0KHz A=0.00000020244405269622 R=21 I=-10 |Z|=212371.53

6.0KHz A=0.00000018306301116943 R=25 I=-13 |Z|=193860.43

7.0KHz A=0.00000015103051662445 R=29 I=-15 |Z|=202794.75

8.0KHz A=0.00000035355331897735 R=15 I=-7 |Z|=170871.54

9.0KHz A=0.00000047036037445068 R=8 I=-8 |Z|=187916.23

10.0KHz A=0.00000039043440818786 R=10 I=-8 |Z|=200000.00

11.0KHz A=0.00000028261672973632 R=13 I=-12 |Z|=199999.98