[go: up one dir, main page]

File: Lorenz.h

package info (click to toggle)
caps 0.3.0-3
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 888 kB
  • ctags: 1,273
  • sloc: cpp: 9,837; ansic: 584; makefile: 62
file content (108 lines) | stat: -rw-r--r-- 2,037 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
	dsp/Lorenz.h
	
	Copyright 2001-4 Tim Goetze <tim@quitte.de>
	
	http://quitte.de/dsp/

	Lorenz fractal.

*/
/*
	This program is free software; you can redistribute it and/or
	modify it under the terms of the GNU General Public License
	as published by the Free Software Foundation; either version 2
	of the License, or (at your option) any later version.

	This program is distributed in the hope that it will be useful,
	but WITHOUT ANY WARRANTY; without even the implied warranty of
	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
	GNU General Public License for more details.

	You should have received a copy of the GNU General Public License
	along with this program; if not, write to the Free Software
	Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
	02111-1307, USA or point your web browser to http://www.gnu.org.
*/

#ifndef _DSP_LORENZ_H_
#define _DSP_LORENZ_H_

namespace DSP {

class Lorenz
{
	public:
		double x[2], y[2], z[2];	
		double h, a, b, c;
		int I;

	public:
		Lorenz()
			{
				h = 0.001;
				a = 10.0;
				b = 28.0;
				c = 8.0 / 3.0;
			}

		/* rate is normalized (0 .. 1) */
		void set_rate (double r)
			{
				h = max (.0000001, r * .015);
			}

		void init (double _h = .001, double seed = .0)
			{
				I = 0;

				x[0] = .1 + seed - frandom() * .1;
				y[0] = 0;
				z[0] = 0;

				/* progress quickly to get a 'stable' system */
				h = .001; 
				
				int n = 10000 + min ((int) (10000 * seed), 10000);
				for (int i = 0; i < n; ++i)
					step();

				h = _h;
			}

		d_sample get()
			{
				step();
				return .5 * get_y() + get_z();
			}

		void step()
			{
				int J = I ^ 1;

				x[J] = x[I] + h * a * (y[I] - x[I]);
				y[J] = y[I] + h * (x[I] * (b - z[I]) - y[I]);
				z[J] = z[I] + h * (x[I] * y[I] - c * z[I]);

				I = J;
			}

		double get_x()
			{
				return .024 * (x[I] - .172);
			}

		double get_y()
			{
				return .018 * (y[I] - .172);
			}

		double get_z()
			{
				return .019 * (z[I] - 25.43);
			}
};

} /* namespace DSP */

#endif /* _DSP_LORENZ_H_ */