# Conditioned Headturn - signal detection

## About this protocol

This protocol demonstrates a common application of a [conditioned headturn procedure](../../goals-and-capabilities/paradigms/conditioned-headturn-procedure): signal detection. It isn't strictly based on any particular study, although it is similar conceptually to many in the realm of infant signal detection in noise, e.g. Trehub, Bull, & Schneider 1981; Werner & Bargones 1991.

In this example study, multi-talker background noise plays continuously throughout. During some trials, an additional voice that repeatedly calls the participant's name begins playing too. When the name is being called and the participant turns toward the source of the voice (a "hit"), they are rewarded with a desirable stimulus (e.g. a toy being lit up or beginning to move). When the name is being called but their behavior does not indicate that they detected it (i.e. they don't turn toward it - a "miss"), the reward stimulus is not presented, nor is it presented when the name is not being played, whether they turn (a "false alarm") or not (a "correct rejection").

This is a simple example of a signal detection task because during the test phase, it does not adjust the intensity of the signal (voice calling the name) relative to the noise, as you would when attempting to establish a detection threshold.

## Starting the protocol

### Starting definitions

This protocol will use two separate channels on a [DMX dimmer pack](../../../set-up/hardware-installation-guide#lights). In the protocol we'll refer to these as `LIGHT LEFT` and `LIGHT RIGHT`, _but crucially, these won't both correspond to lights_.

**The LEFT light will be our reward stimulus**. Depending on the implementation of conditioned headturn, it might be an actual, simple light that illuminates an otherwise invisible toy. Or the "light" might be a plugged-in device or electronic toy that will begin to move when receiving power - BITTSy doesn't know the difference!

**The RIGHT light will refer to an empty channel** on the dimmer pack, with either nothing plugged in or something plugged in that will remain powered off regardless of the dimmer pack command (i.e. by having the power switch on the device be in the off position). We need this empty channel so that trials can always be structured the same way, whether they are trials with a potential to show the reward or not.

```
SIDES ARE {CENTER, LEFT, RIGHT}
LIGHTS ARE {LEFT, RIGHT}
```

The above are our [starting definitions](../starting-definitions). However, if you have more lights connected in your system (e.g. for headturn preference procedure) and will be leaving them all connected during testing, you may need to define more lights so that you can identify which channel has the reward stimulus and which is empty.

### Tags

Now we'll define our [tags that reference files](../tags/tags-referencing-files). We have only audio files for this type of study. One is the background noise that will play continuously throughout. Then we have our signal of interest - the file that contains the voice calling the participant's name. We'll call this audio file `changestim`. We'll need another to be the `controlstim` so that regardless of the trial type, we've got a command to play an audio file. But in this case, the control stimulus is actually a completely silent file, since we're interested in comparing the presentation of the name to a case where the background noise simply continues with nothing else added.

```
LET noise = "C:\Users\ldev\Desktop\BITTSy\ConditionedHeadturn_signaldetection\9-voices.wav"
LET changestim = "C:\Users\ldev\Desktop\BITTSy\ConditionedHeadturn_signaldetection\Alexis.wav"
LET controlstim = "C:\Users\ldev\Desktop\BITTSy\ConditionedHeadturn_signaldetection\silence.wav"
```

### Groups

We'll use groups to set up a key aspect of this paradigm: the "change stimulus" or signal of interest (the voice calling the participant's name) gets paired with the reward stimulus (plugged into the `LEFT` light channel) and the "control stimulus" (the absence of the voice - a silent audio file) does not.

A "change trial" will use both the "change" stimulus and the `LEFT` light. So we'll define a group that pairs them, called `changetrial`.

```
LET changetrialstim = {changestim}
LET changetrialside = {LEFT}
LET changetrial = {changetrialstim, changetrialside}
```

{% hint style="info" %}
If you wanted change trials to contain one of several possible audio files (e.g. with different tokens/words/voices), your `changetrialstim` group would contain multiple tags for the different audio files. In later steps of the protocol when the audio files are played, you could randomize which audio file is selected from the group. However, it's important to set up your [selection criteria](../../selection-and-randomization#repeat-clauses) in a way that ensures that there will always be a valid selection that can be made for the audio file, regardless of whether the current trial is a change trial or control trial.
{% endhint %}

Similarly, we'll make a `controltrial` group that pairs the "control" stimulus (silence) with the empty `RIGHT` channel, so that this trial type can have the same structure within the protocol, but not actually turn on a device.

```
LET controltrialstim = {controlstim}
LET controltrialside = {RIGHT}
LET controltrial = {controltrialstim, controltrialside}
```

{% hint style="info" %}
You may wonder why we define the first two groups in each set rather than directly defining `LET changetrial = {changestim, LEFT}`. At time of writing, BITTSy throws a validation error when a group directly contains both tags and sides. However, creating a "dummy" group that contains each and making `changetrial` be a group of other groups sidesteps the validation error and allows you to run the protocol.&#x20;
{% endhint %}

Now that we have structures representing change and control trials, we can define the groups that we'll use to present these trial types within phases - training phase, conditioning phase, and test phase.

```
LET training = {changetrial}
LET conditioning = {changetrial}
LET test = {changetrial, controltrial}
```

In this study, we can choose to not include control trials in the training phase - since the control trials are the absence of the voice and absence of the reward stimulus, the gaps between change trials essentially function as reinforcing that the reward does not occur until the change stimulus is present. A study focusing on discrimination between two signals, where one is rewarded and the other is not, would likely have control trials during training. But it is not necessary here, so the `training` group can contain only `changetrial`.

The conditioning phase will also only contain change trials - the goal of this phase, after the initial exposure to the paired signal and reward in the training phase, will be to ensure that the participant _predicts_ the reward after hearing the stimulus, and makes an _anticipatory_ turn toward the location of the reward.

The test phase will contain both change trials and control trials. Here, we'll have them occur with equal probability, but we could weight the relative probabilities by adding more change trials or more control trials to the `test` group.

### Experiment settings

There are no special [experiment settings](../optional-experiment-settings) required for this protocol. However, if we planned on using the [reporting module](../../data-output/the-reporting-module) to analyze participant logs, it is helpful to make sure that the key that is used to mark the participant turning toward the signal matches the [key assigned](../../optional-experiment-settings#key-assignments) to the `LEFT` side (where the signal will be presented). That way, the turn is logged as a look toward that stimulus rather than just a timestamped keypress, and we can easily summarize which trials had turns and the time it took before the participant turned via a [standard report](../../data-output/standard-reports) of looking time by trial. This protocol is configured to use L, the default key for `LEFT`, so it doesn't require a key assignment definition, but if you wished to use another key other than L, you could include one in this section.

## STEPS for execution

### Training

First in this study, we'll start playing the background noise file that will play on loop throughout the entire study. Then we'll want to wait until the experimenter judges that the infant is ready for a trial to start. (Typically in conditioned headturn studies, a second experimenter sits in front of the infant to engage their attention with some small toys, and the experimenter running the protocol would wait until the infant was attending to the toys, relaxed and unfussy.) We'll have the main experimenter press C when the infant is ready.

```
STEP 1
Phase Training Start
AUDIO CENTER noise LOOP

STEP 2
UNTIL KEY C
```

{% hint style="info" %}
The starting definitions we used didn't specify a `CENTER` audio channel (i.e. for use with a [multichannel](../../starting-definitions#audio) speaker array), so here we have the default behavior of `CENTER` , where it's exactly the same as `STEREO` - played simultaneously from the left and right channels. This means that when we later have trial audio play from `LEFT`, BITTSy will play it simultaneously from one of the speakers that is already playing the noise file (while the speaker on the right channel continues with only the noise). Having the noise play from `CENTER` allows us to turn off the trial audio on `LEFT` without interrupting the noise at all. If you wanted the noise to come from only the same speaker as the trial audio, while keeping the ability to turn off trial audio without interrupting the noise, you could set up your noise audio file to have information only on the left channel and silence on the right channel, and still instruct BITTSy to play it `CENTER`.
{% endhint %}

Next we'll need to pick the trial type from the `training` group so that we can subsequently use its components. But there's only actually one trial type in this group, so it doesn't matter how we select it, so long as we allow for repeats.

```
STEP 3
LET trial_tr = (FROM training RANDOM)
```

The [dynamic tag](../tags/dynamic-tags) `trial_tr` will now refer to that one trial type group, `changetrial`, which itself has two tags inside - the first referring to the audio file that will be played, and the second referring to the `LIGHT` channel that will be used during those trials - for change trials, the location of the reward stimulus. We can use [selection restrictions](../../selection-and-randomization#repeat-clauses) to ensure we pick first the audio file group, then the reward location group, to access these components and later use them to display stimuli.

```
LET audiostim = (FROM trial_tr FIRST {with max 0 repeats in succession})
LET reward = (FROM trial_tr FIRST {with max 0 repeats in succession})
```

Recall that these subgroups were themselves groups that contained one tag/side each in order to avoid making a group that directly contained both a regular tag and a side name. So we have one more layer of selection to get to our final tags.

```
LET audiostim_tr = (FROM audiostim FIRST)
LET reward_tr = (FROM reward FIRST)
```

Now we can begin to present the change trial audio. We'll add a brief delay after it starts so that the reward doesn't turn on simultaneously with the audio signal, but rather the start of the audio indicates that the reward will appear soon.

```
AUDIO LEFT audiostim_tr LOOP
UNTIL TIME 1000
```

{% hint style="info" %}
Audio set to `LOOP` does not turn off until we use an `AUDIO OFF` command. The change trial audio will continue playing after this step, while we present the reward! If you wanted the audio and reward to be presented sequentially and not overlap, you could adjust this `UNTIL TIME 1000` statement above to be the full length of time you want the audio to play, and put the `AUDIO LEFT OFF` command to before the `LIGHT ON` statement in `STEP 4`.
{% endhint %}

Now it's time to turn on the reward. In the training phase, this isn't dependent on the behavior the participant exhibits yet, we'll simply always turn on the reward. We'll keep it on for a little while, then turn off both the reward and audio together. (Note that since the background noise was playing `AUDIO CENTER` and the change trial audio plays `AUDIO LEFT`, we can turn off the change stimulus with `AUDIO LEFT OFF` without interrupting the background noise.)

```
STEP 4
LIGHT reward_tr ON
UNTIL TIME 5000

STEP 5
LIGHT reward_tr OFF
AUDIO LEFT OFF
```

From `STEP 2` to here constitutes the repeating structure of the training phase - waiting for the experimenter to indicate the participant is ready for a trial, starting to present the change audio, turning on the reward, and turning both off. We can use a [loop ](../loops)to repeat this structure until the end of the phase (in a real study, we would likely repeat it more times.)

```
STEP 6
LOOP STEP 2
UNTIL 3 TIMES

STEP 7
Phase End
```

### Conditioning

Now that the participant has some exposure to the audio signal and has had an opportunity to learn that the reward turns on when it plays, in the conditioning phase, we'll ensure that the participant has learned that the audio stimulus _predicts_ the onset of the reward by requiring that they make anticipatory headturns toward the location of the reward stimulus whenever they hear the audio signal. We'll begin delaying the onset of the reward to give them more opportunity to do so, and require three trials in a row where the participant turns in anticipation before the reward stimulus turns on.

Like the training trials, we need to wait for the experimenter to press C to indicate when we're ready for a trial to start.

```
STEP 8
Phase Conditioning Start

STEP 9
UNTIL KEY C
```

Next we'll select the trial audio (always the change stimulus in this phase, since that's the only trial type in the `conditioning` group) and reward location, and start playing the audio. Note that this selection structure is identical to the training phase.

```
STEP 10
Trial Start
LET trial_c2 = (FROM conditioning RANDOM)
LET audiostim2 = (FROM trial_c2 FIRST {with max 0 repeats in succession})
LET reward2 = (FROM trial_c2 FIRST {with max 0 repeats in succession})
LET audiostim_c2 = (FROM audiostim2 FIRST)
LET reward_c2 = (FROM reward2 FIRST)
AUDIO LEFT audiostim_c2 LOOP
```

What's different in this phase is that we want to do different things depending on whether the participant makes an anticipatory headturn or not. If they don't make the headturn within the time limit before the reward stimulus comes on, we want to continue with more trials exactly like this one so they have more opportunity to learn the pattern. But if they've started to learn that the audio predicts the reward and make an anticipatory turn, we're ready to increase the delay in the next trial, and need to keep track of this successful trial as the start of a possible three in a row that would result in ending this phase.

We can use an [OR combination of terminating conditions](../../step-terminating-conditions#or-combinations) with [JUMP](../jump) to create two separate "branches" for each of these possibilities. If there's a headturn before the time limit, we'll jump to `STEP 14`. If not, we'll keep going to the next step. (For a more detailed explanation of this type of usage of `JUMP`, see [this page](../../jump#events-based-on-participant-choice-or-discrete-behavior).)

```
UNTIL KEY L JUMP STEP 14
UNTIL TIME 2000 JUMP STEP 11
```

{% hint style="info" %}
The second UNTIL statement could also be written `UNTIL TIME 2000` without the JUMP clause - JUMP isn't required when the result is simply to go to the next step. But when the protocol is shown broken up into parts like this, adding it makes it a little easier to track what's happening!
{% endhint %}

From here until `STEP 14` defines what we'll do when the participant failed to make an anticipatory headturn on the trial. It looks just like in the training phase. We'll still turn on the reward, so that the participant continues to have opportunities to learn the relationship between the audio stimulus and reward.

```
STEP 11
LIGHT reward_c2 ON
UNTIL TIME 5000

STEP 12
Trial End
LIGHT reward_c2 OFF
AUDIO LEFT OFF
```

After, we'll use a LOOP statement to run more trials. We should include some way to end the study in case the participant doesn't begin making anticipatory headturns. This [loop terminating condition](../../loops#loop-terminating-conditions) will have us jump to the very end of the protocol (`STEP 37`), ending the study, if the participant fails to make an anticipatory headturn 10 times in a row.

```
STEP 13
LOOP STEP 9
UNTIL 9 TIMES JUMP STEP 37
```

{% hint style="info" %}
Using `JUMP` to move _outside_ of this loop when the participant successfully makes an anticipatory headturn will reset the count on this `UNTIL 9 TIMES` loop statement, which is why it requires 10 times _in a row_ rather than 10 times _total_. If you didn't want to reset the count and use a total number of misses instead, you could A) restructure your steps and JUMPs to not require moving to steps that are outside this "core loop", or B) use a loop terminating condition that depends on phase information, like [TOTALLOOKAWAY](../../loops#totalllookaway) (from the reward stimulus) or global information like whether a group is [EMPTY](../../loops#empty), which are unaffected by moving outside the loop. If you preferred to continue presenting trials until the experimenter judged the participant was tired, you could use [KEY](../../loops#key) instead.
{% endhint %}

Recall that `STEP 14` was where we jumped if the participant successfully made an anticipatory turn. This will also result in presenting the reward.

```
STEP 14
LIGHT reward_c2 ON
UNTIL TIME 5000

STEP 15
Trial End
LIGHT reward_c2 OFF
AUDIO LEFT OFF

STEP 16
UNTIL KEY C
```

But crucially after this, instead of looping back, we'll keep going to `STEP 17`, which is only reached when the participant has a current streak of exactly one anticipatory turns in a row. This way, we can track what they need in order to reach three in a row to move to the next phase. (See [this page](../../jump#progressing-based-on-consecutive-criteria) for further explanation of this type of usage of `JUMP`.)

`STEP 17` will start another trial, which is largely identical to before - the only difference is the amount of delay between when the audio starts and when the reward turns on, during which they have an opportunity to make an anticipatory turn.&#x20;

```
STEP 17
Trial Start
LET trial_c3 = (FROM conditioning RANDOM)
LET audiostim3 = (FROM trial_c3 FIRST {with max 0 repeats in succession})
LET reward3 = (FROM trial_c3 FIRST {with max 0 repeats in succession})
LET audiostim_c3 = (FROM audiostim3 FIRST)
LET reward_c3 = (FROM reward3 FIRST)
AUDIO LEFT audiostim_c3 LOOP
UNTIL KEY L JUMP STEP 20
UNTIL TIME 3000 JUMP STEP 18
```

`STEP 18` begins what will happen when the participant had a current streak of one anticipatory turn, but missed this one, resetting their streak. So after presenting the reward as usual, it will jump back to `STEP 9` to present the next trial, which is used whenever the current streak is zero.

```
STEP 18
LIGHT reward_c3 ON
UNTIL TIME 5000

STEP 19
Trial End
LIGHT reward_c3 OFF
AUDIO LEFT OFF
UNTIL TIME 100 JUMP STEP 9
```

`STEP 20`, however, is where we go when the participant made another anticipatory turn - two in a row now. So after presenting the reward as usual, we'll move on to `STEP 23`, which presents another trial but is only reached when the current streak is two in a row. The delay where the participant has an opportunity to make an anticipatory turn increases again.

```
STEP 20
LIGHT reward_c3 ON
UNTIL TIME 5000

STEP 21
Trial End
LIGHT reward_c3 OFF
AUDIO LEFT OFF

STEP 22
UNTIL KEY C

STEP 23
Trial Start
LET trial_c4 = (FROM conditioning RANDOM)
LET audiostim4 = (FROM trial_c4 FIRST {with max 0 repeats in succession})
LET reward4 = (FROM trial_c4 FIRST {with max 0 repeats in succession})
LET audiostim_c4 = (FROM audiostim4 FIRST)
LET reward_c4 = (FROM reward4 FIRST)
AUDIO LEFT audiostim_c4 LOOP
UNTIL KEY L JUMP STEP 26
UNTIL TIME 5000 JUMP STEP 24
```

`STEP 24` is where we end up when the participant missed the time window for the anticipatory turn. So after presenting the reward, we'll specify a jump back to `STEP 9` to reset their streak.

```
STEP 24
LIGHT reward_c4 ON
UNTIL TIME 5000

STEP 25
Trial End
LIGHT reward_c4 OFF
AUDIO LEFT OFF
UNTIL TIME 100 JUMP STEP 9
```

But if we jumped to `STEP 26` instead, we got here because the participant made another anticipatory turn. They already had two in a row to get to `STEP 23`, so the jump straight to `STEP 26` means that they've now achieved three in a row, our criteria for ending the conditioning phase. So after presenting the reward, we'll end the phase and move on straight to the test phase.

```
STEP 26
LIGHT reward_c4 ON
UNTIL TIME 5000

STEP 27
Trial End
LIGHT reward_c4 OFF
AUDIO LEFT OFF

STEP 28
Phase End
```

### Test

In the test phase, trials will sometimes contain the change audio, and sometimes not. The participant should only be rewarded for successfully detecting (making an anticipatory headturn) the change stimulus - this possible outcome is called a "hit." There are three more possible outcomes - the change audio is present and the participant does not make a headturn to show they detected it (a "miss"), the change audio is not present but the participant makes a headturn anyway (a "false alarm"), and the change audio is not present and the participant does not make a headturn (a "correct rejection").

We'll start a trial just like before, waiting for the experimenter to indicate the participant is ready, then selecting from the highest-level group for this phase until we have the final tags we'll use to play audio and turn on a light channel.

```
STEP 29
Phase Test Start

STEP 30
UNTIL KEY C

STEP 31
Trial Start
LET trial_test = (FROM test RANDOM)
LET audiostim_5 = (FROM trial_test FIRST {with max 0 repeats in succession})
LET reward_5 = (FROM trial_test FIRST {with max 0 repeats in succession})
LET audiostim_test = (FROM audiostim_5 FIRST)
LET reward_test = (FROM reward_5 FIRST)
AUDIO LEFT audiostim_test LOOP
```

Since the `test` group contains both change trials and control trials, `audiostim_test` and `reward_test` end up being either the change audio and `LEFT` (the reward stimulus channel) respectively, or a silent audio file and `RIGHT` (the empty channel on the DMX box).

{% hint style="info" %}
The `test` group was defined at the start of the protocol as having one copy of `changetrial` and one copy of `controltrial`, so `(FROM test RANDOM)` in the step above will select them with equal probability but _not_ guarantee an equal number of each across the test phase. If we wanted to ensure a particular number of each, we could define `test` to have that number of copies - e.g., for four of each trial type, `LET test = {changetrial, changetrial, changetrial, changetrial, controltrial, controltrial, controltrial, controltrial}`Then use `(TAKE test RANDOM)` instead.
{% endhint %}

Like in the conditioning phase, we're interested in whether the participant makes an anticipatory headturn toward the reward (L), and we need to do different actions depending on their behavior. We'll have another OR combination of UNTIL statements that will allow us to jump to different sections depending on what happens.

```
UNTIL TIME 5000 JUMP STEP 34
UNTIL KEY L JUMP STEP 32
```

`STEP 32` is what will execute when the participant makes a headturn within 5 seconds of when the trial audio (either the change audio or the beginning of a silent file) plays. The case where the participant makes a headturn actually represents two different possible trial outcomes, depending on which audio file was playing. If the trial audio was chosen to be the change audio, this represents a _hit_, and we should present the reward. But if it was the silent file, this is a _false alarm_, and we _shouldn't_ present the reward.

Because the audio and side name were paired originally, so that the change audio went with the side of the reward (`LEFT`) and the silent file went with the empty channel (`RIGHT`), we don't actually have to differentiate between these two outcomes in order to correctly reward or not reward the headturn. The tag `reward_test` contains the appropriate side name so that if the change audio was chosen, the `LEFT` channel reward will now turn on, but if it was a control trial, nothing will visibly happen, and we'll simply wait a few seconds before we can start another trial.

```
# hit or false alarm
STEP 32
LIGHT reward_test ON
UNTIL TIME 5000

STEP 33
Trial End
LIGHT reward_test OFF
AUDIO LEFT OFF
UNTIL TIME 100 JUMP STEP 35
```

`STEP 34` is only reached when the participant does _not_ make a headturn shortly after the start of a trial. This behavior could be a _miss_ if the change audio signal was actually present, or it could be a _correct rejection_ if it wasn't. Although when we ultimately analyze data we'll consider the first outcome as an incorrect response on the trial and the second as a correct one, we don't need to differentiate between these possible situations now, because neither results in the presentation of a reward. In both cases, we simply need to end the trial and turn off whatever audio had been playing.

```
# miss or correct rejection
STEP 34
Trial End
AUDIO LEFT OFF
UNTIL TIME 100
```

Regardless of which "branch" was taken to handle the outcome of the trial, we now end up at `STEP 35` (there was a `JUMP` to here from the end of the step that handled hits and false alarms). We could have a larger delay specified here if we wanted to make sure there was a certain minimum time in between trials, and in the next step we'll loop back to `STEP 30` to run more test trials. This one will run a total of 8 test trials.

```
STEP 35
UNTIL TIME 100

STEP 36
LOOP STEP 30
UNTIL 7 TIMES
```

When all eight test trials have been executed and the loop is done, the study is over! We'll end the test phase and turn off the background noise that's been playing from `CENTER` since the beginning.

```
STEP 37
Phase End
AUDIO CENTER OFF
```

See the [resources page ](../../support/resources)to download a copy of this protocol.
