Skip to content

Commit

Permalink
Rhs2116 step size algorithm now accounts for requested amplitude
Browse files Browse the repository at this point in the history
- When calculating the error to find the optimum step size, the algorithm now utilizes the requested amplitude so that in the case when no stimuli are present, the error is correctly modified for each step size and the appropriate size is chosen for the requested amplitude
  • Loading branch information
bparks13 committed Dec 23, 2024
1 parent 3c6702b commit 3ee5b2c
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<PackageLicenseFile>LICENSE</PackageLicenseFile>
<UseArtifactsOutput>true</UseArtifactsOutput>
<PackageIcon>icon.png</PackageIcon>
<VersionPrefix>0.4.2</VersionPrefix>
<VersionPrefix>0.4.3</VersionPrefix>
<VersionSuffix></VersionSuffix>
<LangVersion>10.0</LangVersion>
<Features>strict</Features>
Expand Down
2 changes: 1 addition & 1 deletion OpenEphys.Onix1.Design/Rhs2116StimulusSequenceDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1078,7 +1078,7 @@ private bool UpdateStepSizeFromAmplitude(double amplitude)
return true;
}

StepSize = Rhs2116StimulusSequence.GetStepSizeWithMinError(validStepSizes, Sequence.Stimuli, Sequence.CurrentStepSize);
StepSize = Rhs2116StimulusSequence.GetStepSizeWithMinError(validStepSizes, Sequence.Stimuli, amplitude, Sequence.CurrentStepSize);
textBoxStepSize.Text = GetStepSizeStringuA(StepSize);

return true;
Expand Down
8 changes: 7 additions & 1 deletion OpenEphys.Onix1/Rhs2116StimulusSequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ private static void AddOrInsert(ref Dictionary<uint, BitArray> table, int channe
}
}

internal static Rhs2116StepSize GetStepSizeWithMinError(IEnumerable<Rhs2116StepSize> stepSizes, Rhs2116Stimulus[] stimuli, Rhs2116StepSize currentStepSize)
internal static Rhs2116StepSize GetStepSizeWithMinError(IEnumerable<Rhs2116StepSize> stepSizes, Rhs2116Stimulus[] stimuli, double requestedAmplitude, Rhs2116StepSize currentStepSize)
{
var numberOfStepSizes = stepSizes.Count();
var maxError = new List<double>(numberOfStepSizes);
Expand Down Expand Up @@ -263,6 +263,12 @@ static double CalculateError(double amplitude, double stepSizeuA)

maxError[s] = Math.Max(maxError[s], Math.Max(anodicError, cathodicError));
}

var requestedError = requestedAmplitude < stepSizesuA[s] || requestedAmplitude > stepSizesuA[s] * 255 ?
double.PositiveInfinity :
CalculateError(requestedAmplitude, stepSizesuA[s]);

maxError[s] = Math.Max(maxError[s], requestedError);
}

if (maxError.Distinct().Count() == 1)
Expand Down

0 comments on commit 3ee5b2c

Please sign in to comment.