Skip to content

How do I calibrate my whisker stimulus?

Axel edited this page Oct 23, 2024 · 4 revisions

Stimulus Calibration

The script calibration_coil.m sets up a data acquisition session to calibrate stimuli and measure the magnetic flux response using a coil and teslameter. The results, including stimuli and flux data, are saved. This is done typically before each whisker behavioural session for each mouse.

Main Workflow

1. Session Setup

The data acquisition session is created using the NI-DAQ interface:

  • Analog Output Channel: Sends stimulus (voltage) to the amplifier.
  • Analog Input Channel: Reads input (voltage) from the teslameter/displacement sensor.
session = daq.createSession('ni');
addAnalogOutputChannel(session,'Dev2','ao0', 'Voltage');
addAnalogInputChannel(session,'Dev2','ai6', 'Voltage');

Connect the teslameter as per the session in your file. Power the teslameter with the supplied cable. Fix the probe using Thorlabs post holders and place the probe where the mouse whisker/particle would be.

There should be one teslameter per experimental room, at least. Teslameter specs - for orders, in case one is broken - can be found on the Projekt Electronik box or on the lab Slack. Teslameter probes are quite fragile, so be careful!

2. Directory Setup

Directories are created to store calibration data and results.

dest_path = 'C:\Users\bechvila\Desktop\Behaviour_repo\calibration';
mouse_name = 'PB181';
date = datetime('today', 'Format', 'yyyyMMdd');

Note: if you repeat the calibration of the same mouse on the same day, the previous calibration files will be overwritten.

3. Stimulus Definition

The script defines different stimulus profiles, such as biphasic_square and biphasic_hann, based on the stim_name. Each stimulus is defined by amplitude, duration, and shape.

Example for Biphasic Hann Window (3 ms):

stim_amp_volt = 2.9;
stim_duration_up = 1.5;
impulse_up = tukeywin(stim_duration_up*sr,1);
impulse_down = -tukeywin(stim_duration_down*sr-5,1);

4. Stimulus Execution and Data Collection

The script runs multiple trials, sends the stimulus through the coil, and collects the magnetic flux data for each trial.

for itrial=1:n_trials
   queueOutputData(session, stim');
   d = startForeground(session);
   flux_data(itrial,:) = d(:,1);
end

5. Data Analysis

For each trial, the maximum magnetic flux amplitude is recorded and converted to millitesla (mT). The absolute value is used in case the calibration was performed using the probe upside down.

pks = max(abs(flux_data(itrial,:)));
trials_stim_amp_millitesla(itrial) = pks * 100;

6. Plotting & Saving Results

The script plots both the stimulus and the recorded magnetic flux. It saves the data and the generated plots in the specified folder.

saveas(gcf, figure_file, 'png');
save(data_file, 'stim', 'flux_data', ...);

Here's an example figure below.


Key Variables

  • session_sampling_rate: Defines the sampling rate for the data acquisition session (in Hz).
  • stim_name: Defines the stimulus shape (e.g., biphasic_hann_3ms).
  • n_trials: Number of trials to run for each stimulus.
  • flux_data: Collected magnetic flux data across trials.
  • stim_amp_volt_list: List of stimulus amplitudes used in psychophysical stimuli.

Supported Stimuli

Stimulus Name Description
biphasic_square_1ms Biphasic square pulse, 1 ms duration
biphasic_square_3ms Biphasic square pulse, 3 ms duration
biphasic_hann_3ms Biphasic Hann window, 3 ms duration
biphasic_hann_3ms_psy Biphasic Hann with varying amps for psychophysics

etc. Just add any new one in the script.


Outputs

  1. Stimulus Data (stim): Array of stimulus voltage values.
  2. Magnetic Flux Data (flux_data): Recorded magnetic flux across trials.
  3. Saved Files:
    • .png: Plot showing stimulus and magnetic flux.
    • .mat: MATLAB file containing calibration data.

Usage Example

Uncomment the stimulus name you want to use and run the script.

stim_name = 'biphasic_hann_3ms';
n_trials = 5;
% Run calibration

After calibration, copy the calibration file content in the behavioural session output folder, i.e. at the same level as result.csv.