# How to record xi?

**URL:** <https://brian.discourse.group/t/how-to-record-xi/1185>\
**Category:** Support\
**Created:** [4 April 2024 01:50 UTC](https://brian.discourse.group/t/how-to-record-xi/1185 "2024-04-04T01:50:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cclo](https://avatars.discourse-cdn.com/v4/letter/c/eada6e/32.png) [@cclo](https://brian.discourse.group/u/cclo)\
**Post date:** [4 April 2024 01:50 UTC](https://brian.discourse.group/t/how-to-record-xi/1185/1 "2024-04-04T01:50:43Z")

</div>

# Description of problem

I added the xi variable to my neuron equation to generate noisy membrane potentials.  
I would like to record the xi values as a function of time and plot it in a graph, but I failed.

If xi is not recordable, is there any other way to add a noisy current to a neuron and record the noise term?

# Minimal code to reproduce problem

```python
eqs = '''
dv/dt = (Iint-(v-v0))/tau + sigma*xi*tau**-0.5: 1 (unless refractory)
ref: second
'''
G = NeuronGroup(Nneuron, eqs, threshold='v > v_threshold', reset='v = v_reset', refractory='ref', method='Euler')
M = StateMonitor(G, ('v', 'xi'), record=True) # record the membrane potential
run(1000*ms)
plot(M.t/ms, M.xi[0], color='black')
show()

```

# Expected output (if relevant)

A plot with a Gaussian distributed noise as a function of time

# Actual output (if relevant)

A flat line of y=0

---

<div class="post-metadata">

**Author:** ![mstimberg](https://yyz2.discourse-cdn.com/free1/user_avatar/brian.discourse.group/mstimberg/32/11_2.png) [@mstimberg](https://brian.discourse.group/u/mstimberg)\
**Post date:** [8 April 2024 14:05 UTC](https://brian.discourse.group/t/how-to-record-xi/1185/2 "2024-04-08T14:05:15Z")

</div>

Hi @cclo. I agree that this is not ideal – in particular, you should get an error message when trying to record from `xi`. The reason why this isn’t possible is that internally, there is no variable named `xi`, it is directly taken in charge as part of the numerical integration process. As an alternative, you can replace it by a variable that does the same thing manually, and which you can then record in the usual way:

```python
eqs = '''
dv/dt = sigma*noise*tau**-0.5: 1 (unless refractory)
noise = randn()/sqrt(dt) : second**-0.5 (constant over dt)
...
'''

```

The value of `noise` might still not quite what you expect, since the values will depend on the `dt` that is used for the simulation. This is correct, though (see [Models and neuron groups — Brian 2 2.6.0 documentation](https://brian2.readthedocs.io/en/stable/user/models.html#time-scaling-of-noise) for a short explication). If you are only interested in the values of the random generator you could of course reformulate everything as, for example:

```python
eqs = '''
dv/dt = sigma*noise/sqrt(dt)*tau**-0.5: 1 (unless refractory)
noise = randn() : 1 (constant over dt)
...
'''

```

You might also be interested in these comments I made in other discussions threads:

- [Implementation of stochastic noise in a Hodgkin-Huxley model but as a current - #10 by mstimberg](https://brian.discourse.group/t/implementation-of-stochastic-noise-in-a-hodgkin-huxley-model-but-as-a-current/787/10)
- [Additive noise implementation - #2 by mstimberg](https://brian.discourse.group/t/additive-noise-implementation/1170/2)
