A sibling to the MRI, PET, EEG and MEG simulators. Describe a recording in a few lines, shine near-infrared light through scalp, skull and cortex, catch what comes back, and turn it into oxy- and deoxyhaemoglobin. Then let the heartbeat, the breath, blood-pressure waves, the scalp, a loose optode and the room lights in, and do what an fNIRS lab does: check, correct, filter, regress, average and model. The simulator always knows what the cortex really did, so every answer can be checked.
Skin, bone and brain are nearly transparent to near-infrared light between about 650 and 950 nm, but they scatter it fiercely: a photon changes direction every tenth of a millimetre. Light shone into the scalp at one point therefore diffuses through the head, and a little of it, a billionth or so, comes back out a few centimetres away. On its way it passes through the cortex, where oxyhaemoglobin and deoxyhaemoglobin absorb it, each with its own colour. When neurons fire, blood flow rises and the mix changes, and so does the light that comes out. An fNIRS system is a set of light sources at two or more wavelengths, optodes held against the scalp by a cap, detectors sensitive enough to see a few picowatts, and a way of multiplexing so each detector knows which source its light came from. Click a part of the system or a stage below.
A laser diode emits a line a nanometre or two wide; an LED spreads over 30 to 50 nm. The conversion to haemoglobin uses the extinction coefficients at the nominal wavelength, but an LED's photons sample the spectrum across its whole band, weighted toward wherever haemoglobin absorbs least. Where the spectrum is steep (below 750 nm for deoxyhaemoglobin) the effective coefficient differs from the nominal one by several percent, and the error leaks between HbO and HbR. Lasers need fibres and safety interlocks; LEDs can sit on the scalp, which is why most wearable systems use them. Either way the power at the skin is kept to a few milliwatts per square millimetre.
The cap holds sources (squares) and detectors (circles) in a fixed layout over a 10-20 position. A channel is a source-detector pair close enough to see each other's light, usually 3 cm apart, and its signal comes from the tissue between them. The small circles are short-separation detectors, 8 mm from a source, that see almost only scalp.
Light has to get from the optode tip into the skin and back out at the detector. Hair in between blocks it, scatters it and, if dark, absorbs it: melanin absorbs more strongly at shorter wavelengths, so dark hair costs more light at 760 nm than at 850. Each optode is pushed through the hair and wiggled into place, which is why setting up a cap takes longer than recording with it. The numbers are the light reaching a 3 cm detector through two optodes, relative to bare skin.
Absorption coefficient μa (how often light is absorbed) and reduced scattering coefficient μs′ (how often it effectively changes direction) of each layer, computed from its blood, water and background content. Scattering is a hundred times stronger than absorption everywhere except in the cerebrospinal fluid, a clear layer through which light channels sideways. The Light in tissue tab follows photons through these layers.
The detected power at each separation for a 10 mW source (adult head, 850 nm, bare skin). An 8 mm channel and a 4 cm channel on the same detector differ by four orders of magnitude, so a detector must handle microwatts without saturating and picowatts without drowning in its own noise. A photodiode is linear over a huge range but noisy; an avalanche photodiode multiplies its photocurrent internally; a silicon photomultiplier counts single photons but saturates early, which makes short channels hard. The shaded band is where a detector gives a usable signal (signal-to-noise above 100 at 10 Hz).
Continuous wave measures only how much light arrives. Many pairs of absorption and scattering give the same intensity (the curve), so CW cannot tell them apart and reports only changes, through a pathlength it must assume (the DPF). It is cheap, simple and the basis of most fNIRS systems, and of this simulator.
Frequency domain modulates the source at around 100 MHz. The light arrives smaller (demodulated) and late (phase shifted); the phase is the mean time of flight, so it measures the pathlength, and with intensity it separates μa from μs′ to give absolute concentrations.
Time domain sends picosecond pulses and times each returning photon. The distribution of times of flight holds everything: its decay gives μa, its rise μs′, and photons that arrive late have travelled further and deeper, so gating on late photons rejects the scalp. The most informative, and the most expensive.
Every fNIRS study can be written down as a handful of decisions: which wavelengths, how fast to sample and how to multiplex; where the probe goes and how its sources and detectors are laid out, including short channels; whose head it is; what the cortex does and when; what the body does anyway; what goes wrong; and how the data will be analysed. The program on the left is exactly that, in a small language. Change a line and press Build recording: the simulator records a new session and every other tab updates. The examples are a good place to start. The language is described under the editor.
A program is a few blocks in braces. Inside a block each statement is a keyword and its values. A number takes a unit
(nm, Hz, bpm, /min, s, ms, cm, mm,
uM, mW, nW, deg) or a %, and the unit says what the number is, so
cardiac 70 bpm 1 uM and cardiac 1 uM 70 bpm mean the same. In a run of numbers the last unit applies to all:
bandpass 0.01 0.2 Hz. Line breaks are only spacing, and # starts a comment.
| Statement | Meaning |
|---|---|
| recording { ... } | |
| wavelengths 760 850 nm | One, two or three wavelengths between 600 and 1000 nm. One is allowed so you can watch the conversion fail. |
| rate 10 Hz | Sampling rate, 0.5 to 50 Hz. |
| multiplex time | frequency | none | How the sources are told apart: in turn with a dark slot, by modulation and lock-in detection, or not at all. |
| source laser | led power 10 mW | Source type (an LED is 35 nm wide) and power at each source. |
| detector photodiode | apd | sipm | Detector type, which sets the noise floor and the saturation level. |
| system cw seed 1 | The recording is always continuous wave; fd and td are shown on the System tab. The seed fixes every random choice. |
| probe over C3 { ... } | |
| layout motor | forehead | A ready-made array: four sources and four detectors on a 3 cm checkerboard, or a forehead strip. Each comes with short channels. |
| source S1 at -3 1.5 cm detector D1 at 0 1.5 cm | Your own optodes on the probe patch, in cm from its centre (x to the right, y toward the nose). |
| short S1 8 mm [90 deg] short off | A short-separation detector beside a source, at an optional angle; short off removes them. |
| channels 3.5 cm channel S1 D1 | Every pair from 1.5 cm up to this distance is a channel, or list the channels yourself. |
| rotate 30 deg | Turn the probe on the head. over takes any of the 10-20 positions drawn on the cap. |
| head adult | thick | infant { ... } | |
| hair none | light | dense | dark | Hair under the optodes: less light, more at short wavelengths when dark, and more variable from optode to optode. |
| scalp 5 mm skull 7 mm csf 2 mm gray 4 mm | Override a layer's thickness; white matter fills the rest. |
| activation name { ... } | |
| at 0 0 cm under S3 D1 | Where the active cortex lies under the probe: a position, or the midpoint of a channel. |
| depth 15 mm radius 8 mm | Depth of its centre below the scalp (default: just inside the gray matter) and its size. |
| flow 50% coupling 2.5 dip | Peak rise in blood flow for a sustained block; the ratio of flow change to oxygen-consumption change; an initial dip. |
| condition tap 1 | Gain for each condition; with none listed, every condition drives it equally. |
| pair name { ... } | |
| region A { under S1 D1 } region B { at 3 0 cm } | Two regions with shared spontaneous activity, for connectivity. |
| coupling 0.7 fluctuation 15% band 0.01 0.1 Hz | Fraction of activity they share, size of the flow fluctuations, and their frequency band. |
| timeline { ... } | |
| rest 30 s block tap 20 s | A rest period, or a single block of a condition. |
| blocks 10 on 20 s off 20 s jitter 5 s { condition tap } | A block design. With several conditions, they appear in random, alternate or sequence order. |
| events 40 isi 12 s jitter 6 s duration 1 s { condition a 50% ... } | An event-related design: a trial every isi plus a random 0 to jitter. |
| physiology { ... } | |
| cardiac 72 bpm 1 uM respiration 15 bpm 0.35 uM | Heart rate and breathing, with their peak-to-peak size in the scalp. |
| mayer 0.1 Hz 0.6 uM drift 0.8 uM | Blood-pressure (Mayer) waves, and spontaneous low-frequency fluctuations. |
| taskbp 1.5 uM [2 s] | The task raises blood pressure and scalp blood flow: a response in the scalp that mimics activation. Optional delay. |
| heterogeneity 15% brain 100% | How much the scalp signals vary across the probe, and how much systemic physiology reaches the brain. |
| … off | Declare a signal but start with it off. Unlisted signals are off when the block is present; all are switchable on the Confounds tab. |
| artifacts { ... } | |
| spikes 2 /min 50% | Motion spikes: sudden changes in optode coupling that recover within seconds. |
| shifts 3 30% | Baseline shifts: an optode slips and stays slipped. |
| poor D3 2% | One optode that barely touches the scalp (2% of normal coupling). |
| ambient 3 nW flicker 120 Hz change 200 s | Room light reaching the detectors, flickering at twice the mains frequency, tripled from a time on. |
| analysis { ... } | |
| quality sci 0.75 cv 15% | Reject channels whose scalp coupling index is below, or coefficient of variation above, these thresholds. |
| motion none | tddr | spline | Motion correction: none, temporal derivative distribution repair, or spline interpolation. |
| bandpass 0.01 0.2 Hz highpass lowpass | Zero-phase Butterworth filters on optical density. |
| dpf 6 | dpf 6.3 5.2 | dpf age 30 | dpf model | Differential pathlength factor: one value, one per wavelength, from age, or the true one from the light model. |
| short off | nearest | mean glm | before | Short-channel regression: which short channel, and whether its weight is estimated inside the GLM or subtracted first. |
| epoch -5 25 s baseline -5 0 s | Block-averaging window and baseline. |
| hrf canonical | gamma derivative on noise ar | ols | GLM: response shape, an added temporal derivative, and the noise model. |
Each photon takes a random walk: a straight step, a new direction, another step, until it is absorbed or escapes. Most escape close to the source. The few that reach a detector centimetres away must have wandered deep enough to get there and back, and the region they visited, weighted by how likely each route is, is shaped like a banana between source and detector. Its depth grows with separation, roughly a third to a half of it, but every extra centimetre costs about a factor of ten in light. A short channel sees the scalp; a 3 cm channel reaches the cortex but still spends most of its path in scalp and skull; a 5 cm channel goes deeper still but gets almost no light. The orange paths are individual photons from a Monte Carlo random walk; the shaded banana is the sensitivity from diffusion theory, which the photons fill in as they accumulate.
Top: detected power from a 10 mW source on a log scale, with the noise floor of an avalanche photodiode. Bottom: the share of each channel's path that lies in the brain (gray and white matter). The marker is the current separation. Separations of 3 to 4 cm are the compromise every adult probe makes; in an infant the brain is so close that 2 cm already reaches it.
Top: mean pathlength in each layer, from diffusion theory and from the photons detected so far (which agree to within the noise of the count and the approximations of each method). Bottom: how sensitivity is spread over depth for this separation and for the short channel. The modified Beer-Lambert law treats the whole path as if it were in the cortex; this is the partial volume it ignores.
The arrival times of the detected photons (pathlength divided by the speed of light in tissue, 21 cm/ns). Early photons took short, shallow paths; late photons wandered long and deep. Tick "only late photons" to draw only those after the gate: their paths dive into the brain. This is how time-domain systems separate scalp from cortex with a single source-detector pair.
A change in light at one wavelength could be a change in oxyhaemoglobin, a change in deoxyhaemoglobin, or any mix of the two. Measure at a second wavelength where the two absorb in a different ratio and you have two equations in two unknowns, which can be solved. How well depends on how different the ratios are. Below the isosbestic point near 800 nm, deoxyhaemoglobin absorbs more; above it, oxyhaemoglobin does. One wavelength on each side gives well-separated equations; two on the same side give nearly parallel ones, and the solution amplifies noise and mixes the two. Below 650 nm haemoglobin absorbs so strongly that little light survives; above 950 nm water does. Between lies the near-infrared window.
For every pair of wavelengths, how much measurement noise is amplified in the recovered HbO and HbR, relative to the best pair, at a 3 cm separation. Dark is good. The diagonal is useless (one wavelength twice), and so is anything with both wavelengths above about 800 nm. The cross is the current pair.
A block response (HbO up, HbR down, dashed: the truth) passed through the forward model at the chosen wavelengths, with noise added to the optical densities, then converted back. With a well-conditioned pair the recovered curves follow the truth; with a poor pair the noise is amplified and a wrong pathlength ratio makes some of HbO appear as HbR and vice versa (crosstalk), even with no noise at all. Left: the common 760 / 850 nm pair; right: your choice, with exactly the same noise.
The instrument reports intensity. Taking minus the logarithm of the intensity relative to its baseline gives the optical density change, which for small changes is proportional to the change in absorption along the path. The modified Beer-Lambert law says how: ΔOD(λ) = [εHbO(λ) ΔHbO + εHbR(λ) ΔHbR] × d × DPF(λ), where d is the source-detector distance and the differential pathlength factor says how much longer than d the light really travelled. With two wavelengths that is two equations, solved for ΔHbO and ΔHbR. A continuous-wave system cannot measure the DPF, so it is assumed, and the law also assumes the change fills the whole path, when in fact it is confined to a patch of cortex that the light only grazes.
Click any plot to move the cursor; the equation below uses the values there. "Model" uses the true pathlength from the light model, which no real continuous-wave instrument knows. I0 is the mean intensity of the whole recording, so rest periods sit a little below zero.
Each channel is sensitive to a banana-shaped volume, and only the deep end of the banana reaches the brain. A patch of active cortex shows up in a channel only as much as the two overlap: move the activation sideways and it leaves one channel and enters another; push it deeper and it fades from all of them; thicken the skull and the whole brain recedes. The colours on the probe are each channel's sensitivity to the region, the centimetres of mean path that lie inside it. Drag the region on the probe, or use the sliders, then press Apply to record with it.
Bars: each channel's sensitivity to the region at 850 nm (cm of path inside it) and, as a percentage, the share of its whole path that is. The expected measured HbO change is roughly the true local change times that share divided by the share the Beer-Lambert law assumes (all of it).
The light that reaches a detector has crossed the scalp twice, and the scalp is full of blood vessels that pulse with every heartbeat, swell with every breath and wave with the blood pressure. Worse, the scalp's blood flow responds to the task itself, through the blood pressure, so its changes are time-locked to the stimulus and look like activation. On top of the body come the instrument's problems: optodes that move, slip or barely touch the skin, and light from the room. Each is switchable here without changing anything else in the recording, so you can see its fingerprint alone or in company. The other tabs update as you switch.
For every channel and every wavelength the instrument writes one number per sample: the light that arrived. Before any processing you can already read a lot from it: the heartbeat riding on every good channel, the slow waves, the steps and spikes of motion, a channel with no light at all. The haemoglobin traces here use the plain Beer-Lambert conversion with no filtering or correction; the Processing tab does the rest. Click a channel on the map to show it.
Most analyses follow the same steps: reject channels that are not really measuring tissue, convert intensity to optical density, repair motion artifacts, filter out the heartbeat and the slowest drifts, convert to haemoglobin, and remove what the short channels say came from the scalp. Each step has a choice and a cost. Switch them here and watch each one's effect on the selected channel; the Averaging and GLM tab uses the result.
A single trial's response is a fraction of a micromolar, smaller than the heartbeat and the Mayer waves. Averaging trials time-locked to the stimulus shrinks everything that is not time-locked by the square root of the number of trials, so the canonical shape emerges: HbO rising over five or six seconds, HbR falling by a third as much, both returning after the stimulus ends. What is time-locked survives averaging, including the scalp's response to the task. The GLM does the same job with a model, fitting a predicted response shape to the whole time series at once, which copes with overlapping trials and can include the short channel as a regressor.
The design matrix, one column per regressor and time running down: the task regressors (stimulus timing convolved with the response shape, scaled to a peak of 1 so that β is the response size in µM), slow cosine drifts and a constant. The model is fitted to motion-corrected but unfiltered data, with the drifts doing the high-pass and an autoregressive noise model of up to 4 s of lags; the short channel, when used, is first subtracted with the weight found on the Processing tab.
fNIRS and BOLD fMRI watch the same thing: active neurons trigger a rise in blood flow larger than the rise in oxygen use, so the blood in and downstream of the active cortex becomes more oxygenated. More oxygenated blood means more HbO and less HbR. fNIRS measures both changes directly, optically. fMRI measures HbR indirectly: deoxyhaemoglobin is paramagnetic and dephases the MR signal, so less of it means more signal. The same balloon model drives both here, from one neural event: flow, blood volume and oxygen use in, HbO, HbR, total haemoglobin and BOLD out. Then each modality samples it in its own way.
The same slab of head. fMRI samples every 2.5 mm voxel (green grid, one filled in the cortex) through the whole depth; one fNIRS channel (orange) sees a banana a centimetre or two deep, blurred over a few centimetres, and nothing below it.
| fNIRS | BOLD fMRI | |
|---|---|---|
| Measures | Changes in HbO and HbR (and their sum, HbT), optically, in µM | Mostly the change in HbR content, through its magnetic effect, in % signal change |
| Sign of activation | HbO up, HbR down | Signal up (because HbR went down) |
| Sampling | 10 Hz or faster; the heartbeat is resolved | One volume every 0.5 to 3 s; the heartbeat aliases |
| Spatial resolution | 1 to 3 cm, set by the banana | 1 to 3 mm voxels (the vessels blur it a little) |
| Depth | Outer 1 to 2 cm of cortex only | The whole brain |
| Absolute or relative | Relative (CW): needs an assumed pathlength | Relative: % change from baseline |
| Main confounds | Scalp blood flow, hair, coupling, motion | Head motion, physiology, susceptibility artifacts |
| Setting | Portable, quiet, tolerant of movement; infants, walking, conversation | Lying still in a loud, strong magnet |
| Cost | Tens of thousands of dollars | Millions of dollars, and a building |
A sparse probe with one separation gives one number per channel: a map at best (topography), blurred over centimetres and with no depth. A high-density array overlaps many channels at several separations, so every point in the tissue is seen by many bananas of different depths. Writing the sensitivity of every channel to every voxel as a matrix, the measurements are that matrix times the absorption change, and inverting it, with regularization because there are far more voxels than channels, gives a three-dimensional image. Short separations pin down the shallow part, long ones the deep part. This is what modern HD-DOT systems do with hundreds of channels.
Built for NBL 425/625, Methods in Human Neuroimaging. See also the course's Beer-Lambert unmixer, photon transport and short-channel regression and banana path demos.