Function Reference

# BrainWave.FMPMethod.

FMP(segs)

References

# BrainWave.FMPIterativeWeightedMethod.

FMPIterativeWeighted(sweeps)

# BrainWave.RMSMethod.

RMS(ave, winStart, winStop, preDur, sampRate)

# BrainWave.averageAveragesMethod.

Perform a weighted average of a list of averages. The weight of each average in the list is determined by the number of segments from which it was obtained.

averageAverages(aveList, nSegments)

Arguments

Returns

Examples

    epochDur=0.5; preDur=0.15; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs, nRaw = segment(rec, evtTab, -preDur, epochDur, sampRate)
    ave, nSegs = averageEpochs(segs)

    rec2, evtTab2 = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs2, nRaw2 = segment(rec2, evtTab2, -preDur, epochDur, sampRate)
    ave2, nSegs2 = averageEpochs(segs2)

    aveList = [ave, ave2]; nCleanByBlock = [nRaw, nRaw2]
    aveAll, nSegsAll = averageAverages(aveList, nCleanByBlock)

# BrainWave.averageEpochsMethod.

Average the epochs of a segmented recording.

averageEpochs(rec)

Arguments

Returns

Examples

    epochDur=0.5; preDur=0.15; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs, nRaw = segment(rec, evtTab, -preDur, epochDur, sampRate)
    ave, nSegs = averageEpochs(segs)

averageEpochs{T<:Real}(rec::Array{T,3})

# BrainWave.averageEpochsIterativeWeightedMethod.

Average the epochs of a segmented recording using iterative weighted averaging algorithm (see References below).

averageEpochsIterativeWeighted(rec)

Arguments

segments is derived from all the channels. If byChannel an noise estimate is derived for each channel and segments are weighted differently for each channel depending on the channel noise estimate.

Returns

Examples

    epochDur=0.5; preDur=0.15; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs, nRaw = segment(rec, evtTab, -preDur, epochDur, sampRate)
    ave = averageEpochsIterativeWeighted(segs)

References

# BrainWave.baselineCorrect!Method.

Perform baseline correction by subtracting the average pre-event voltage from each channel of a segmented recording.

baselineCorrect!(rec, baselineStart, preDur, sampRate)

Arguments

Examples

    epochDur=0.5; preDur=0.15; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs, nRaw = segment(rec, evtTab, -preDur, epochDur, sampRate)

    #baseline window has the same duration of preDur
    baselineCorrect!(segs, -preDur, preDur, sampRate)
    #now with a baseline shorter than preDur
    baselineCorrect!(segs, -0.15, preDur, sampRate)

# BrainWave.deleteSlice2DMethod.

Delete a row or a column from a 2-dimensional array.

deleteSlice2D(x, toRemove, axis)

Arguments

Returns

Examples

    x = [1 2 3 4;
         5 6 7 8;
         9 10 11 12;
         13 14 15 16
        ]

    #remove first row
    isequal(deleteSlice2D(x, 1, 1), x[2:end,:])
    #remove rows 1 and 4
    isequal(deleteSlice2D(x, [1,4], 1), x[2:3,:])
    # remove columns 1 and 4
    isequal(deleteSlice2D(x, [1,4], 2), x[:,2:3])

# BrainWave.deleteSlice3DMethod.

Delete a slice from a 3-dimensional array.

deleteSlice3D(x, toRemove, axis)

Arguments

Returns

Examples

    x = reshape(collect(1:27), 3,3,3)
    deleteSlice3D(x, 2, 1)
    deleteSlice3D(x, [2,3], 3)
    isequal(deleteSlice3D(x, [2,3], 3), x[:,:, [1]])

# BrainWave.detrendEEG!Method.

Remove the mean value from each channel of an EEG recording.

detrendEEG!(rec)

Arguments

Examples

    x = [1 2 3; 4 5 6]
    detrendEEG!(x)

# BrainWave.epochVarianceMethod.

epochVariance(rec, winStart, winStop, preDur, sampRate)

# BrainWave.fftconvolveMethod.

Convolve two 1-dimensional arrays using the FFT.

fftconvolve(x, y, mode)

Arguments

Returns

Examples

    x = rand(1:10, 10)
    y = rand(1:10, 10)
    fftconvolve(x, y, "same")

# BrainWave.filterContinuous!Method.

Filter a continuous EEG recording.

filterContinuous!(rec, sampRate, filterType, nTaps, cutoffs)

Arguments

Examples

    sampRate = 2048; nTaps=512
    rec, evtTab = simulateRecording(nChans=4, dur=120, sampRate=sampRate)
    filterContinuous!(rec, sampRate, "highpass", nTaps, [30], channels=[1,2,3,4], transitionWidth=0.2)

    #using the parallel processing version of the function with a SharedArray
    @everywhere using BrainWave
    rec, evtTab = simulateRecording(nChans=4, dur=120, sampRate=sampRate);
    #to exploit parallel processing you need to call julia with -p `n` parameter, or use addprocs(`n`)
    #where n is the number of processes you want to use
    #convert recording to SharedArray
    sharedRec = convert(SharedArray, rec)
    #call the filtering function
    filterContinuous!(rec, sampRate, "highpass", nTaps, [30], channels=[1,2,3,4], transitionWidth=0.2)
    #convert back to Array type
    rec = convert(Array, sharedRec)

    #using the parallel processing version of the function with a DistributedArray
    @everywhere using BrainWave, DistributedArrays
    rec, evtTab = simulateRecording(nChans=4, dur=120, sampRate=sampRate);
    #to exploit parallel processing you need to call julia with -p `n` parameter, or use addprocs(`n`)
    #where n is the number of processes you want to use
    nProcsToUse = min(length(workers()), size(rec, 1))
    workersToUse = workers()[1:nProcsToUse]
    #convert recording to DistributedArray
    dRec = distribute(rec, procs=workersToUse, dist=[nProcsToUse, 1])
    #call the filtering function, note that you need to pass the ids of the workers to use
    filterContinuous!(dRec, sampRate, "highpass", nTaps, [30], workersToUse, channels=[1,2,3,4], transitionWidth=0.2)
    #convert back to Array type
    rec[:,:] = convert(Array, dRec)

# BrainWave.findABRPeaksMethod.

Attempt to find peaks and troughs of the ABR response for a click of a given level. The algorithm is largely based on Bradley and Wilson (2004).

findABRPeaks(sig, stimLevel, sampRate)

Arguments

Returns

References

Examples


# BrainWave.findArtefactThreshFunction.

Find epochs with voltage values exceeding a given threshold.

findArtefactThresh(rec, thresh, channels)
findArtefactThresh(rec, thresh)

Arguments

Returns

Notes

If neither channel indexes (chans) nor channel labels (chanLabels) for the channels on which to check artefacts are provided, then artefacts will be checked for on all channels. If channel labels (chanLabels) are given for the channels on which to check for artefacts, then an ordered list containing the names of all available channels (chanList) must be provided as well.

thresh should be a list of threshold values, one for each channel to check. If thresh contains only one value, it is assumed that this is the desired threshold for all of the channels to check. If thresh contains more than one value, its length must match the number of channels to check.

Examples

    epochDur=0.5; preDur=0.15; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs, nRaw = segment(rec, evtTab, -preDur, epochDur, sampRate)
    # on all channels
    badSegs = findArtefactThresh(segs, 65)
    # on channels 1 and 2
    badSegs = findArtefactThresh(segs, 65, [1,2])
    # on channels FP1 and F4 #not run
    #findArtefactThresh(segs, 20, ["Fp1", "F4"], chanLabels)

# BrainWave.findExtremumMethod.

Find the time point at which a waveform reaches a maximum or a minimum.

findExtremum(wave, searchStart, searchStop, extremumSign, epochStart, sampRate)

Arguments:

Returns

Examples

    ## not run
    ## P2SearchStart = 0.150
    ## P2SearchStop = 0.250
    ## epochStart = -0.150
    ## sampRate = 8192
    ## sampPnt, timePnt = findExtremum(wave1, P2SearchStart, P2SearchStop, "positive", epochStart, sampRate)

    # contrived example
    #using Winston
    sampRate = 256
    dur = 0.6
    epochStart = -0.15
    P2SearchStart = 0.150
    P2SearchStop = 0.250
    nSamp = round(Int, dur*sampRate)
    freq = 2
    phase = 1/4*(-pi)
    tArr = collect(0:nSamp-1)/sampRate + epochStart
    wave1 = sin(2*pi*freq*tArr+phase)
    wave1[1:round(Int, abs(epochStart)*sampRate)] = 0
    sampPnt, timePnt = findExtremum(wave1, P2SearchStart, P2SearchStop, "positive", epochStart, sampRate)
    #p = plot(tArr, wave1)
    #l1 = LineX(timePnt, color="red")
    #add(p, l1)
    #display(p)

# BrainWave.getACFMethod.

Compute the autocorrelation function of a 1-dimensional signal.

getACF(sig, sampRate, maxLag)

Arguments:

Returns

Examples

    using DSP
    sampRate = 48000
    dur = 1
    nSamp = round(Int, sampRate*dur)
    tArr = collect(0:nSamp-1)/sampRate
    freq = 440
    sig = sin(2*pi*freq*tArr)
    maxLag = 1/200
    acf, lags = getACF(sig, sampRate, maxLag, normalize=true, window=hamming)

# BrainWave.getAutocorrelogramMethod.

Compute the autocorrelogram of a 1-dimensional array.

getAutocorrelogram(sig, sampRate, winLength, overlap, maxLag)

Arguments

Returns

Examples

    sig = rand(512)
    acg, lags, t = getAutocorrelogram(sig, 256, 0.02, 30, 0.01)

# BrainWave.getPhaseSpectrumMethod.

Compute the phase spectrum of a 1-dimensional array.

getPhaseSpectrum(sig, sampRate)

Arguments

Returns

Examples

    sig = rand(512)
    p, f = getPhaseSpectrum(sig, 256)

# BrainWave.getSNRMethod.

Compute the signal-to-noise ratio at a given frequency in the power spectrum of a recording.

getSNR(spec, freqArr, sigFreq, nSideComp, nExclude)

Arguments

Returns

Examples

    sig = rand(512)
    p, f = getSpectrum(sig, 512)
    snr = getSNR(p, f, 140, 10, 1)

# BrainWave.getSNR2Method.

Compute the signal-to-noise ratio at a given frequency in the power spectrum of a recording. This function is the same as getSNR, but it additionaly returns the signal and noise magnitudes separately.

getSNR2(spec, freqArr, sigFreq, nSideComp, nExclude)

Arguments

Returns

Examples

    sig = rand(512)
    p, f = getSpectrum(sig, 512)
    snr, sigMag, noiseMag = getSNR2(p, f, 140, 10, 1)

# BrainWave.getSpectrogramMethod.

Compute the spectrogram of a 1-dimensional array.

getSpectrogram(sig, sampRate, winLength, overlap)

Arguments

Returns

Notes

If the signal length is not a multiple of the window length it is trucated.

Examples

    sig = rand(512)
    spec, f, t = getSpectrogram(sig, 256, 0.02, 30)

# BrainWave.getSpectrumMethod.

Compute the power spectrum of a 1-dimensional array.

getSpectrum(sig, sampRate)

Arguments

Returns

Examples

    sig = rand(512)
    p, f = getSpectrum(sig, 256)

# BrainWave.inputFunction.

input(prompt::AbstractString="")

input()
input(prompt)

Read a string from STDIN. The trailing newline is stripped.

The prompt string, if given, is printed to standard output without a trailing newline before reading input.

# BrainWave.iterativeWeightedAverageMethod.

Compute an iterative weighted average from a matrix of segmented EEG recordings.

iterativeWeightedAverage(sweeps)

Arguments

average should be computed.

segments is derived from all the channels. If byChannel an noise estimate is derived for each channel and segments are weighted differently for each channel depending on the channel noise estimate.

Returns

Examples

nChans = 3; nSamp=1000; nSweeps=500 sweeps = rand(nChans, nSamp, nSweeps) iterativeWeightedAverage(sweeps, noiseEstimate="global") iterativeWeightedAverage(sweeps, noiseEstimate="byChannel") iterativeWeightedAverage(sweeps, 0, 0.2, 0.1, 1000, noiseEstimate="global")

References

# BrainWave.meanERPAmplitudeMethod.

Compute the mean amplitude of an ERP waveform in a time window centered on a given point.

meanERPAmplitude(wave, center, centerType, winLength, sampRate)

Arguments:

Returns

Examples

```julia
## not run
## P2WinLength = 0.050
## centerPoint = 2512
## sampRate = 8192
## meanAmp =  meanERPAmplitude(wave, centerPoint, "point", P2WinLength, sampRate)

## epochStart = -0.150
## centerPointTm = 0.156
## meanAmp =  meanERPAmplitude(wave, centerPointTm, "time", P2WinLength, sampRate)

# contrived example
#using Winston
sampRate = 256
dur = 0.6
epochStart = -0.15
P2SearchStart = 0.150
P2SearchStop = 0.250
nSamp = round(Int, dur*sampRate)
freq = 2
phase = 1/4*(-pi)
tArr = collect(0:nSamp-1)/sampRate + epochStart
wave1 = sin(2*pi*freq*tArr+phase)
wave1[1:round(Int, abs(epochStart)*sampRate)] = 0
sampPnt, timePnt = findExtremum(wave1, P2SearchStart, P2SearchStop, "positive", epochStart, sampRate)
#p = plot(tArr, wave1)
#l1 = LineX(timePnt, color="red")
#add(p, l1)
#display(p)
meanAmp =  meanERPAmplitude(wave1, sampPnt, "point", 0.05, sampRate)
```

# BrainWave.mergeEventTableCodes!Method.

Substitute the event table triggers listed in trigList with newTrig

mergeEventTableCodes!(eventTable, trigList, newTrig)

Arguments

Examples

```julia
rec, evtTab= simulateRecording(events=[1,2,3,4])
mergeEventTableCodes!(evtTab, [1,2], 1)
mergeEventTableCodes!(evtTab, [3,4], 3)
```

# BrainWave.nextPowTwoMethod.

Find the exponent of the next power of 2 closest to x.

nextPowTwo(x)

Arguments

Examples

```julia
nextPowTwo(6)
nextPowTwo(511)
isequal(2^(nextPowTwo(6)), 2^3)
```

# BrainWave.removeEpochs!Method.

Remove epochs from a segmented recording.

removeEpochs!(rec, toRemove)

Arguments

Examples

    epochDur=0.5; preDur=0.15; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events)
    segs, nRaw = segment(rec, evtTab, -preDur, epochDur, sampRate)
    segsToReject = Dict{String,Array{Int,1}}()
    segsToReject["1"] = [3,5]
    segsToReject["2"] = [1,2]
    #toRemove = @compat Dict("1" => [3,5], "2" => [2])
    removeEpochs!(segs, segsToReject)

# BrainWave.removeSpuriousTriggers!Method.

Attempt to remove spurious triggers from an event table.

removeSpuriousTriggers!(eventTable, sentTrigs, minTrigDur, minTrig, maxTrig)

Arguments

Returns

Notes

Spurious triggers may be cause by hardware mulfunction. They may also occurr if the triggers are not sent digitally (e.g. through the parallel port), but are sent through an analogous device (e.g. through the soundcard to synchronize them directly with sound onset). Spurious triggers may have completely different codes (e.g. 177, when the triggers that were actually sent could only take the values of 100 and 120), in which case they are easy to find and remove. However, they may also have the same code as legitimate triggers. In this case they are more difficult to find. This function can find them if they have a shorter duration than legitimate triggers.

Examples

    using BrainWave, Compat

    sentTrigs = [1,1,1,2,2,1,2,2,1,1] #triggers that were actually sent
    evtTab = Dict{String,Any}() #fictitious event table
    evtTab["code"] = [1,1,5,1,7,2,5,2,1,2,8,2,1,1,7] #with spurious triggers
    evtTab["idx"] = collect(1:500:500*15)
    evtTab["dur"] = [0.001 for i=1:15]
    res_info = removeSpuriousTriggers!(evtTab, sentTrigs, 0.0004, 192, 254)
    println(res_info)
    assert(res_info["match"] == true)
    #sometimes spurious triggers have the same code as legitimate ones
    #but they can still be found if they differ from legitimate
    #triggers in duration
    sentTrigs = [1,2,3,4,5,6,7,8,9,10] #triggers that were actually sent
    evtTab = Dict{String,Any}() #fictitious event table
    evtTab["code"] = [1,1,1,2,3,4,4,5,6,7,7,7,8,9,10] #with spurious triggers
    evtTab["idx"] = collect(1:500:500*15)
    evtTab["dur"] = [0.001 for i=1:15]
    evtTab["dur"][[2,3,7,11,12]] = 0.0001 #spurious triggers have shorter duration

    res_info = removeSpuriousTriggers!(evtTab, sentTrigs, 0.0004, 192, 254)
    println(res_info)
    assert(res_info["match"] == true)

# BrainWave.rerefCnt!Method.

Rereference channels in a continuous recording.

rerefCnt!(rec, refChan)

Arguments

Examples

    rec, evtTab = simulateRecording(nChans=4)
    rerefCnt!(rec, 4, channels=[1, 2, 3])

# BrainWave.segmentMethod.

Segment a continuous EEG recording into discrete event-related epochs.

segment(rec, eventTable, epochStart, epochEnd, sampRate)

Arguments

Returns

Examples

    epochDur=0.5; preDur=0.2; events=[1,2]; sampRate=256;
    rec, evtTab = simulateRecording(dur=120, epochDur=epochDur, preDur=preDur, events=events, sampRate=sampRate)
    segs, nSegs = segment(rec, evtTab, -preDur, epochDur, sampRate, eventsList=[1, 2], eventsLabelsList=["cnd1", "cnd2"])

# BrainWave.simulateRecordingMethod.

Generate a simulated EEG recordings. Not physiologically plausible. Mainly useful for testing purposes.

simulateRecording(; nChans, dur, sampRate, minVolt, maxVolt, events, epochDur, preDur)

Arguments

Returns

Examples

    rec, evtTab = simulateRecording()
    rec, evtTab = simulateRecording(dur=180, events=[1,2,3])

# BrainWave._centeredMethod.