|
| 1 | +# -*- coding: utf-8 -*- |
| 2 | +# MLC (Machine Learning Control): A genetic algorithm library to solve chaotic problems |
| 3 | +# Copyright (C) 2015-2017, Thomas Duriez (thomas.duriez@gmail.com) |
| 4 | +# Copyright (C) 2015, Adrian Durán (adrianmdu@gmail.com) |
| 5 | +# Copyright (C) 2015-2017, Ezequiel Torres Feyuk (ezequiel.torresfeyuk@gmail.com) |
| 6 | +# Copyright (C) 2016-2017, Marco Germano Zbrun (marco.germano@intraway.com) |
| 7 | +# Copyright (C) 2016-2017, Raúl Lopez Skuba (raulopez0@gmail.com) |
| 8 | +# |
| 9 | +# This program is free software: you can redistribute it and/or modify |
| 10 | +# it under the terms of the GNU General Public License as published by |
| 11 | +# the Free Software Foundation, either version 3 of the License, or |
| 12 | +# (at your option) any later version. |
| 13 | +# |
| 14 | +# This program is distributed in the hope that it will be useful, |
| 15 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | +# GNU General Public License for more details. |
| 18 | +# |
| 19 | +# You should have received a copy of the GNU General Public License |
| 20 | +# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 21 | + |
| 22 | +# -*- coding: utf-8 -*- |
| 23 | +# MLC (Machine Learning Control): A genetic algorithm library to solve chaotic problems |
| 24 | +# Copyright (C) 2015-2017, Thomas Duriez (thomas.duriez@gmail.com) |
| 25 | +# Copyright (C) 2015, Adrian Durán (adrianmdu@gmail.com) |
| 26 | +# Copyright (C) 2015-2017, Ezequiel Torres Feyuk (ezequiel.torresfeyuk@gmail.com) |
| 27 | +# Copyright (C) 2016-2017, Marco Germano Zbrun (marco.germano@intraway.com) |
| 28 | +# Copyright (C) 2016-2017, Raúl Lopez (raulopez@gmail.com) |
| 29 | +# |
| 30 | +# This program is free software: you can redistribute it and/or modify |
| 31 | +# it under the terms of the GNU General Public License as published by |
| 32 | +# the Free Software Foundation, either version 3 of the License, or |
| 33 | +# (at your option) any later version. |
| 34 | +# |
| 35 | +# This program is distributed in the hope that it will be useful, |
| 36 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 37 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 38 | +# GNU General Public License for more details. |
| 39 | +# |
| 40 | +# You should have received a copy of the GNU General Public License |
| 41 | +# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 42 | + |
| 43 | +# -*- coding: utf-8 -*- |
| 44 | +# MLC (Machine Learning Control): A genetic algorithm library to solve chaotic problems |
| 45 | +# Copyright (C) 2015 Thomas Duriez (thomas.duriez@gmail.com), Adrian Durán (adrianmdu@gmail.com), |
| 46 | +# Ezequiel Torres (ezequiel.torresfeyuk@gmail.com), Marco Germano (marco.germano@intraway.com), |
| 47 | +# Raul Lopez (raulopez@gmail.com) |
| 48 | + |
| 49 | +# This program is free software: you can redistribute it and/or modify |
| 50 | +# it under the terms of the GNU General Public License as published by |
| 51 | +# the Free Software Foundation, either version 3 of the License, or |
| 52 | +# (at your option) any later version. |
| 53 | + |
| 54 | +# This program is distributed in the hope that it will be useful, |
| 55 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 56 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 57 | +# GNU General Public License for more details. |
| 58 | + |
| 59 | +# You should have received a copy of the GNU General Public License |
| 60 | +# along with this program. If not, see <http://www.gnu.org/licenses/> |
| 61 | +import numpy as np |
| 62 | +import matplotlib.pyplot as plt |
| 63 | + |
| 64 | +# Sine amplitud |
| 65 | +A = 1 |
| 66 | +# Offset |
| 67 | +Offset = 1.6 |
| 68 | +f0 = 10 |
| 69 | +w0 = 2 * np.pi * f0 |
| 70 | +fs = 10e3 |
| 71 | + |
| 72 | +n = np.linspace(0, fs, num=fs) |
| 73 | +sinewave = Offset + A * np.cos(w0 * n / fs) |
| 74 | + |
| 75 | +dac_max_value = 3800 |
| 76 | +dac_min_value = 100 |
| 77 | + |
| 78 | +# Normalization |
| 79 | +min_value = Offset - A |
| 80 | +sinewave = (sinewave - min_value) * (dac_max_value - dac_min_value) / 2 + dac_min_value |
| 81 | +sinewave = [int(x) for x in sinewave] |
| 82 | + |
| 83 | +fig = plt.figure() |
| 84 | +plt.plot(n, sinewave, 'k') |
| 85 | +plt.show(block=True) |
| 86 | + |
| 87 | +output = "" |
| 88 | +for i in xrange(int(fs)): |
| 89 | + if i == 0: |
| 90 | + output += "{" + "{0}, ".format(sinewave[i]) |
| 91 | + if i == (fs - 1): |
| 92 | + output += "{0}".format(sinewave[i]) + "}" |
| 93 | + else: |
| 94 | + output += "{0}, ".format(sinewave[i]) |
| 95 | + |
| 96 | +with open("sinewave.txt", "w") as f: |
| 97 | + f.write(output) |
0 commit comments