Skip to content

Commit a577c71

Browse files
committed
bump 0.3.0
1 parent 06e50a2 commit a577c71

File tree

11 files changed

+595
-42
lines changed

11 files changed

+595
-42
lines changed

CHANGELOG.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,22 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9-
## [0.2.7] - 2024-07-05
9+
## [0.3.0] - 2024-07-05
1010
- add **float sinusDiode(float t)**
1111
- add **float sinusRectified(float t)**
1212
- add **float trapezium1(float t)** with duty cycle.
1313
- add **float trapezium2(float t)** with duty cycle.
1414
- add **float heartBeat(float t)**
1515
- add **float freeWave(float t, int16_t arr)** arbitrary wave generator.
16+
- add **float freeWaveN(float t, int16_t arr, int N)** arbitrary wave generator.
1617
- update **functionGeneratorPerformance.ino**
1718
- add examples for **freeWave()**
1819
- fix Arduino-lint.yml (long library name error)
20+
- update readme.md
1921
- minor edits
2022

23+
----
24+
2125
## [0.2.6] - 2023-11-02
2226
- update readme.md
2327
- update keywords.txt (align)

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ As always, feedback and ideas are welcome.
3535
You always have to verify your own performance measurements to see if
3636
your requirements are met by this library.
3737

38-
Indication of what performance can be expected (based upon 0.2.1 version).
38+
**Indication** of what performance can be expected (based upon 0.2.1 version).
3939
Note that the values need to be transported to a DAC or serial port too.
4040
Numbers based on performance example, for one single signal.
4141

@@ -174,8 +174,8 @@ DutyCycle changes duration HIGH vs LOW, wave stays trapezium like.
174174
Note at 50% DC the two trapezium functions are identical.
175175
- **float heartBeat(float t)** simplified heartbeat wave.
176176
To get a regular BPM heartbeat one should **setFrequency(BPM/60.0)** e.g 72/60 = 1.2.
177-
- **float freeWave(float t, int16_t arr)** define a free wave form.
178-
It uses an array of **101** values, dividing a full period in **100** equidistant steps.
177+
- **float freeWave(float t, int16_t arr, int16_t N)** define a free wave form.
178+
It uses an array of **N+1** values, dividing a full period in **N** equidistant steps.
179179
The last value should equal the first value to have a smooth transition.
180180
The values of the array normally vary between -10000 and +10000 to manage
181181
the set the relative amplitude in small steps.
@@ -206,6 +206,8 @@ The length of the HIGH LOW level go from 0 to half a period.
206206
- **float trapezium2(float t)** The duty cycle determines the length of the HIGH level,
207207
which is 0 for 0% DC and half a period for 100% DC.
208208
The rising and falling edges stay same.
209+
- **float heartBeat(float t)** The duty cycle determines the part of the period
210+
that the signal ~zero.
209211

210212
### No duty cycle
211213

@@ -220,23 +222,23 @@ Think of it as the halve of the triangle wave.
220222
- **zero()** has no period so does not make sense (yet).
221223
- **float sinusDiode(float t)**
222224
- **float sinusRectified(float t)**
223-
- **float heartBeat(float t)**
224-
- **float freeWave(float t, int16_t arr)**
225-
225+
- **float freeWave(float t, int16_t arr, int16_t N)**
226226

227227
## Future
228228

229229
#### Must
230230

231231
- improve documentation
232232
- reorganize
233+
- section per function might be better.
233234

234235
#### Should
235236

236237
- smart reseed needed for random().
237238
- initialize random generator with compile file + date + time.
238239
- use function values for seed bits.
239240
- stand-alone functions in separate .h
241+
- clean up code
240242

241243
#### Could
242244

@@ -255,14 +257,16 @@ Think of it as the halve of the triangle wave.
255257
- heartBeat
256258
- small noise/variation parameter on amplitude and frequency.
257259
- reduce footprint ==> wrapper around freeWave()
258-
- add **freeWaveN(t, arr, N)** ==> arbitrary array size
259260
- waves
260261
- white noise, pink noise (better done with hardware)
261262
- min() + max() => return +-amplitude + yshift?
262263
- RC function curve.
263264
- Gamma curve.
264-
- freeWave allows a lot.
265-
- create a function table
265+
- create a function table? with what?
266+
- create an example program to sample an arbitrary wave form
267+
- output in the right format.
268+
- slow sampling vs real time.
269+
266270

267271
#### Examples
268272

examples/funcGenFreeWavePlotter/funcGenFreeWavePlotter.ino

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ void loop()
8686
Serial.print("\t");
8787
Serial.print(-80);
8888
Serial.print("\t");
89-
Serial.print(gen.freeWave(t, arr_two_sin));
89+
Serial.print(gen.freeWave(t, arr_two_sin, 100));
9090
Serial.println();
9191
delay(10);
9292
}

examples/functionGeneratorPerformance/functionGeneratorPerformance.ino

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,32 @@ volatile float y;
1717
funcgen gen;
1818

1919

20+
// sin(t) + 0.25 * sin(5t)
21+
int16_t arr_two_sin[101] =
22+
{
23+
0, 1120, 2178, 3117, 3891, 4472,
24+
4847, 5024, 5029, 4904, 4702,
25+
4481, 4300, 4213, 4261, 4472,
26+
4852, 5392, 6063, 6820, 7608,
27+
8366, 9033, 9554, 9886, 10000,
28+
9886, 9554, 9033, 8366, 7608,
29+
6820, 6063, 5392, 4852, 4472,
30+
4261, 4213, 4300, 4481, 4702,
31+
4904, 5029, 5024, 4847, 4472,
32+
3891, 3117, 2178, 1120, 0,
33+
-1120, -2178, -3117, -3891, -4472,
34+
-4847, -5024, -5029, -4904, -4702,
35+
-4481, -4300, -4213, -4261, -4472,
36+
-4852, -5392, -6063, -6820, -7608,
37+
-8366, -9033, -9554, -9886, -10000,
38+
-9886, -9554, -9033, -8366, -7608,
39+
-6820, -6063, -5392, -4852, -4472,
40+
-4261, -4213, -4300, -4481, -4702,
41+
-4904, -5029, -5024, -4847, -4472,
42+
-3891, -3117, -2178, -1120, 0,
43+
};
44+
45+
2046
void setup()
2147
{
2248
Serial.begin(115200);
@@ -49,8 +75,14 @@ void setup()
4975
delay(10);
5076
test_sinusRectified();
5177
delay(10);
78+
test_trapezium1();
79+
delay(10);
5280
test_trapezium2();
5381
delay(10);
82+
test_heartBeat();
83+
delay(10);
84+
test_freeWave();
85+
delay(10);
5486
Serial.println();
5587

5688
Serial.println("t \t sqr\t saw\t tri\t sin\t str\t rnd\t line\t zero\t sinD\t sinR\t trap");
@@ -264,6 +296,22 @@ void test_sinusRectified()
264296
}
265297

266298

299+
void test_trapezium1()
300+
{
301+
start = micros();
302+
for (int i = 0; i < 10000; i++)
303+
{
304+
t = gen.trapezium1(i);
305+
}
306+
stop = micros();
307+
Serial.print(__FUNCTION__);
308+
Serial.print(":\t");
309+
Serial.print((stop - start) / 10000.0);
310+
Serial.print("\t");
311+
Serial.println(1000000.0 / ((stop - start) / 10000.0));
312+
}
313+
314+
267315
void test_trapezium2()
268316
{
269317
start = micros();
@@ -280,6 +328,38 @@ void test_trapezium2()
280328
}
281329

282330

331+
void test_heartBeat()
332+
{
333+
start = micros();
334+
for (int i = 0; i < 10000; i++)
335+
{
336+
t = gen.heartBeat(i);
337+
}
338+
stop = micros();
339+
Serial.print(__FUNCTION__);
340+
Serial.print(":\t");
341+
Serial.print((stop - start) / 10000.0);
342+
Serial.print("\t");
343+
Serial.println(1000000.0 / ((stop - start) / 10000.0));
344+
}
345+
346+
347+
void test_freeWave()
348+
{
349+
start = micros();
350+
for (int i = 0; i < 10000; i++)
351+
{
352+
t = gen.freeWave(i, arr_two_sin);
353+
}
354+
stop = micros();
355+
Serial.print(__FUNCTION__);
356+
Serial.print(":\t");
357+
Serial.print((stop - start) / 10000.0);
358+
Serial.print("\t");
359+
Serial.println(1000000.0 / ((stop - start) / 10000.0));
360+
}
361+
362+
283363
void loop()
284364
{
285365
}

examples/functionGeneratorPerformance/performance_0.2.7.txt

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,27 @@
22
functionGeneratorPerformance.ino
33
FUNCTIONGENERATOR_LIB_VERSION: 0.2.7
44

5-
func usec max calls/sec (indicative)
6-
test_square: 55.20 18116.73
7-
test_sawtooth: 62.32 16047.14
8-
test_triangle: 80.42 12433.98
9-
test_sinus: 167.01 5987.72
10-
test_stair: 81.49 12270.96
11-
test_random: 43.18 23159.30
12-
test_random_DC: 67.75 14760.76
13-
test_line: 0.76 1324152.50
14-
test_zero: 0.76 1324152.50
15-
test_sinusDiode: 170.56 5863.09
16-
test_sinusRectified: 169.55 5897.87
17-
test_trapezium2: 68.35 14630.15
5+
indicative output Arduino UNO 1.8.19, 16 MHz.
6+
7+
| wave form name | usec | max calls/sec |
8+
|:---------------|-------:|----------------:|
9+
| square | 54.57 | 18325.49 |
10+
| sawtooth | 61.69 | 16210.61 |
11+
| triangle | 79.80 | 12531.96 |
12+
| sinus | 166.38 | 6010.37 |
13+
| stair | 80.86 | 12366.38 |
14+
| random | 42.61 | 23466.69 |
15+
| random_DC | 67.18 | 14885.12 |
16+
| line | 0.76 | 1322751.37 |
17+
| zero | 0.75 | 1324854.25 |
18+
| sinusDiode | 169.93 | 5884.79 |
19+
| sinusRectified | 169.49 | 5900.03 |
20+
| trapezium1 | 100.98 | 9903.30 |
21+
| trapezium2 | 143.98 | 6945.58 |
22+
| heartBeat | 128.52 | 7780.77 |
23+
| freeWave | 75.52 | 13241.31 |
24+
25+
1826

1927
t sqr saw tri sin str rnd line zero sinD sinR trap
2028
-4.00 -1.00 1.00 -1.00 -0.00 1.00 0.50 1.00 0.00 0.00 0.00 -1.00

0 commit comments

Comments
 (0)