Page 1 of 1

introduce a specific type of noise

Posted: Fri Jun 22, 2007 2:18 pm
by neurite
I would like to introduce a very specific type of noise to one of my channels. From the code below, I essentially need to add the variable 'dpz' to 'm' at very time step. I thought the code would work, but it doesn't. Please advise.

Code: Select all

NEURON {
	SUFFIX nap_ch
	USEION na READ ena WRITE ina
	RANGE gnabar, gna, ina
	GLOBAL m_inf
}

UNITS {
	(S) = (siemens)
	(mV) = (millivolt)
	(mA) = (milliamp)
}

PARAMETER { 

	gnabar = 0.0001 (S/cm2) 
	ena = 45 (mV)
}

ASSIGNED {
	v (mV)
	ina (mA/cm2)
	gna (S/cm2)
	m_inf
	
}

STATE { m }

BREAKPOINT {
	SOLVE states METHOD cnexp
	
	gna = gnabar * m
	ina = gna * (v - ena)
}


INITIAL {
	m = m_inf
}

DERIVATIVE states {
	rates(v)
	noise(m)
	UNITSOFF
	m' = (m_inf - m)/0.1 
	UNITSON
}



PROCEDURE rates(v (mV)) {
	
	m_inf = (1/(1+exp(-(v+50)/3.0 (mV))))
}

PROCEDURE noise(m) {

	LOCAL randflag, dpa, dpb, dpz

	:generate the random term
	srand ( time(NULL) )
	

	:generate randomflag between 0 and 1
	randflag = roundf(rand()/(2^31-1))
	
	if (randflag == 1){
		dpa = cos(2*(22/7)*rand()/(2^31-1))
	}
	
	if (randflag == 0){
		dpa = sin(2*(22/7)*rand()/(2^31-1))
	}


	dpb = -2*.001*(m_inf + m - 2*m_inf*m)/(300*.1)

	dpz = dpa*(dpb*log(rand()/(2^31-1)))^(1/2)

	m = m + dpz 
	
	if (m<0)
	{
             m=0
        }
           
        if (m>1)
	{
             m=1
        }
}

Posted: Wed Jun 27, 2007 11:11 am
by hines
I assume you are using mswin since
on that machine you can only call
functions in the nrniv.exe file that
are listed in an export file and srand
and rand do not exist in the executable anyway. So you need to use either the built-in random generators, scop_rand, or Random
(for the latter, see src/nrnoc/netstim.mod for how to connect a hoc Random instance for use in a mod file) or else put a c implementation of a random function into a VERBATIM block in the mod file. There are examples of this in ModelDB. Search for drand48 or srand48.

Posted: Thu Jun 28, 2007 10:34 am
by neurite
thanks for the pointer Michael, but it still doesn't really address the issue of adding an varying value to m at every time step.

Re: introduce a specific type of noise

Posted: Thu Jul 10, 2008 3:19 pm
by patoorio
Why don't you just do something like

Code: Select all

DERIVATIVE states { 
rates(v) 
dpz=whatever-random-function-you-want
UNITSOFF 
m' = (m_inf - m + dpz)/0.1 
UNITSON 
} 
instead of 'manually' adding the random value in a separate procedure?