SpHr_ActivityAlpha [ /AT or /OT /ACC /DF]  Wts =  { Wts [,  minValue, maxValue ] } [, moreWts =  { moreWts [,  minValue, maxValue ] } ]


Generates an 'alpha' color-mask image to display atop images previously generated images using the SpHr_ActivityAtTime operation (see this operation's /AT flag) or the SpHr_ActivityOverTime operation (see this operation's /OT flag).

A Color table that fades from transparent to white (or black) may be generated using the operation: SpHr_ColorTable/Dest=AlphaCT/A={0,1} "White" // (or "Black")

A Color table that fades from transparent to any other r,g,b color may be generated using the operation: SpHr_ColorTable/Dest=AlphaCT/M={r,g,b}/A={0,1} "Solid"


keywords

Wts =  { Wts [,  minValue, maxValue ] }

    Weights used to generate alpha values. Typical values are average binaural levels (ABLs) or envelope weights obtained using the SpHr_CrossingCarrierCues or SpHr_CrossingEnvelopeCues operations.

    minValue is the minimum value used to normalize Wts, such that minValue is set to 0.0.

    maxValue is the maximum value used to normalize Wts, such that maxValue is set to 1.0.

    If minValue and maxValue are omitted, the minimum value found in Wts is set to 0.0 and the maximum value found in Wts is set to 1.0.


moreWts =  { moreWts [,  minValue, maxValue ] }

    Optional weights. Values are normalized as described above for the Wts keyword. Both sets of values are then averaged.


Flags

/AT = { ATimageReference [, AlphaMaskSpec] }

    Generates an alpha color mask image that may be overlain atop images obtained using the SpHr_ActivityAtTime operation with /HM and/or /M flags.

    ATimageReference  - Reference to source image generated by the SpHr_ActivityAtTime operation using the /HM or /M flag.

    AlphaMaskSpec - Destination specification for the generated 'alpha' image. If AlphaMaskSpec is omitted, an image named ImageMask is created. When the /AT flag is used, the name of the generated image is always set to the string variable S_ATflagName.

    ModifyImage $NameOfWave($S_ATflagName) ctab= {1,0,AlphaCT,0}


or


/OT = { OTdatafolderSpec, CFs [, AlphaMaskPrefixString] }

    Generates alpha color-mask images that may be overlain atop images obtained using the SpHr_ActivityOverTime operation.

    OTdatafolderSpec  - reference to the datafolder where waves were previously written when calling the SpHr_ActivityOverTime operation.

    CFs - Wave reference to CFs wave, typically generated using the SpHr_FilterCenterFreqs operation.

    AlphaMaskPrefixString - prefix added to the beginning of new waves generated in the existing OTdatafolderSpec datafolder. If the string AlphaMaskPrefixString is omitted, the string "ImageMask" is used. When the /OT flag is used, the prefix used is always set to the string variable S_OTflagPrefix.

    To avoid generating excess waves, it is recommended that the datafolders created by this operation are killed between calls, after closing all windows using included waves.

        Existing waves are expected to have names where an integer frequency is found between two underscore characters, followed by the "Hz" string, e.g.,  '_100_Hz'. This frequency is extracted and the CFs wave is used to find the column index into wave Wts and, optionally, wave moreWts. Values normalized between 0 and 1 are then used to generate each frequency-specific alpha color-mask image.

    For example, if a wave named HM_100_Hz_Left was previously generated in a datafolder named HM, this operation would create a new wave named ColorMaskHM_100_Hz_Left if "ColorMask" was passed for AlphaMaskPrefixString.

    ModifyImage $NameOfWave($S_OTflagPrefix+"HM_100_Hz_Left ") ctab= {1,0,AlphaCT,0}

    Similarly, if a wave named HM_100_Hz_Left was previously generated in a datafolder named HM and AlphaMaskPrefixString was omitted, a new wave named ImageMaskHM_100_Hz_Left would be created.

    ModifyImage $NameOfWave($S_OTflagPrefix+"HM_100_Hz_Left ") ctab= {1,0,AlphaCT,0}

    In all cases, no new wave would be generated if an integer frequency of 100 could not be found in the CFs wave.


/ACC = { acc }

    acc is a wave reference to activity accruals generated using the /ACC flag with the SpHr_ActivityAtTime and/or SpHr_ActivityOverTime operations. Values passed using the Wts and moreWts keywords are multiplied with ACC values. The /ACC flag should be used if the SpHr_ActivityAtTime operation was used without the /Avg or /Stat flag (together with this operation's /AT flag). In contrast, the /ACC flag should be omitted if the SpHr_ActivityAtTime operation was used with the /Avg or /Stat flag or if the SpHr_ActivityOverTime operation was used (together with this operation's /OT flag).


/DF = dfRef    dfRef is an optional datafolder reference. Destination waves and variables are written to this already existing datafolder, overriding any datafolder specified by the destination waves. Waves are written to the current datafolder if not specified here or by the destination waves. 


Examples using /OT flag and then the /AT flag

Function SpHr_ActivityAlphaOT_Example()

    variable useEnvelopeCues = 0 // carrier=0, envelope=1

    DFREF saveDFR = GetDataFolderDFR()

    NewDataFolder/O/S ActivityOverTime

    // Test Signal, ITD= 0.1 (ms), ILD= 3 (dB), Independence  0.1 (Index)

    SpHr_SignalBinaural/sec=1/Ramp=1/dB=70/HP=50/Sp=1/Ind=0.1/ITD={0.1}/ILD={3} 48000, NoiseBurst

    SpHr_SignalAM/Type={"Cos"}/F=5/D=100/A=1/Ramp={100} NoiseBurst

    // Filter bank

    variable lowHz = 100, highHz = 8000, carrierHighHz = 2000

    SpHr_FilterCenterFreqs/R/Type=(2) lowHz, highHz, 32, CFs

    SpHr_FilterBankBiquadCoefs/W=FilterWidths 48000, CFs, coefBank

    SpHr_FilterBankBiquad /RMS/Dest=FilterBanks CFs, coefBank, NoiseBurst

    KillWaves/Z coefBank, NoiseBurst

    variable Frequency

    // Cues: IPD, ILDs, Xs, and XNs

    if(useEnvelopeCues)

        Frequency = 2500

        SpHr_CrossingEnvelopeCues/IPD=IPDs/ILD=ILDs/ABL=ABLs/X=Xs/XN=Ns CFs, FilterBanks

    else

        Frequency = 300

        SpHr_CrossingCarrierCues/F={carrierHighHz}/IPD=IPDs/ILD=ILDs/ABL=ABLs/X=Xs/XN=Ns/AWts={20,20,EnvWts} CFs, FilterBanks

    endif

    KillWaves/Z FilterBanks

    // Model left hemisphere IPD and ILD Neurons

    variable numNeurons = 501, numNeuronBins = 501

    SpHr_NeuronsIPD/R=1.2/L=0.2/N={numNeurons,numNeuronBins} IPDLabels, MaxLabels, IPDNeurons; killwaves/Z MaxLabels

    SpHr_NeuronsILD/R=(50)/W=6/S/L=24/N={numNeurons,numNeuronBins}/SL=(V_IPDLabelShift) ILDLabels, ILDNeurons

    // SpHr_ActivityOverTime - default output wave names

    variable LimitSet = 20 // Activity limit

    String HM_Str="", HM_DFStr=""

    if(useEnvelopeCues) // include Env={FilterWidths,V_NeuronWidth}

        SpHr_ActivityOverTime/Lim=(LimitSet)/ITD/HM/P/X CFs=CFs,XsNs={Xs,Ns},ILD={ILDs,ILDNeurons,ILDLabels,1},IPD={IPDs,IPDNeurons,IPDLabels},Env={FilterWidths,V_NeuronWidth}

    else

        SpHr_ActivityOverTime/Lim=(LimitSet)/F=(carrierHighHz)/ITD/HM/P/X CFs=CFs,XsNs={Xs,Ns},ILD={ILDs,ILDNeurons,ILDLabels,1},IPD={IPDs,IPDNeurons,IPDLabels}

    endif

    Wave HM_Points = $S_PflagHM

    Wave M_Points = $S_PflagM; KillWaves/Z M_Points

    // Display Activities re: Half-maximum

    Variable LimitUsed = V_FreqAvgLimit

    // custom ColorTable, /P=(0.5) so half-maximum is hot

    SpHr_ColorTable/P=(0.5)/Dest=ColorTable "Turbo"

    // Find index in CFs closest to Frequency

    Frequency = limit(Frequency,CFs[0],CFs[numpnts(CFs)-1])

    variable FreqIndex = round(BinarySearchInterp(CFs,Frequency))

    Frequency = CFs[FreqIndex] // CFs frequency

    ////////////////////////////////////////////////////////////////

    // Make ABL Alpha waves prefixed with "ABLMask" for all waves in DataFolder $S_HMflag

    wavestats/Q/RMD=[][FreqIndex,FreqIndex] ABLs

    SpHr_ActivityAlpha /OT={$S_HMflag,CFs,"ABLMask"} Wts={ABLs,V_min+6,V_max}

    // Color Table AlphaCT for ABLMasks

    SpHr_ColorTable/Dest=AlphaCT/A={0,1} "White"

    ////////////////////////////////////////////////////////////////

    KillWindow/Z LeftHemisphereOT; KillWindow/Z RightHemisphereOT

    // Left Hemisphere

    Display /W=(12,55,450,290)/N=LeftHemisphereOT/K=1 HM_Points[*][FreqIndex][0][0] vs Xs[][FreqIndex] as "Left Hemisphere "+num2str(Frequency)+" Hz"

    wave HM_L = $":"+S_HMflag+":"+S_HMflag+"_"+num2str(Frequency)+"_Hz_Left"

    wave XEdges = $":"+S_Xflag+":"+S_Xflag+"_"+num2str(Frequency)+"_Hz"

    AppendImage HM_L vs {XEdges,*}

    ModifyImage $NameOfWave(HM_L) ctab={0,LimitUsed,ColorTable,0}

    ModifyGraph mode=3,marker=19,rgb=(0,0,0),msize=1

    ModifyGraph zero(left)=1,mirror=0,zeroThick(left)=0.5

    SetAxis/A/E=2 left

    Label bottom "time (\\U)"

    Label left "Combination of ILD and ITD\\u#2"

    ModifyGraph margin(right)=54

    ColorScale/C/N=text0/F=0/B=1/A=RC/X=-15.00/Y=0.00

    ColorScale/C/N=text0 image=$NameOfWave(HM_L),side=1,frame=0

    ColorScale/C/N=text0 height=120, width=6,tickThick=0.5,tickLen=2,nticks=3,lblMargin=-4

    ////////////////////////////////////////////////////////////////

    // Append SpHr_ActivityAlpha /OT output

    // S_OTflagPrefix = "ABLMask"

    wave Mask_L = $":"+S_HMflag+":"+S_OTflagPrefix+S_HMflag+"_"+num2str(Frequency)+"_Hz_Left"

    AppendImage Mask_L vs {XEdges,*}

    ModifyImage $NameOfWave(Mask_L) ctab= {1,0,AlphaCT,0}

    ////////////////////////////////////////////////////////////////

    // Right Hemisphere

    KillWindow/Z RightHemisphereOT; KillWindow/Z RightHemisphereOT

    Display /W=(12,316,450,551)/N=RightHemisphereOT/K=1 HM_Points[*][FreqIndex][1][0] vs Xs[][FreqIndex] as "Right Hemisphere "+num2str(Frequency)+" Hz"

    wave HM_R = $":"+S_HMflag+":"+S_HMflag+"_"+num2str(Frequency)+"_Hz_Right"

    wave XEdges = $":"+S_Xflag+":"+S_Xflag+"_"+num2str(Frequency)+"_Hz"

    AppendImage HM_R vs {XEdges,*}

    ModifyImage $NameOfWave(HM_R) ctab={0,LimitUsed,ColorTable,0}

    ModifyGraph mode=3,marker=19,rgb=(0,0,0),msize=1

    ModifyGraph zero(left)=1,mirror=0,zeroThick(left)=0.5

    SetAxis/A/E=2 left

    Label bottom "time (\\U)"

    Label left "Combination of ILD and ITD\\u#2"

    ModifyGraph margin(right)=54

    ColorScale/C/N=text0/F=0/B=1/A=RC/X=-15.00/Y=0.00

    ColorScale/C/N=text0 image=$NameOfWave(HM_R),side=1,frame=0

    ColorScale/C/N=text0 height=120, width=6,tickThick=0.5,tickLen=2,nticks=3,lblMargin=-4

    ////////////////////////////////////////////////////////////////

    // Append SpHr_ActivityAlpha /OT output

    // S_OTflagPrefix = "ABLMask"

    wave Mask_R = $":"+S_HMflag+":"+S_OTflagPrefix+S_HMflag+"_"+num2str(Frequency)+"_Hz_Right"

    AppendImage Mask_R vs {XEdges,*}

    ModifyImage $NameOfWave(Mask_R) ctab= {1,0,AlphaCT,0}

    ////////////////////////////////////////////////////////////////

    SetDataFolder saveDFR

End


Function SpHr_ActivityAlphaAT_Example()

    // Signal spectrum is 1/frequency ('pink').

    // The displayed image should therefore fade to white as

    // frequency increases and ABL declines.

    variable useEnvelopeCues = 0 // carrier=0, envelope=1

    DFREF saveDFR = GetDataFolderDFR()

    NewDataFolder/O/S ActivityAtTime

    // Test Signal, ITD= 0.1 ms, ILD= 3 dB, independence index= 0.1

    SpHr_SignalBinaural/sec=1/Ramp=1/dB=70/HP=50/Sp=1/Ind=0.1/ITD={0.1}/ILD={3} 48000, NoiseBurst

    // Filter bank

    variable lowHz = 100, highHz = 8000, carrierHighHz = 2000

    SpHr_FilterCenterFreqs/R/Type=(2)/E=CFEdges  lowHz, highHz, 32, CFs

    SpHr_FilterBankBiquadCoefs/W=FilterWidths 48000, CFs, coefBank

    SpHr_FilterBankBiquad /RMS/Dest=FilterBanks CFs, coefBank, NoiseBurst

    KillWaves/Z coefBank, NoiseBurst

    // IPD, ILDs, Xs, and XNs

    if(useEnvelopeCues)

        SpHr_CrossingEnvelopeCues/IPD=IPDs/ILD=ILDs/ABL=ABLs/X=Xs/XN=Ns CFs, FilterBanks

    else

        SpHr_CrossingCarrierCues/F={carrierHighHz}/IPD=IPDs/ILD=ILDs/ABL=ABLs/X=Xs/XN=Ns/AWts={20,20,EnvWts} CFs, FilterBanks

    endif

    KillWaves/Z FilterBanks

    // Model left hemisphere IPD and ILD Neurons

    variable numNeurons = 1001, numNeuronBins = 1001

    SpHr_NeuronsIPD/R=1.2/L=0.2/N={numNeurons,numNeuronBins} IPDLabels, MaxLabels, IPDNeurons; killwaves/Z MaxLabels

    SpHr_NeuronsILD/R=(50)/W=6/S/L=24/N={numNeurons,numNeuronBins}/SL=(V_IPDLabelShift) ILDLabels, ILDNeurons

    // SpHr_ActivityAtTime - default output wave names

    variable LimitSet = 20 // Activity limit

    if(useEnvelopeCues) // include Env={FilterWidths,V_NeuronWidth}

        SpHr_ActivityAtTime/Q/F=(lowHz)/Lim=(LimitSet)/ITD/HM/P Env={FilterWidths,V_NeuronWidth},CFs=CFs,XsNs={Xs,Ns},IPD={IPDs,IPDNeurons,IPDLabels},ILD={ILDs,ILDNeurons,ILDLabels,1}

    else

        SpHr_ActivityAtTime/Q/F=(carrierHighHz)/Lim=(LimitSet)/ITD/HM/P CFs=CFs,XsNs={Xs,Ns},Wts={EnvWts},IPD={IPDs,IPDNeurons,IPDLabels},ILD={ILDs,ILDNeurons,ILDLabels,1} 

    endif

    wave HM_L = $S_HMflagLeft; wave HM_R = $S_HMflagRight; wave HM_Points = $S_PflagHM // default wave names

    Variable LimitUsed = V_FreqAvgLimit

    // Display Activities re: Half-maximum

    SpHr_ColorTable/P=(0.5)/Dest=ColorTable "Turbo" // /P=(0.5) so half-maximum is hot color

    ////////////////////////////////////////////////////////////////

    // // Make ABL Alpha wave named ABLMask

    wavestats/Q ABLs

    SpHr_ActivityAlpha/AT={HM_L, ABLMask} Wts={ABLs,v_max-36,v_max-12}

    // Color Table for ABLMask

    SpHr_ColorTable/Dest=AlphaCT/A={0,1} "White"

    ////////////////////////////////////////////////////////////////

    KillWindow/Z LeftHemisphereAT; KillWindow/Z RightHemisphereAT

    // Left Hemisphere

    Display/W=(455,54,822,290)/N=LeftHemisphereAT/K=1/VERT HM_Points[*][0][0] vs CFs as "Left Hemisphere"

    ModifyGraph margin(right)=54

    AppendImage/G=1 HM_L vs {*,CFEdges}

    ModifyImage $NameOfWave(HM_L) ctab={0,LimitUsed,ColorTable,0}

    ModifyGraph mode=3,marker=19,rgb=(48059,48059,48059),msize=1.5

    ModifyGraph log(left)=1,zero(bottom)=2, mirror=0

    SetAxis/A/E=2 bottom

    Label left "frequency (\\U)"

    Label bottom "Combination of ILD and ITD \\U"

    ColorScale/C/N=text0/F=0/B=1/A=RC/X=-20.00/Y=0.00

    ColorScale/C/N=text0 image=$NameOfWave(HM_L),side=1,frame=0

    ColorScale/C/N=text0 height=120, width=6,tickThick=0.5,tickLen=2,nticks=3,lblMargin=-2

    ////////////////////////////////////////////////////////////////

    // Append ABLMask

    // S_ATflagName = "ABLMask"

    AppendImage $S_ATflagName vs {*,CFEdges}

    ModifyImage $S_ATflagName ctab= {1,0,AlphaCT,0}

    ////////////////////////////////////////////////////////////////

    // Right Hemisphere

    Display/W=(455,315,822,551)/N=RightHemisphereAT/K=1/VERT HM_Points[*][1][0] vs CFs as "Right Hemisphere"

    ModifyGraph margin(right)=54

    AppendImage/G=1 HM_R vs {*,CFEdges}

    ModifyImage $NameOfWave(HM_R) ctab={0,LimitUsed,ColorTable,0}

    ModifyGraph mode=3,marker=19,rgb=(48059,48059,48059),msize=1.5

    ModifyGraph log(left)=1,zero(bottom)=2, mirror=0

    SetAxis/A/E=2 bottom

    Label left "frequency (\\U)"

    Label bottom "Combination of ILD and ITD \\U"

    ColorScale/C/N=text0/F=0/B=1/A=RC/X=-20.00/Y=0.00

    ColorScale/C/N=text0 image=$NameOfWave(HM_R),side=1,frame=0

    ColorScale/C/N=text0 height=120, width=6,tickThick=0.5,tickLen=2,nticks=3,lblMargin=-2

    ////////////////////////////////////////////////////////////////

    // Append ABLMask

    // S_ATflagName = "ABLMask"

    AppendImage $S_ATflagName vs {*,CFEdges}

    ModifyImage $S_ATflagName ctab= {1,0,AlphaCT,0}

    ////////////////////////////////////////////////////////////////

    SetDataFolder saveDFR

End

Contact: Brian