File MIES_WaveBuilder.ipf

WB Stimulus set creation

Constants for WB_GetControlWithDeltaIdx

The numeric values are row indizes in the waves returned by WB_GetControlWithDeltaWvs().

static const double WB_IDX_DURATION = 0
static const double WB_IDX_AMPLITUDE = 2
static const double WB_IDX_OFFSET = 4
static const double WB_IDX_SIN_CHIRP_SAW_FREQUENCY = 6
static const double WB_IDX_TRAIN_PULSE_DURATION = 8
static const double WB_IDX_PSC_EXP_RISE_TIME = 10
static const double WB_IDX_PSC_EXP_DECAY_TIME_1_2 = 12
static const double WB_IDX_PSC_EXP_DECAY_TIME_2_2 = 14
static const double WB_IDX_PSC_RATIO_DECAY_TIMES = 16
static const double WB_IDX_LOW_PASS_FILTER_CUT_OFF = 20
static const double WB_IDX_HIGH_PASS_FILTER_CUT_OFF = 22
static const double WB_IDX_CHIRP_END_FREQUENCY = 24
static const double WB_IDX_NOISE_FILTER_ORDER = 26
static const double WB_IDX_PT_FIRST_MIXED_FREQUENCY = 28
static const double WB_IDX_PT_LAST_MIXED_FREQUENCY = 30
static const double WB_IDX_NUMBER_OF_PULSES = 45
static const double WB_IDX_ITI = 99

Functions that build wave types

static variable WB_SquareSegment(SegmentParameters *pa)
static variable WB_RampSegment(SegmentParameters *pa)
variable WB_IsValidCutoffFrequency(variable freq)

Check if the given frequency is a valid setting for the noise epoch.

variable WB_IsValidScaledCutoffFrequency(variable freq)

Check if the given frequency is a valid setting for the noise epoch.

Requires a scaled frequency as input, see DisplayHelpTopic "FilterIIR"

static variable WB_NoiseSegment(SegmentParameters *pa)
static std::tuple<variable, variable> WB_TrigGetBoundsForInflectionPoints(SegmentParameters *pa, variable offset)
static variable WB_CheckTrigonometricSegmentParameters(SegmentParameters *pa)
static std::tuple<WaveDouble, WaveDouble> WB_TrigCalculateInflectionPoints(SegmentParameters *pa, variable k0, variable k1, variable k2, variable k3)

Calculate the x values where the trigonometric epoch has inflection points.

For zero offset, the inflection points coincide with the zero crossings/roots. In case nothing can be calculated the inflectionPoints wave has one NaN entry.

The formula without chirp can be solved for \(f(x) == 0\) as:

\[\begin{split}f(x) &= a \cdot \sin(k_0 \cdot x) \\ k_0 \cdot x &= c \cdot \pi \\ x &= \frac{c \cdot \pi}{k_0}\end{split}\]

And for cosine:

\[x = \frac{(c + \frac{1}{2}) \cdot \pi}{k_0}\]

With chirp and sine:

\[\begin{split}f(x) &= a \cdot \sin(k_2 \cdot e^{k_1 \cdot x}- k_3) \\ k_2 \cdot e^{k_1 \cdot x} - k_3 &= c \cdot \pi \\ e^{k_1 \cdot x} &= \frac{c \cdot \pi + k_3}{k_2} \\ k_1 \cdot x &= \ln\left(\frac{c \cdot \pi + k_3}{k_2}\right) \\ x &= \frac{1}{k_1} \cdot \ln\left(\frac{c \cdot \pi + k_3}{k_2}\right)\end{split}\]

And analogous for cosine:

\[x = \frac{1}{k_1} \cdot \ln\left(\frac{(c + \frac{1}{2}) \cdot \pi + k_3}{k_2}\right)\]

static std::tuple<WaveDouble, WaveDouble> WB_TrigSegment(SegmentParameters *pa)
static variable WB_SawToothSegment(SegmentParameters *pa)
static variable WB_CreatePulse(wave wv, variable pulseType, variable amplitude, variable first, variable last)
string WB_ToEpochTypeString(variable epochType)

Convert the numeric epoch type to a stringified version.

variable WB_ToEpochType(string epochTypeStr)

Convert the stringified epoch type to a numerical one.

string WB_GetWaveNoteEntry(string text, variable entryType, string key = defaultValue, variable sweep = defaultValue, variable epoch = defaultValue)

Query stimset wave note entries.

Format of the wave note:

The wave note version is tracked through STIMSET_NOTE_VERSION

Lines separated by \r (carriage return) in UTF-8 encoding. The lines hold Igor Pro style key value pairs in the form key = value; where value can contain any character except ; (semicolon).

Four types of entries can be distinguished:

  • Version: In the very first line (line 1)

  • Sweep specific entries have an epoch of nan: (line 2, 7)

  • Epoch specific: (line 3 - 6)

  • Stimset specific: (line 12)

Additional infos on selected entries: - ITI is in seconds - Flipping is done on a per stimset basis - Durations are in stimset build ms - Pulse Train Pulses are absolute pulse starting times in epoch build ms - Pulse To Pulse Length is in stimset build ms - Function params (encoded) contains the analysis function parameters. The values have the format described at GetWaveBuilderWaveTextParam(). - Inflection Points are in epoch build ms. For offset zero these coincide with the roots.

Added with version 10:
  • start and end indices for pulses in pulse trains (end index is part of the pulse)

  • length of each segment

  • inflection point positions (left side index)


 1Version = 2;
 2Sweep = 0;Epoch = nan;ITI = 1;
 3Sweep = 0;Epoch = 0;Type = Square pulse;Duration = 500;Amplitude = 0;
 4Sweep = 0;Epoch = 1;Type = Ramp;Duration = 150;Amplitude = 1;Offset = 0;
 5Sweep = 0;Epoch = 2;Type = Square pulse;Duration = 300;Amplitude = 0;
 6Sweep = 0;Epoch = 3;Type = Pulse Train;Duration = 960.005;Amplitude = 1;Offset = 0;Pulse Type = Square;Frequency = 20;Pulse To Pulse Length = 50;Pulse duration = 10;Number of pulses = 20;Mixed frequency = False;First mixed frequency = 0;Last mixed frequency = 0;Poisson distribution = False;Random seed = 0.963638;Pulse Train Pulses = 0,50,100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,;Definition mode = Duration;
 7Sweep = 1;Epoch = nan;ITI = 2;
 8Sweep = 1;Epoch = 0;Type = Square pulse;Duration = 500;Amplitude = 0;
 9Sweep = 1;Epoch = 1;Type = Ramp;Duration = 150;Amplitude = 1;Offset = 0;
10Sweep = 1;Epoch = 2;Type = Square pulse;Duration = 300;Amplitude = 0;
11Sweep = 1;Epoch = 3;Type = Pulse Train;Duration = 960.005;Amplitude = 1;Offset = 0;Pulse Type = Square;Frequency = 20;Pulse To Pulse Length = 50;Pulse duration = 10;Number of pulses = 20;Mixed frequency = False;First mixed frequency = 0;Last mixed frequency = 0;Poisson distribution = False;Random seed = 0.963638;Pulse Train Pulses = 0,50,100,150,200,250,300,350,400,450,500,550,600,650,700,750,800,850,900,950,;Definition mode = Duration;
12Stimset;Sweep Count = 2;Epoch Count = 4;Pre DAQ = ;Mid Sweep = ;Post Sweep = ;Post Set = ;Post DAQ = ;Pre Sweep = ;Generic = PSQ_Ramp;Pre Set = ;Function params (encoded)= NumberOfSpikes:variable=5,Elements:string=%20%3B%2C;Flip = 0;Random Seed = 0.963638;Wavebuilder Error = 0;Checksum = 65446509;

  • text – stimulus set wave note

  • entryType – one of StimsetWaveNoteEntryTypes

  • key – [optional] named entry to return, not required for VERSION_ENTRY

  • sweep – [optional] number of the sweep

  • epoch – [optional] number of the epoch

variable WB_GetWaveNoteEntryAsNumber(string text, variable entryType, string key = defaultValue, variable sweep = defaultValue, variable epoch = defaultValue)
static std::tuple<WaveDouble, WaveDouble, WaveDouble, variable> WB_PulseTrainSegment(SegmentParameters *pa, variable mode)
static variable WB_PSCSegment(SegmentParameters *pa)
static variable WB_CustomWaveSegment(SegmentParameters *pa, wave customWave)
static wave WB_FillWaveFromFormula(string formula, variable channelType, variable sweep)

Create a wave segment as combination of existing stim sets.


wave WB_CreateAndGetStimSet(string setName)

Return the stim set wave and create it permanently in the datafolder hierarchy.


stimset wave ref or an invalid wave ref

string WB_GetParameterWaveName(string stimset, variable type, variable nwbFormat = defaultValue)

Return the name of one of the three stimset parameter waves.

  • stimset – name of stimset

  • type – indicate parameter wave (WP, WPT, or SegWvType), see ParameterWaveTypes

  • nwbFormat – [optional, defaults to false] nwbFormat has type as suffix


name as string

wave WB_GetWaveParamForSet(string setName)

Return the wave WP for a stim set.


valid/invalid wave reference

wave WB_GetWaveTextParamForSet(string setName)

Return the wave WPT for a stim set.


valid/invalid wave reference

wave WB_GetSegWvTypeForSet(string setName)

Return the wave SegmentWvType for a stim set.


valid/invalid wave reference

static variable WB_StimsetNeedsUpdate(string setName)

Check if stimset needs to be created.

Stimset is recreated

  • if one of the parameter waves was modified

  • the custom wave that was used to build the stimset was modified


1 if stimset needs to be recreated, 0 otherwise

static variable WB_StimsetHasLatestNoteVersion(string setName)

Check if the stimset wave note has the latest version.

static variable WB_ParameterWvsNewerThanStim(string setName)

Check if parameter waves’ are newer than the saved stimset.


setName – string containing name of stimset


1 if Parameter waves were modified, 0 otherwise

variable WB_GetStimsetChecksum(wave stimset, string setName, variable dataAcqOrTP)

Return a checksum of the stimsets and its parameter waves.

Uses the entry from the stimset wave note if available.

static variable WB_CalculateStimsetChecksum(wave stimset, string setName)

Calculcate the checksum of the stimsets and its parameter waves.

variable WB_GetLastModStimSet(string setName)

Get modification date of saved stimset wave.


setName – string containing name of stimset


date of last modification as double precision Igor date/time value

wave WB_GetStimSetForWaveBuilder()

Return the current stimset wave for the wavebuilder.

static wave WB_GetStimSet(string setName = defaultValue)

Return the stim set wave.

As opposed to WB_CreateAndGetStimSet this function returns a free wave only


setName – [optional, defaults to WaveBuilderPanel GUI settings] name of the set


free wave with the stim set, invalid wave ref if the WP* parameter waves could not be found.

static wave WB_GetControlWithDeltaIdx()

Return a free wave with indizes referencing the values with delta values.

Indizes are into WP

and reference the entry with the value itself.

Constants are defined at


static wave WB_GetControlWithDeltaWvs(wave WP, wave SegWvType)

Return a free wave with wave references where the values with delta reside in.

variable WB_GetDeltaDimLabel(wave wv, variable index, DeltaControlNames *s)

Return the WP/WPT/SegWvType dimension labels for the related delta controls given the index into WP of the value itself.


0 on success, 1 otherwise

static variable WB_AddDelta(string setName, wave WP, wave WPOrig, WaveText WPT, wave SegWvType, wave SegWvTypeOrig, variable sweep, variable numSweeps)

Add delta to appropriate parameters.

Relies on alternating sequence of parameter and delta’s in parameter waves as documented in WB_MakeWaveBuilderWave().

  • setName – name of the stimset

  • WP – wavebuilder parameter wave (temporary copy)

  • WPOrig – wavebuilder parameter wave (original)

  • WPT – wavebuilder text parameter wave

  • SegWvType – segment parameter wave (temporary copy)

  • SegWvTypeOrig – segment parameter wave (original)

  • sweep – sweep number

  • numSweeps – total number of sweeps

static variable WB_CalculateParameterWithDelta(variable operation, variable *value, variable *delta, variable dme, string ldelta, variable originalValue, variable sweep, variable numSweeps, string setName, string paramName)

Calculate the new value of a parameter taking into account the delta operation.

  • operation[in] delta operation, one of WaveBuilderDeltaOperationModes

  • value[inout] parameter value (might be incremented by former delta application calls)

  • delta[inout] delta value

  • dme[in] delta multiplier or exponent

  • ldelta[in] explicit list of delta values

  • originalValue[in] unmodified parameter value

  • sweep[in] sweep number

  • numSweeps[in] number of sweeps

  • setName[in] name of the stimulus set (used for error reporting)

  • paramName[in] name of the parameter (used for error reporting)

static wave WB_MakeWaveBuilderWave(wave WP, WaveText WPT, wave SegWvType, variable stepCount, variable numEpochs, variable channelType, variable updateEpochIDWave, string stimset = defaultValue)
static variable WB_UpdateEpochID(variable epochIndex, variable epochDuration, variable accumulatedDuration)

Update the accumulated stimset duration for the mouse selection via GetEpochID()

  • epochIndex[in] index of the epoch

  • epochDuration[in] duration of the current segment

  • accumulatedDuration[in] accumulated duration in the stimset for the first step

variable WB_GetITI(wave stimset, variable sweep)

Query the stimset wave note for the sweep/set specific ITI.

variable WB_UpgradeCustomWaveInWPT(WaveText wv, variable channelType, variable i)

Try to recover a custom wave when in the old format (aka with only a wave name and not a full path)

  • wv – WPT wave reference

  • channelType – AD/DA or TTL channel type

  • i – index of epoch containing custom wave

static variable WB_ApplyOffset(SegmentParameters *pa)
static variable WB_InitializeSeed(wave WP, wave SegWvType, variable epoch, variable type, variable stepCount)

Initialize the seed value of the pseudo random number generator.

variable WB_UpdateEpochCombineList(WaveText epochCombineList, variable channelType)

Update the shorthand/stimset wave for the epoch type Combine

The rows are sorted by creationDate of the WP/stimset wave to try to keep the shorthands constants even when new stimsets are added.

static string WB_GenerateUniqueLabel(variable idx)

Generate a unique textual representation of an index.

Returns the alphabet for 1-26, and then A1, B1, …, Z1000

variable WB_ParseCombinerFormula(variable channelType, string formula, variable sweep, FormulaProperties *fp)

Parse the formula from the epoch type Combine

  • channelType[in] One of CHANNEL_TYPE_DA or CHANNEL_TYPE_TTL

  • formula[in] math formula to execute, all operators which Igor can grok are allowed

  • sweep[in] current sweep (aka step)

  • fp[out] parsed formula structure, with shorthands replaced by stimsets, empty on parse error, ready to be executed by WB_FillWaveFromFormula()


0 on success, 1 on parse errors (currently not many are found)

variable WB_FormulaSwitchToStimset(variable channelType, string formula, FormulaProperties *fp)

Replace shorthands with the real stimset names suffixed with ?

static variable WB_PrepareFormulaForExecute(FormulaProperties *fp, variable sweep)

Add wave ranges to every stimset (location marked by ?) and add a left hand side to the formula.

string WB_FormulaSwitchToShorthand(variable channelType, string formula)

Replace all stimsets suffixed with ? by their shorthands.

wave WB_CustomWavesFromStimSet(string stimsetList)

Get all custom waves that are used by the supplied stimset.

used by WaveBuilder and NeuroDataWithoutBorders


a wave of wave references

wave WB_CustomWavesPathFromStimSet(string stimsetList)

Get all custom waves that are used by the supplied stimset.


a text wave with paths to custom waves.

static wave WB_UpgradeCustomWaves(string stimsetList)

Try to upgrade all epochs with custom waves from the stimsetlist.

you can only use this function if the custom wave is present in the current experiment. do not try to upgrade when loading stimsets. The custom waves have to be loaded first.


a text wave with paths to custom waves.

static string WB_StimsetChildren(string stimset = defaultValue)

Search for stimsets in formula epochs.

a stimset (parent) can depend on other stimsets (child)


non-unique list of all (child) stimsets

variable WB_StimsetFamilyNames(string *knownNames, string *parent = defaultValue)

Get children of current parent stimset.

  • parent – [optional: defaults to current WB panel] specify parent stimset.

  • knownNames[out] unique list of stimsets


number of parents stimsets that were moved to child stimsets

string WB_StimsetRecursion(string parent = defaultValue, string knownStimsets = defaultValue)

Recursively descents into parent stimsets.

You can not recurse into a stimset that depends on itself.


list of stimsets that derive from the input stimset

string WB_StimsetRecursionForList(string stimsetQueue)

Recursively descents into parent stimsets.


stimsetQueue – can be a list of stimsets (separated by ;) or a simple string


list of stimsets that derive from the input stimsets

variable WB_ParameterWavesExist(string stimset)

check if parameter waves exist


1 if parameter waves exist, 0 otherwise

variable WB_StimsetExists(string stimset)

check if (custom) stimset exists


1 if stimset wave was found, 0 otherwise

variable WB_KillParameterWaves(string stimset)

Kill Parameter waves for stimset.

variable WB_KillStimset(string stimset)

Kill (custom) stimset.

variable WB_StimsetIsFromThirdParty(string stimset)

Determine if the stimset is third party or from MIES.

Third party stimsets don’t have all parameter waves


true if from third party, false otherwise

variable WB_AddAnalysisParameterIntoWPT(WaveText WPT, string name, variable var = defaultValue, string str = defaultValue, wave wv = defaultValue)

Internal use only.

variable WB_SetAnalysisFunctionGeneric(variable stimulusType, string analysisFunction, WaveText WPT)

Internal use only.

static variable WB_SaveStimSetParameterWaves(string setName, wave SegWvType, wave WP, WaveText WPT, variable stimulusType)
string WB_SaveStimSet(string baseName, variable stimulusType, wave SegWvType, wave WP, WaveText WPT, variable setNumber, variable saveAsBuiltin)
wave WB_GetEpochLengths(string setName)

Return a wave with the length of all epochs.


wave with epoch lengths or an invalid wave reference in case we don’t have any epochs

static variable WB_CheckForEmptyEpochs(string setname)
static string WB_AssembleSetName(string basename, variable stimulusType, variable setNumber, string suffix = defaultValue, variable lengthLimit = defaultValue)

Return the name of a stimulus set build up from the passed parts.


complete stimulus set name or an empty string in case the basename is too long

variable WB_SplitStimsetName(string setName, string *setPrefix, variable *stimulusType, variable *setNumber)

Split the full setname into its three parts: prefix, stimulusType and set number.

Counterpart to WB_AssembleSetName()

variable WB_MakeStimsetThirdParty(string setName)

Changes an existing stimset to a third party stimset.

variable WB_UpdateChangedStimsets(string device = defaultValue, variable stimulusType = defaultValue)

Propagate added/removed stimsets to DA_Ephys panels and our epoch combine list.

static std::tuple<variable, variable, variable, variable> WB_GetIndicesForSignalDuration(variable startTime, variable duration, variable sampleInterval)

Returns the start and end indices for a wave given a FP duration. The length within the wave is calculated in a way, that at least the points to fill duration are included. So the effective duration never gets shortened.

  • startTime – floating point start time of the range

  • duration – floating point duration time

  • sampleInterval – floating point sample interval

Return values:
  • startIndex – index where the range starts

  • endIndex – index where the range ends, this is inclusive for e.g. data[startIndex, endIndex] = amplitude

  • startOffset – floating point error of start in wave regarding startTime argument: >= -0.5 * sampleInterval && < 0.5 * sampleInterval

  • durationError – floating point error of duration in wave regarding duration argument: >= 0 && < sampleInterval


static const double PULSE_TRAIN_MODE_DUR = 0x01
static const double PULSE_TRAIN_MODE_PULSE = 0x02
static const double WB_PULSE_TRAIN_TYPE_SQUARE = 0
static const double WB_PULSE_TRAIN_TYPE_TRIANGLE = 1
static const double WB_TRIG_TYPE_SIN = 0
static const double WB_TRIG_TYPE_COS = 1
static const double DELTA_OPERATION_EXPLICIT = 6
struct SegmentParameters

Public Members

variable duration
variable deltaDur
variable amplitude
variable deltaAmp
variable offset
variable frequency
variable deltaFreq
variable pulseDuration
variable tauRise
variable tauDecay1
variable tauDecay2
variable tauDecay2Weight
variable lowPassCutOff
variable highPassCutOff
variable filterOrder
variable endFrequency
variable numberOfPulses
variable poisson
variable logChirp
variable randomSeed
variable trigFuncType
variable noiseType
variable noiseGenMode
variable noiseGenModePTMixedFreq
variable buildResolution
variable pulseType
variable mixedFreq
variable mixedFreqShuffle
variable firstFreq
variable lastFreq