Newer
Older
{
"cell_type": "markdown",
"source": [
"Import the necessary modules. We need stationarity from ntrfc and some other modules for the definition of a signal and for rendering a plot"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 9,
"outputs": [],
"source": [
"from ntrfc.timeseries.stationarity import stationarity\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"Lets define a signal generator. We want to generate a signal with some noise, an initial transient and a constant deterministic fluctuation."
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 10,
"outputs": [],
"source": [
"def signalgen_abatingsine(amplitude, noiseamplitude, frequency, mean, abate, time):\n",
" resolution = 2048\n",
" step = (resolution * frequency ** -1) ** -1\n",
"\n",
" times = np.arange(0, time, step)\n",
" noise = np.random.normal(-1, 1, len(times)) * noiseamplitude\n",
"\n",
" values = amplitude * np.sin(frequency * (2 * np.pi) * times) + mean + np.e ** -(times * abate) + noise\n",
" return times, values"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"Lets define the input arguments for the signal generator and lets generate a signal."
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
{
"cell_type": "code",
"execution_count": 11,
"outputs": [],
"source": [
"test_amplitudes = 0.1\n",
"test_noiseamplitude = 0.01\n",
"test_frequencies = 6\n",
"test_times = 40\n",
"test_mean = -1\n",
"test_abate = 1\n",
"\n",
"\n",
"timesteps, values = signalgen_abatingsine(amplitude=test_amplitudes, noiseamplitude=test_noiseamplitude,\n",
" frequency=test_frequencies, mean=test_mean, time=test_times,\n",
" abate=test_abate)\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
},
{
"cell_type": "markdown",
"source": [
"Lets compute the index of the stationary timestep."
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
"outputs": [],
"source": [
"stationary_timestep = stationarity(timesteps, values)\n",
"\n",
"well_computed_stationarity_limit = -np.log(0.05) / abate\n",
"well_computed_stationary_time = timesteps[-1] - well_computed_stationarity_limit\n",
"stationary_time = timesteps[-1] - stationary_timestep\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
{
"cell_type": "markdown",
"source": [
"Lets plot the result"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%% md\n"
}
}
},
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
{
"cell_type": "code",
"execution_count": null,
"outputs": [],
"source": [
"plt.figure()\n",
"plt.plot(timesteps, values)\n",
"plt.axvline(stationary_timestep, color=\"green\")\n",
"plt.show()\n"
],
"metadata": {
"collapsed": false,
"pycharm": {
"name": "#%%\n"
}
}
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 2
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython2",
"version": "2.7.6"
}
},
"nbformat": 4,
"nbformat_minor": 0
}