@ohos-ports/stdlib-simulate 0.4.1-beta.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +177 -0
- package/NOTICE +1 -0
- package/README.md +188 -0
- package/SECURITY.md +5 -0
- package/docs/types/index.d.ts +43 -0
- package/iter/README.md +142 -0
- package/iter/awgn/README.md +240 -0
- package/iter/awgn/docs/repl.txt +85 -0
- package/iter/awgn/docs/types/index.d.ts +155 -0
- package/iter/awgn/docs/types/test.ts +150 -0
- package/iter/awgn/lib/defaults.js +38 -0
- package/iter/awgn/lib/index.js +55 -0
- package/iter/awgn/lib/main.js +278 -0
- package/iter/awgn/package.json +68 -0
- package/iter/awln/README.md +238 -0
- package/iter/awln/docs/repl.txt +85 -0
- package/iter/awln/docs/types/index.d.ts +155 -0
- package/iter/awln/docs/types/test.ts +150 -0
- package/iter/awln/lib/defaults.js +38 -0
- package/iter/awln/lib/index.js +55 -0
- package/iter/awln/lib/main.js +299 -0
- package/iter/awln/package.json +72 -0
- package/iter/awun/README.md +238 -0
- package/iter/awun/docs/repl.txt +85 -0
- package/iter/awun/docs/types/index.d.ts +155 -0
- package/iter/awun/docs/types/test.ts +150 -0
- package/iter/awun/lib/defaults.js +38 -0
- package/iter/awun/lib/index.js +55 -0
- package/iter/awun/lib/main.js +305 -0
- package/iter/awun/package.json +68 -0
- package/iter/bartlett-hann-pulse/README.md +331 -0
- package/iter/bartlett-hann-pulse/docs/img/equation_bartlett_hann_pulse_waveform.svg +191 -0
- package/iter/bartlett-hann-pulse/docs/repl.txt +54 -0
- package/iter/bartlett-hann-pulse/docs/types/index.d.ts +105 -0
- package/iter/bartlett-hann-pulse/docs/types/test.ts +89 -0
- package/iter/bartlett-hann-pulse/lib/index.js +54 -0
- package/iter/bartlett-hann-pulse/lib/main.js +192 -0
- package/iter/bartlett-hann-pulse/lib/validate.js +97 -0
- package/iter/bartlett-hann-pulse/package.json +76 -0
- package/iter/bartlett-pulse/README.md +328 -0
- package/iter/bartlett-pulse/docs/img/equation_bartlett_pulse_waveform.svg +128 -0
- package/iter/bartlett-pulse/docs/repl.txt +54 -0
- package/iter/bartlett-pulse/docs/types/index.d.ts +105 -0
- package/iter/bartlett-pulse/docs/types/test.ts +89 -0
- package/iter/bartlett-pulse/lib/index.js +54 -0
- package/iter/bartlett-pulse/lib/main.js +169 -0
- package/iter/bartlett-pulse/lib/validate.js +97 -0
- package/iter/bartlett-pulse/package.json +72 -0
- package/iter/cosine-wave/README.md +292 -0
- package/iter/cosine-wave/docs/img/equation_cosine_waveform.svg +55 -0
- package/iter/cosine-wave/docs/repl.txt +51 -0
- package/iter/cosine-wave/docs/types/index.d.ts +96 -0
- package/iter/cosine-wave/docs/types/test.ts +78 -0
- package/iter/cosine-wave/lib/index.js +54 -0
- package/iter/cosine-wave/lib/main.js +156 -0
- package/iter/cosine-wave/lib/validate.js +90 -0
- package/iter/cosine-wave/package.json +70 -0
- package/iter/dirac-comb/README.md +278 -0
- package/iter/dirac-comb/docs/img/equation_dirac_comb.svg +44 -0
- package/iter/dirac-comb/docs/repl.txt +48 -0
- package/iter/dirac-comb/docs/types/index.d.ts +89 -0
- package/iter/dirac-comb/docs/types/test.ts +78 -0
- package/iter/dirac-comb/lib/index.js +54 -0
- package/iter/dirac-comb/lib/main.js +152 -0
- package/iter/dirac-comb/lib/validate.js +82 -0
- package/iter/dirac-comb/package.json +72 -0
- package/iter/docs/types/index.d.ts +678 -0
- package/iter/docs/types/test.ts +29 -0
- package/iter/flat-top-pulse/README.md +330 -0
- package/iter/flat-top-pulse/docs/img/equation_flat_top_pulse_waveform.svg +177 -0
- package/iter/flat-top-pulse/docs/repl.txt +54 -0
- package/iter/flat-top-pulse/docs/types/index.d.ts +105 -0
- package/iter/flat-top-pulse/docs/types/test.ts +89 -0
- package/iter/flat-top-pulse/lib/index.js +54 -0
- package/iter/flat-top-pulse/lib/main.js +193 -0
- package/iter/flat-top-pulse/lib/validate.js +97 -0
- package/iter/flat-top-pulse/package.json +71 -0
- package/iter/hann-pulse/README.md +328 -0
- package/iter/hann-pulse/docs/img/equation_hann_pulse_waveform.svg +129 -0
- package/iter/hann-pulse/docs/repl.txt +54 -0
- package/iter/hann-pulse/docs/types/index.d.ts +105 -0
- package/iter/hann-pulse/docs/types/test.ts +89 -0
- package/iter/hann-pulse/lib/index.js +54 -0
- package/iter/hann-pulse/lib/main.js +171 -0
- package/iter/hann-pulse/lib/validate.js +97 -0
- package/iter/hann-pulse/package.json +72 -0
- package/iter/lanczos-pulse/README.md +325 -0
- package/iter/lanczos-pulse/docs/img/equation_lanczos_pulse_waveform.svg +122 -0
- package/iter/lanczos-pulse/docs/repl.txt +54 -0
- package/iter/lanczos-pulse/docs/types/index.d.ts +105 -0
- package/iter/lanczos-pulse/docs/types/test.ts +89 -0
- package/iter/lanczos-pulse/lib/index.js +54 -0
- package/iter/lanczos-pulse/lib/main.js +169 -0
- package/iter/lanczos-pulse/lib/validate.js +97 -0
- package/iter/lanczos-pulse/package.json +70 -0
- package/iter/lib/index.js +186 -0
- package/iter/package.json +63 -0
- package/iter/periodic-sinc/README.md +301 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc.svg +146 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_in_terms_of_period.svg +164 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_in_terms_of_sinc_function.svg +65 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_substitution_even.svg +34 -0
- package/iter/periodic-sinc/docs/img/equation_periodic_sinc_substitution_odd.svg +34 -0
- package/iter/periodic-sinc/docs/repl.txt +54 -0
- package/iter/periodic-sinc/docs/types/index.d.ts +98 -0
- package/iter/periodic-sinc/docs/types/test.ts +102 -0
- package/iter/periodic-sinc/lib/index.js +50 -0
- package/iter/periodic-sinc/lib/main.js +241 -0
- package/iter/periodic-sinc/lib/validate.js +90 -0
- package/iter/periodic-sinc/package.json +70 -0
- package/iter/pulse/README.md +322 -0
- package/iter/pulse/docs/img/equation_pulse_waveform.svg +115 -0
- package/iter/pulse/docs/repl.txt +58 -0
- package/iter/pulse/docs/types/index.d.ts +109 -0
- package/iter/pulse/docs/types/test.ts +100 -0
- package/iter/pulse/lib/index.js +54 -0
- package/iter/pulse/lib/main.js +165 -0
- package/iter/pulse/lib/validate.js +105 -0
- package/iter/pulse/package.json +69 -0
- package/iter/sawtooth-wave/README.md +289 -0
- package/iter/sawtooth-wave/docs/img/equation_sawtooth_waveform.svg +73 -0
- package/iter/sawtooth-wave/docs/repl.txt +51 -0
- package/iter/sawtooth-wave/docs/types/index.d.ts +96 -0
- package/iter/sawtooth-wave/docs/types/test.ts +78 -0
- package/iter/sawtooth-wave/lib/index.js +54 -0
- package/iter/sawtooth-wave/lib/main.js +161 -0
- package/iter/sawtooth-wave/lib/validate.js +90 -0
- package/iter/sawtooth-wave/package.json +67 -0
- package/iter/sine-wave/README.md +292 -0
- package/iter/sine-wave/docs/img/equation_sine_waveform.svg +55 -0
- package/iter/sine-wave/docs/repl.txt +51 -0
- package/iter/sine-wave/docs/types/index.d.ts +96 -0
- package/iter/sine-wave/docs/types/test.ts +78 -0
- package/iter/sine-wave/lib/index.js +54 -0
- package/iter/sine-wave/lib/main.js +156 -0
- package/iter/sine-wave/lib/validate.js +90 -0
- package/iter/sine-wave/package.json +70 -0
- package/iter/square-wave/README.md +291 -0
- package/iter/square-wave/docs/img/equation_square_waveform.svg +115 -0
- package/iter/square-wave/docs/repl.txt +55 -0
- package/iter/square-wave/docs/types/index.d.ts +105 -0
- package/iter/square-wave/docs/types/test.ts +89 -0
- package/iter/square-wave/lib/index.js +54 -0
- package/iter/square-wave/lib/main.js +156 -0
- package/iter/square-wave/lib/validate.js +99 -0
- package/iter/square-wave/package.json +67 -0
- package/iter/triangle-wave/README.md +289 -0
- package/iter/triangle-wave/docs/img/equation_triangle_waveform.svg +75 -0
- package/iter/triangle-wave/docs/repl.txt +51 -0
- package/iter/triangle-wave/docs/types/index.d.ts +96 -0
- package/iter/triangle-wave/docs/types/test.ts +78 -0
- package/iter/triangle-wave/lib/index.js +54 -0
- package/iter/triangle-wave/lib/main.js +160 -0
- package/iter/triangle-wave/lib/validate.js +90 -0
- package/iter/triangle-wave/package.json +66 -0
- package/lib/index.js +51 -0
- package/package.json +72 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
|
|
2
|
+
{{alias}}( [options] )
|
|
3
|
+
Returns an iterator which generates a Bartlett-Hann pulse waveform.
|
|
4
|
+
|
|
5
|
+
If an environment supports Symbol.iterator, the returned iterator is
|
|
6
|
+
iterable.
|
|
7
|
+
|
|
8
|
+
Parameters
|
|
9
|
+
----------
|
|
10
|
+
options: Object (optional)
|
|
11
|
+
Function options.
|
|
12
|
+
|
|
13
|
+
options.period: integer (optional)
|
|
14
|
+
Pulse period (i.e., the number of iterations until a waveform repeats).
|
|
15
|
+
Default: 100.
|
|
16
|
+
|
|
17
|
+
options.duration: integer (optional)
|
|
18
|
+
Pulse duration. Must be greater than 2. Default: options.period.
|
|
19
|
+
|
|
20
|
+
options.amplitude: number (optional)
|
|
21
|
+
Amplitude. Default: 1.0.
|
|
22
|
+
|
|
23
|
+
options.offset: integer (optional)
|
|
24
|
+
Phase offset (in units of iterations; zero-based). A negative offset
|
|
25
|
+
translates the waveform to the left. A positive offset translates a
|
|
26
|
+
waveform to the right. Default: 0.
|
|
27
|
+
|
|
28
|
+
options.iter: integer (optional)
|
|
29
|
+
Number of iterations. Default: 1e308.
|
|
30
|
+
|
|
31
|
+
Returns
|
|
32
|
+
-------
|
|
33
|
+
iterator: Object
|
|
34
|
+
Iterator.
|
|
35
|
+
|
|
36
|
+
iterator.next(): Function
|
|
37
|
+
Returns an iterator protocol-compliant object containing the next
|
|
38
|
+
iterated value (if one exists) and a boolean flag indicating whether the
|
|
39
|
+
iterator is finished.
|
|
40
|
+
|
|
41
|
+
iterator.return( [value] ): Function
|
|
42
|
+
Finishes an iterator and returns a provided value.
|
|
43
|
+
|
|
44
|
+
Examples
|
|
45
|
+
--------
|
|
46
|
+
> var it = {{alias}}();
|
|
47
|
+
> var v = it.next().value
|
|
48
|
+
<number>
|
|
49
|
+
> v = it.next().value
|
|
50
|
+
<number>
|
|
51
|
+
|
|
52
|
+
See Also
|
|
53
|
+
--------
|
|
54
|
+
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
// TypeScript Version: 4.1
|
|
20
|
+
|
|
21
|
+
/// <reference types="@stdlib/types"/>
|
|
22
|
+
|
|
23
|
+
import { Iterator as Iter, IterableIterator } from '@stdlib/types/iter';
|
|
24
|
+
|
|
25
|
+
// Define a union type representing both iterable and non-iterable iterators:
|
|
26
|
+
type Iterator = Iter | IterableIterator;
|
|
27
|
+
|
|
28
|
+
interface Options {
|
|
29
|
+
/**
|
|
30
|
+
* Pulse period (i.e., the number of iterations until a waveform repeats).
|
|
31
|
+
*/
|
|
32
|
+
period?: number;
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Pulse duration.
|
|
36
|
+
*/
|
|
37
|
+
duration?: number;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Amplitude.
|
|
41
|
+
*/
|
|
42
|
+
amplitude?: number;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Phase offset (in units of iterations; zero-based).
|
|
46
|
+
*
|
|
47
|
+
* ## Notes
|
|
48
|
+
*
|
|
49
|
+
* - A negative offset translates a waveform to the left.
|
|
50
|
+
* - A positive offset translates a waveform to the right.
|
|
51
|
+
*/
|
|
52
|
+
offset?: number;
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Number of iterations.
|
|
56
|
+
*/
|
|
57
|
+
iter?: number;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* Returns an iterator which generates a Bartlett-Hann pulse waveform.
|
|
62
|
+
*
|
|
63
|
+
* ## Notes
|
|
64
|
+
*
|
|
65
|
+
* - If an environment supports `Symbol.iterator`, the returned iterator is iterable.
|
|
66
|
+
*
|
|
67
|
+
* @param options - function options
|
|
68
|
+
* @param options.period - number of iterations before a waveform repeats (default: 100)
|
|
69
|
+
* @param options.duration - pulse duration (default: options.period)
|
|
70
|
+
* @param options.amplitude - amplitude (default: 1.0)
|
|
71
|
+
* @param options.offset - phase offset (in units of iterations; default: 0)
|
|
72
|
+
* @param options.iter - number of iterations (default: 1e308)
|
|
73
|
+
* @throws `duration` option must be a positive integer
|
|
74
|
+
* @throws `period` option must be a positive integer
|
|
75
|
+
* @throws `offset` option must be an integer
|
|
76
|
+
* @throws `amplitude` option must be a positive number
|
|
77
|
+
* @throws `iter` option must be a nonnegative integer
|
|
78
|
+
* @throws `duration` option must be less than or equal to the `period`
|
|
79
|
+
* @throws `duration` option must be greater than 2
|
|
80
|
+
* @returns iterator
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* var opts = {
|
|
84
|
+
* 'period': 10
|
|
85
|
+
* };
|
|
86
|
+
*
|
|
87
|
+
* var iter = iterBartlettHannPulse( opts );
|
|
88
|
+
*
|
|
89
|
+
* var v = iter.next().value;
|
|
90
|
+
* // returns <number>
|
|
91
|
+
*
|
|
92
|
+
* v = iter.next().value;
|
|
93
|
+
* // returns <number>
|
|
94
|
+
*
|
|
95
|
+
* v = iter.next().value;
|
|
96
|
+
* // returns <number>
|
|
97
|
+
*
|
|
98
|
+
* // ...
|
|
99
|
+
*/
|
|
100
|
+
declare function iterBartlettHannPulse( options?: Options ): Iterator;
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
// EXPORTS //
|
|
104
|
+
|
|
105
|
+
export = iterBartlettHannPulse;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import iterBartlettHannPulse = require( './index' );
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
// TESTS //
|
|
23
|
+
|
|
24
|
+
// The function returns an iterator...
|
|
25
|
+
{
|
|
26
|
+
iterBartlettHannPulse(); // $ExpectType Iterator
|
|
27
|
+
iterBartlettHannPulse( {} ); // $ExpectType Iterator
|
|
28
|
+
iterBartlettHannPulse( { 'iter': 10 } ); // $ExpectType Iterator
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
// The compiler throws an error if the function is provided a first argument which is not an options object...
|
|
32
|
+
{
|
|
33
|
+
iterBartlettHannPulse( null ); // $ExpectError
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// The compiler throws an error if the function is provided a `duration` option which is not a number...
|
|
37
|
+
{
|
|
38
|
+
iterBartlettHannPulse( { 'duration': '5' } ); // $ExpectError
|
|
39
|
+
iterBartlettHannPulse( { 'duration': true } ); // $ExpectError
|
|
40
|
+
iterBartlettHannPulse( { 'duration': false } ); // $ExpectError
|
|
41
|
+
iterBartlettHannPulse( { 'duration': null } ); // $ExpectError
|
|
42
|
+
iterBartlettHannPulse( { 'duration': [] } ); // $ExpectError
|
|
43
|
+
iterBartlettHannPulse( { 'duration': {} } ); // $ExpectError
|
|
44
|
+
iterBartlettHannPulse( { 'duration': ( x: number ): number => x } ); // $ExpectError
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
// The compiler throws an error if the function is provided a `period` option which is not a number...
|
|
48
|
+
{
|
|
49
|
+
iterBartlettHannPulse( { 'period': '5' } ); // $ExpectError
|
|
50
|
+
iterBartlettHannPulse( { 'period': true } ); // $ExpectError
|
|
51
|
+
iterBartlettHannPulse( { 'period': false } ); // $ExpectError
|
|
52
|
+
iterBartlettHannPulse( { 'period': null } ); // $ExpectError
|
|
53
|
+
iterBartlettHannPulse( { 'period': [] } ); // $ExpectError
|
|
54
|
+
iterBartlettHannPulse( { 'period': {} } ); // $ExpectError
|
|
55
|
+
iterBartlettHannPulse( { 'period': ( x: number ): number => x } ); // $ExpectError
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// The compiler throws an error if the function is provided an `amplitude` option which is not a number...
|
|
59
|
+
{
|
|
60
|
+
iterBartlettHannPulse( { 'amplitude': '5' } ); // $ExpectError
|
|
61
|
+
iterBartlettHannPulse( { 'amplitude': true } ); // $ExpectError
|
|
62
|
+
iterBartlettHannPulse( { 'amplitude': false } ); // $ExpectError
|
|
63
|
+
iterBartlettHannPulse( { 'amplitude': null } ); // $ExpectError
|
|
64
|
+
iterBartlettHannPulse( { 'amplitude': [] } ); // $ExpectError
|
|
65
|
+
iterBartlettHannPulse( { 'amplitude': {} } ); // $ExpectError
|
|
66
|
+
iterBartlettHannPulse( { 'amplitude': ( x: number ): number => x } ); // $ExpectError
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// The compiler throws an error if the function is provided an `offset` option which is not a number...
|
|
70
|
+
{
|
|
71
|
+
iterBartlettHannPulse( { 'offset': '5' } ); // $ExpectError
|
|
72
|
+
iterBartlettHannPulse( { 'offset': true } ); // $ExpectError
|
|
73
|
+
iterBartlettHannPulse( { 'offset': false } ); // $ExpectError
|
|
74
|
+
iterBartlettHannPulse( { 'offset': null } ); // $ExpectError
|
|
75
|
+
iterBartlettHannPulse( { 'offset': [] } ); // $ExpectError
|
|
76
|
+
iterBartlettHannPulse( { 'offset': {} } ); // $ExpectError
|
|
77
|
+
iterBartlettHannPulse( { 'offset': ( x: number ): number => x } ); // $ExpectError
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// The compiler throws an error if the function is provided an `iter` option which is not a number...
|
|
81
|
+
{
|
|
82
|
+
iterBartlettHannPulse( { 'iter': '5' } ); // $ExpectError
|
|
83
|
+
iterBartlettHannPulse( { 'iter': true } ); // $ExpectError
|
|
84
|
+
iterBartlettHannPulse( { 'iter': false } ); // $ExpectError
|
|
85
|
+
iterBartlettHannPulse( { 'iter': null } ); // $ExpectError
|
|
86
|
+
iterBartlettHannPulse( { 'iter': [] } ); // $ExpectError
|
|
87
|
+
iterBartlettHannPulse( { 'iter': {} } ); // $ExpectError
|
|
88
|
+
iterBartlettHannPulse( { 'iter': ( x: number ): number => x } ); // $ExpectError
|
|
89
|
+
}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Create an iterator which generates a Bartlett-Hann pulse waveform.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/simulate/iter/bartlett-hann-pulse
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var iterBartlettHannPulse = require( '@stdlib/simulate/iter/bartlett-hann-pulse' );
|
|
28
|
+
*
|
|
29
|
+
* var opts = {
|
|
30
|
+
* 'period': 10
|
|
31
|
+
* };
|
|
32
|
+
*
|
|
33
|
+
* var iter = iterBartlettHannPulse( opts );
|
|
34
|
+
*
|
|
35
|
+
* var v = iter.next().value;
|
|
36
|
+
* // returns <number>
|
|
37
|
+
*
|
|
38
|
+
* v = iter.next().value;
|
|
39
|
+
* // returns <number>
|
|
40
|
+
*
|
|
41
|
+
* v = iter.next().value;
|
|
42
|
+
* // returns <number>
|
|
43
|
+
*
|
|
44
|
+
* // ...
|
|
45
|
+
*/
|
|
46
|
+
|
|
47
|
+
// MODULES //
|
|
48
|
+
|
|
49
|
+
var main = require( './main.js' );
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
// EXPORTS //
|
|
53
|
+
|
|
54
|
+
module.exports = main;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var setReadOnly = require( '@stdlib/utils/define-nonenumerable-read-only-property' );
|
|
24
|
+
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
|
|
25
|
+
var abs = require( '@stdlib/math/base/special/abs' );
|
|
26
|
+
var cospi = require( '@stdlib/math/base/special/cospi' );
|
|
27
|
+
var format = require( '@stdlib/string/format' );
|
|
28
|
+
var validate = require( './validate.js' );
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
// VARIABLES //
|
|
32
|
+
|
|
33
|
+
var A0 = 0.62;
|
|
34
|
+
var A1 = 0.48;
|
|
35
|
+
var A2 = 0.38;
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
// FUNCTIONS //
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Evaluates a Bartlett-Hann window function.
|
|
42
|
+
*
|
|
43
|
+
* @private
|
|
44
|
+
* @param {integer} t - value at which to evaluate the function
|
|
45
|
+
* @param {integer} T - period
|
|
46
|
+
* @param {number} A - amplitude
|
|
47
|
+
* @returns {number} function value
|
|
48
|
+
*/
|
|
49
|
+
function bartlettHann( t, T, A ) {
|
|
50
|
+
T -= 1;
|
|
51
|
+
return A * ( A0 - (A1*abs( (t/T)-0.5) ) - (A2*cospi( (2.0/T)*t) ) );
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
// MAIN //
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Returns an iterator which generates a Bartlett-Hann pulse waveform.
|
|
59
|
+
*
|
|
60
|
+
* @param {Options} [options] - function options
|
|
61
|
+
* @param {PositiveInteger} [options.period=100] - number of iterations before a waveform repeats
|
|
62
|
+
* @param {PositiveInteger} [options.duration=options.period] - pulse duration
|
|
63
|
+
* @param {PositiveNumber} [options.amplitude=1.0] - amplitude
|
|
64
|
+
* @param {integer} [options.offset=0] - phase offset (in units of iterations; zero-based)
|
|
65
|
+
* @param {NonNegativeInteger} [options.iter=1e308] - number of iterations
|
|
66
|
+
* @throws {TypeError} options argument must be an object
|
|
67
|
+
* @throws {TypeError} must provide valid options
|
|
68
|
+
* @throws {RangeError} pulse duration must be less than or equal to the period
|
|
69
|
+
* @throws {RangeError} pulse duration must be greater than `2`
|
|
70
|
+
* @returns {Iterator} iterator
|
|
71
|
+
*
|
|
72
|
+
* @example
|
|
73
|
+
* var opts = {
|
|
74
|
+
* 'period': 10
|
|
75
|
+
* };
|
|
76
|
+
*
|
|
77
|
+
* var iter = iterBartlettHannPulse( opts );
|
|
78
|
+
*
|
|
79
|
+
* var v = iter.next().value;
|
|
80
|
+
* // returns <number>
|
|
81
|
+
*
|
|
82
|
+
* v = iter.next().value;
|
|
83
|
+
* // returns <number>
|
|
84
|
+
*
|
|
85
|
+
* v = iter.next().value;
|
|
86
|
+
* // returns <number>
|
|
87
|
+
*
|
|
88
|
+
* // ...
|
|
89
|
+
*/
|
|
90
|
+
function iterBartlettHannPulse( options ) {
|
|
91
|
+
var opts;
|
|
92
|
+
var iter;
|
|
93
|
+
var FLG;
|
|
94
|
+
var err;
|
|
95
|
+
var t;
|
|
96
|
+
var i;
|
|
97
|
+
|
|
98
|
+
opts = {
|
|
99
|
+
'duration': -1,
|
|
100
|
+
'period': 100,
|
|
101
|
+
'amplitude': 1.0,
|
|
102
|
+
'offset': 0,
|
|
103
|
+
'iter': 1e308
|
|
104
|
+
};
|
|
105
|
+
if ( arguments.length ) {
|
|
106
|
+
err = validate( opts, options );
|
|
107
|
+
if ( err ) {
|
|
108
|
+
throw err;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if ( opts.duration === -1 ) {
|
|
112
|
+
opts.duration = opts.period;
|
|
113
|
+
}
|
|
114
|
+
if ( opts.duration > opts.period ) {
|
|
115
|
+
throw new RangeError( format( 'invalid option. `%s` option must be less than or equal to the period. Option: `%u`.', 'duration', opts.duration ) );
|
|
116
|
+
}
|
|
117
|
+
if ( opts.duration <= 2 ) {
|
|
118
|
+
throw new RangeError( format( 'invalid option. `%s` option must be greater than 2. Option: `%s`.', 'duration', opts.duration ) );
|
|
119
|
+
}
|
|
120
|
+
t = ( opts.period-opts.offset ) % opts.period;
|
|
121
|
+
if ( t < 0 ) {
|
|
122
|
+
t += opts.period;
|
|
123
|
+
}
|
|
124
|
+
t -= 1;
|
|
125
|
+
i = 0;
|
|
126
|
+
|
|
127
|
+
// Create an iterator protocol-compliant object:
|
|
128
|
+
iter = {};
|
|
129
|
+
setReadOnly( iter, 'next', next );
|
|
130
|
+
setReadOnly( iter, 'return', end );
|
|
131
|
+
|
|
132
|
+
// If an environment supports `Symbol.iterator`, make the iterator iterable:
|
|
133
|
+
if ( iteratorSymbol ) {
|
|
134
|
+
setReadOnly( iter, iteratorSymbol, factory );
|
|
135
|
+
}
|
|
136
|
+
return iter;
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Returns an iterator protocol-compliant object containing the next iterated value.
|
|
140
|
+
*
|
|
141
|
+
* @private
|
|
142
|
+
* @returns {Object} iterator protocol-compliant object
|
|
143
|
+
*/
|
|
144
|
+
function next() {
|
|
145
|
+
i += 1;
|
|
146
|
+
if ( FLG || i > opts.iter ) {
|
|
147
|
+
return {
|
|
148
|
+
'done': true
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
t = (t+1) % opts.period;
|
|
152
|
+
return {
|
|
153
|
+
'value': ( t < opts.duration ) ? bartlettHann( t, opts.duration, opts.amplitude ) : 0.0,
|
|
154
|
+
'done': false
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* Finishes an iterator.
|
|
160
|
+
*
|
|
161
|
+
* @private
|
|
162
|
+
* @param {*} [value] - value to return
|
|
163
|
+
* @returns {Object} iterator protocol-compliant object
|
|
164
|
+
*/
|
|
165
|
+
function end( value ) {
|
|
166
|
+
FLG = true;
|
|
167
|
+
if ( arguments.length ) {
|
|
168
|
+
return {
|
|
169
|
+
'value': value,
|
|
170
|
+
'done': true
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
'done': true
|
|
175
|
+
};
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Returns a new iterator.
|
|
180
|
+
*
|
|
181
|
+
* @private
|
|
182
|
+
* @returns {Iterator} iterator
|
|
183
|
+
*/
|
|
184
|
+
function factory() {
|
|
185
|
+
return iterBartlettHannPulse( opts );
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
// EXPORTS //
|
|
191
|
+
|
|
192
|
+
module.exports = iterBartlettHannPulse;
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license Apache-2.0
|
|
3
|
+
*
|
|
4
|
+
* Copyright (c) 2019 The Stdlib Authors.
|
|
5
|
+
*
|
|
6
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
7
|
+
* you may not use this file except in compliance with the License.
|
|
8
|
+
* You may obtain a copy of the License at
|
|
9
|
+
*
|
|
10
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
+
*
|
|
12
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
13
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
14
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
15
|
+
* See the License for the specific language governing permissions and
|
|
16
|
+
* limitations under the License.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
'use strict';
|
|
20
|
+
|
|
21
|
+
// MODULES //
|
|
22
|
+
|
|
23
|
+
var isPlainObject = require( '@stdlib/assert/is-plain-object' );
|
|
24
|
+
var hasOwnProp = require( '@stdlib/assert/has-own-property' );
|
|
25
|
+
var isPositiveNumber = require( '@stdlib/assert/is-positive-number' ).isPrimitive;
|
|
26
|
+
var isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
|
|
27
|
+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
|
|
28
|
+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
|
|
29
|
+
var format = require( '@stdlib/string/format' );
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
// MAIN //
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Validates function options.
|
|
36
|
+
*
|
|
37
|
+
* @private
|
|
38
|
+
* @param {Object} opts - destination object
|
|
39
|
+
* @param {Options} options - function options
|
|
40
|
+
* @param {PositiveInteger} [options.period] - number of iterations before a waveform repeats
|
|
41
|
+
* @param {PositiveInteger} [options.duration] - pulse duration
|
|
42
|
+
* @param {PositiveNumber} [options.amplitude] - amplitude
|
|
43
|
+
* @param {integer} [options.offset] - phase offset (in units of iterations)
|
|
44
|
+
* @param {NonNegativeInteger} [options.iter] - number of iterations
|
|
45
|
+
* @returns {(Error|null)} null or an error object
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
* var opts = {};
|
|
49
|
+
* var options = {
|
|
50
|
+
* 'iter': 100
|
|
51
|
+
* };
|
|
52
|
+
* var err = validate( opts, options );
|
|
53
|
+
* if ( err ) {
|
|
54
|
+
* throw err;
|
|
55
|
+
* }
|
|
56
|
+
*/
|
|
57
|
+
function validate( opts, options ) {
|
|
58
|
+
if ( !isPlainObject( options ) ) {
|
|
59
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
60
|
+
}
|
|
61
|
+
if ( hasOwnProp( options, 'duration' ) ) {
|
|
62
|
+
opts.duration = options.duration;
|
|
63
|
+
if ( !isPositiveInteger( options.duration ) ) {
|
|
64
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'duration', options.duration ) );
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
if ( hasOwnProp( options, 'period' ) ) {
|
|
68
|
+
opts.period = options.period;
|
|
69
|
+
if ( !isPositiveInteger( options.period ) ) {
|
|
70
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive integer. Option: `%s`.', 'period', options.period ) );
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if ( hasOwnProp( options, 'amplitude' ) ) {
|
|
74
|
+
opts.amplitude = options.amplitude;
|
|
75
|
+
if ( !isPositiveNumber( options.amplitude ) ) {
|
|
76
|
+
return new TypeError( format( 'invalid option. `%s` option must be a positive number. Option: `%s`.', 'amplitude', options.amplitude ) );
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
if ( hasOwnProp( options, 'offset' ) ) {
|
|
80
|
+
opts.offset = options.offset;
|
|
81
|
+
if ( !isInteger( options.offset ) ) {
|
|
82
|
+
return new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'offset', options.offset ) );
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if ( hasOwnProp( options, 'iter' ) ) {
|
|
86
|
+
opts.iter = options.iter;
|
|
87
|
+
if ( !isNonNegativeInteger( options.iter ) ) {
|
|
88
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) );
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
// EXPORTS //
|
|
96
|
+
|
|
97
|
+
module.exports = validate;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/simulate/iter/bartlett-hann-pulse",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Create an iterator which generates a Bartlett-Hann pulse waveform.",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"author": {
|
|
7
|
+
"name": "The Stdlib Authors",
|
|
8
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
9
|
+
},
|
|
10
|
+
"contributors": [
|
|
11
|
+
{
|
|
12
|
+
"name": "The Stdlib Authors",
|
|
13
|
+
"url": "https://github.com/stdlib-js/stdlib/graphs/contributors"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
"main": "./lib",
|
|
17
|
+
"directories": {
|
|
18
|
+
"benchmark": "./benchmark",
|
|
19
|
+
"doc": "./docs",
|
|
20
|
+
"example": "./examples",
|
|
21
|
+
"lib": "./lib",
|
|
22
|
+
"test": "./test"
|
|
23
|
+
},
|
|
24
|
+
"types": "./docs/types",
|
|
25
|
+
"scripts": {},
|
|
26
|
+
"homepage": "https://github.com/stdlib-js/stdlib",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "git://github.com/stdlib-js/stdlib.git"
|
|
30
|
+
},
|
|
31
|
+
"bugs": {
|
|
32
|
+
"url": "https://github.com/stdlib-js/stdlib/issues"
|
|
33
|
+
},
|
|
34
|
+
"dependencies": {},
|
|
35
|
+
"devDependencies": {},
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=0.10.0",
|
|
38
|
+
"npm": ">2.7.0"
|
|
39
|
+
},
|
|
40
|
+
"os": [
|
|
41
|
+
"aix",
|
|
42
|
+
"darwin",
|
|
43
|
+
"freebsd",
|
|
44
|
+
"linux",
|
|
45
|
+
"macos",
|
|
46
|
+
"openbsd",
|
|
47
|
+
"sunos",
|
|
48
|
+
"win32",
|
|
49
|
+
"windows"
|
|
50
|
+
],
|
|
51
|
+
"keywords": [
|
|
52
|
+
"stdlib",
|
|
53
|
+
"simulate",
|
|
54
|
+
"simulation",
|
|
55
|
+
"bartlett",
|
|
56
|
+
"triangle",
|
|
57
|
+
"triangular",
|
|
58
|
+
"fejer",
|
|
59
|
+
"hann",
|
|
60
|
+
"raised",
|
|
61
|
+
"cosine",
|
|
62
|
+
"raised-cosine",
|
|
63
|
+
"window",
|
|
64
|
+
"pulse",
|
|
65
|
+
"wave",
|
|
66
|
+
"train",
|
|
67
|
+
"signal",
|
|
68
|
+
"processing",
|
|
69
|
+
"waveform",
|
|
70
|
+
"periodic",
|
|
71
|
+
"iterator",
|
|
72
|
+
"iterate",
|
|
73
|
+
"iteration",
|
|
74
|
+
"iter"
|
|
75
|
+
]
|
|
76
|
+
}
|