To further elaborate on it, since you're using gain apparently (assuming I read your code correctly) we'll have to convert the scope's measurement error to gain error:
Gain = 20 log(V1/V2)
dGain/dV1 = - 20 / V1
dGain/dV2 = 20 / V2
So then:
Gain Error = sqrt( (dGain/dV1 * V1_Error)^2 + (dGain/dV2 * V2_Error)^2 )
Gain Error = sqrt( (20 / V1 * V1_Error)^2 + (20 / V2 * V2_Error)^2 )
Gain Error = 20 * sqrt( (V1_Error / V1)^2 + (V2_Error / V2)^2 )
Next we need to put this into Z_DUT = Z_REF * V1 / (V2 - V1)
If we rework it a bit it should become Z_DUT = Z_REF / (V2 / V1 - 1) = Z_REF / (1 / (V1/V2) - 1)
Then V1/V2 = (|V1| < Phi)/(V2 < 0°) = (|V1| * cos(phi) + j * |V1| * sin(phi)) / |V2| so we need to know the error on |V1|/|V2|.
Since |V1|/|V2| = 10^(Gain/20) the error becomes sqrt((Gain Error * 2^((x-40)/20) * 5^((x-20)/20) * ln(10))
I'll do the rest later.
To further elaborate on it, since you're using gain apparently (assuming I read your code correctly) we'll have to convert the scope's measurement error to gain error:
Gain = 20 log(V1/V2)
dGain/dV1 = - 20 / V1
dGain/dV2 = 20 / V2
So then:
Gain Error = sqrt( (dGain/dV1 * V1_Error)^2 + (dGain/dV2 * V2_Error)^2 )
Gain Error = sqrt( (20 / V1 * V1_Error)^2 + (20 / V2 * V2_Error)^2 )
Gain Error = 20 * sqrt( (V1_Error / V1)^2 + (V2_Error / V2)^2 )
Next we need to put this into Z_DUT = Z_REF * V1 / (V2 - V1)
If we rework it a bit it should become Z_DUT = Z_REF / (V2 / V1 - 1) = Z_REF / (1 / (V1/V2) - 1)
Then V1/V2 = (|V1| < Phi)/(V2 < 0°) = (|V1| * cos(phi) + j * |V1| * sin(phi)) / |V2| so we need to know the error on |V1|/|V2|.
Since |V1|/|V2| = 10^(Gain/20) the error becomes sqrt((Gain Error * 2^((x-40)/20) * 5^((x-20)/20) * ln(10))^2)
I'll do the rest later.
syms REF_Magnitude positive; syms Error_REF_Magnitude positive;
syms REF_Phi real; syms Error_REF_Phi positive;
syms V1_Magnitude positive; syms Error_V1_Magnitude positive;
syms V1_Phi real; syms Error_V1_Phi positive;
syms V2_Magnitude positive; syms Error_V2_Magnitude positive;
%Calculate Gain error based on scope measurements
%This should be a function of the scope which is calculated once.
TrueGain = 20 * log10(V1_Magnitude / V2_Magnitude);
dGain_dV1 = diff(TrueGain, V1_Magnitude);
dGain_dV2 = diff(TrueGain, V2_Magnitude);
TrueGain_Error = sqrt( (dGain_dV1 * Error_V1_Magnitude)^2 + (dGain_dV2 * Error_V2_Magnitude)^2 );
%Lets assume the Gain and Gain_Error are input variables
syms Gain Gain_Error real;
%Calculate V1/V2 error based on Gain error
V1_V2_Magn_ratio = 10 ^ (Gain / 20);
Error_V1_V2_Magn_ratio = abs(diff(V1_V2_Magn_ratio, Gain) * Gain_Error);
V1_V2 = V1_V2_Magn_ratio * exp(1i * V1_Phi);
dV1_V2_dGain = diff(V1_V2, Gain);
dV1_V2_dV1_Phi = diff(V1_V2, V1_Phi);
V1_V2_Error = sqrt(( dV1_V2_dGain * Gain_Error)^2 + (dV1_V2_dV1_Phi * Error_V1_Phi)^2);
%Device Under Test
Z_REF = REF_Magnitude * exp(1i * REF_Phi);
Z_DUT = Z_REF * 1 / (1 / V1_V2 - 1);
Z_DUT_Magnitude = abs(Z_DUT);
Z_DUT_Phase = angle(Z_DUT);
Z_DUT_Magnitude_deltas = [diff(Z_DUT_Magnitude, REF_Magnitude) diff(Z_DUT_Magnitude, REF_Phi) diff(Z_DUT_Magnitude, Gain) diff(Z_DUT_Magnitude, V1_Phi)];
Z_DUT_Magnitude_errors = [Error_REF_Magnitude Error_REF_Phi Gain_Error Error_V1_Phi];
Z_DUT_Phase_deltas = [diff(Z_DUT_Phase, REF_Magnitude) diff(Z_DUT_Phase, REF_Phi) diff(Z_DUT_Phase, Gain) diff(Z_DUT_Phase, V1_Phi)];
Z_DUT_Phase_errors = [Error_REF_Magnitude Error_REF_Phi Gain_Error Error_V1_Phi];
Z_DUT_Magnitude_Error = sqrt(sum((Z_DUT_Magnitude_deltas .* Z_DUT_Magnitude_errors).^2));
Z_DUT_Phase_Error = sqrt(sum((Z_DUT_Phase_deltas .* Z_DUT_Phase_errors).^2));
Z_DUT_Magnitude = REF_Magnitude/abs(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1)
Z_DUT_Phase = angle(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1))
Z_DUT_Magnitude_Error = (Error_REF_Magnitude^2/abs(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^2 - (1/10^(Gain/10)*Error_V1_Phi^2*REF_Magnitude^2*sign(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1)^2*exp(-V1_Phi*2i))/abs(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^4 + (1/10^(Gain/10)*Gain_Error^2*REF_Magnitude^2*sign(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1)^2*exp(-V1_Phi*2i)*log(10)^2)/(400*abs(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^4))^(1/2)
Z_DUT_Phase_Error = ((Gain_Error^2*real(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1))^4*(imag((1/10^(Gain/20)*exp(REF_Phi*1i)*exp(-V1_Phi*1i)*log(10))/(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^2)/(20*real(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1))) - (real((1/10^(Gain/20)*exp(REF_Phi*1i)*exp(-V1_Phi*1i)*log(10))/(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^2)*imag(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1)))/(20*real(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2))^2)/(imag(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2 + real(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2)^2 + (Error_V1_Phi^2*real(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1))^4*(real((1/10^(Gain/20)*exp(REF_Phi*1i)*exp(-V1_Phi*1i))/(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^2)/real(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1)) + (imag((1/10^(Gain/20)*exp(REF_Phi*1i)*exp(-V1_Phi*1i))/(exp(-V1_Phi*1i)/10^(Gain/20) - 1)^2)*imag(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1)))/real(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2)^2)/(imag(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2 + real(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2)^2 + (Error_REF_Phi^2*real(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1))^4*(imag(exp(REF_Phi*1i)/(1/10^(Gain/20)*exp(-V1_Phi*1i) - 1))^2/real(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2 + 1)^2)/(imag(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2 + real(exp(REF_Phi*1i)/(exp(-V1_Phi*1i)/10^(Gain/20) - 1))^2)^2)^(1/2)
Yikes . That's alot of math to check this weekend. Maybe I will need a couple more...
Series = 0.001:0.005:10;
[X, Y] = meshgrid(Series, Series);
Z = 20 .* log10(X./Y);
figure(1);
surf(X, Y, Z, 'edgecolor', 'none');
xlabel('V2 [V]');
ylabel('V1 [V]');
zlabel('Gain [dB]');
title('Voltage Gain - Decibel');
%Scope error = Gain error + Offset error + ADC error
% = +/- 5% value +/- 5 mV +/- 0.25% range
Range1X = X <= 0.1; Range1Y = Y <= 0.1;
Range2X = xor(X <= 1, Range1X); Range2Y = xor(Y <= 1, Range1Y);
Range3X = xor(X <= 10, Range1X | Range2X); Range3Y = xor(Y <= 10, Range1Y | Range2Y);
XError = 0.05 .* X + 0.005 + 0.0025 .* (Range1X .* 0.1 + Range2X .* 1 + Range3X .* 10);
YError = 0.05 .* Y + 0.005 + 0.0025 .* (Range1Y .* 0.1 + Range2Y .* 1 + Range3Y .* 10);
ZError = (20 ./ log(10)) .* sqrt((YError./Y).^2 + (XError./X).^2 );
figure(2);
surf(X, Y, ZError, 'edgecolor','none');
xlabel('V2 [V]');
ylabel('V1 [V]');
zlabel('Gain Error [dB]');
title('Voltage Gain Error - Decibel Error');
Hi Wim,
I have used FRA4 quite a lot on and of since it was released. So yours is a really nice contribution to the tools for Picoscope,
expanding on the usability !
As for Hans in the Previous post I can't get the included measurement application to work. See attached file.
With FRA4 everything works just fine.
As for calibration and improvements. May I suggest to add checkboxes with a number for each loaded file.
(Or some other good way to do it)
- Unchecking will remove them from display
- Simple functions could take Trace 1 and subract from Trace 2 (where Trace 1 could be e.g a zero ohm refererence)
- You could save a combination of data as new data
- You could delete Trace X of not needed anymore etc
Keep up the good work !
)) Kind regards, Per
Added Log first changed to .txt then zipped and changed to .txt, will it post
YES, this worked better !!!
2019-03-07 22:02:35,865 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetDoubleValue: SettingName:StartFrequencyHz DefaultValue:100
2019-03-07 22:02:35,904 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:StartFrequencyHz
2019-03-07 22:02:35,908 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:35,913 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetIntValue: SettingName:ExtraSettlingTimeMs DefaultValue:30
2019-03-07 22:02:35,919 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:ExtraSettlingTimeMs
2019-03-07 22:02:35,926 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:35,934 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetDoubleValue: SettingName:StimulusOffset DefaultValue:0
2019-03-07 22:02:35,941 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:StimulusOffset
2019-03-07 22:02:35,950 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:35,956 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetDoubleValue: SettingName:InitialStimulus DefaultValue:0,1
2019-03-07 22:02:35,963 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:InitialStimulus
2019-03-07 22:02:35,966 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:35,973 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetDoubleValue: SettingName:OutputDCOffset DefaultValue:0
2019-03-07 22:02:35,978 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:OutputDCOffset
2019-03-07 22:02:35,986 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:35,995 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetStringValue: SettingName:OutputChannel DefaultValue:B
2019-03-07 22:02:36,001 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:OutputChannel
2019-03-07 22:02:36,006 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:36,010 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetStringValue: SettingName:OutputAttenuation DefaultValue:X1
2019-03-07 22:02:36,016 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:OutputAttenuation
2019-03-07 22:02:36,023 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
2019-03-07 22:02:36,030 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsManager - GetStringValue: SettingName:OutputCoupling DefaultValue:DC
2019-03-07 22:02:36,039 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetValue fileType:Settings section:Picoscope settingName:OutputCoupling
2019-03-07 22:02:36,046 [1] DEBUG WHConsult.Utils.Settings.IniFiles.IniSettingsController - GetInifile fileType:Settings
This should do it I hope, booth from 1008 and 1009. Just Zipped this time
Running it from the C-drive didn't make a difference.
)) Per