@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,50 @@
|
|
|
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 periodic sinc waveform.
|
|
23
|
+
*
|
|
24
|
+
* @module @stdlib/simulate/iter/periodic-sinc
|
|
25
|
+
*
|
|
26
|
+
* @example
|
|
27
|
+
* var iterPeriodicSinc = require( '@stdlib/simulate/iter/periodic-sinc' );
|
|
28
|
+
*
|
|
29
|
+
* var iter = iterPeriodicSinc( 7 );
|
|
30
|
+
*
|
|
31
|
+
* var v = iter.next().value;
|
|
32
|
+
* // returns <number>
|
|
33
|
+
*
|
|
34
|
+
* v = iter.next().value;
|
|
35
|
+
* // returns <number>
|
|
36
|
+
*
|
|
37
|
+
* v = iter.next().value;
|
|
38
|
+
* // returns <number>
|
|
39
|
+
*
|
|
40
|
+
* // ...
|
|
41
|
+
*/
|
|
42
|
+
|
|
43
|
+
// MODULES //
|
|
44
|
+
|
|
45
|
+
var main = require( './main.js' );
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
// EXPORTS //
|
|
49
|
+
|
|
50
|
+
module.exports = main;
|
|
@@ -0,0 +1,241 @@
|
|
|
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 isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
|
|
25
|
+
var isEven = require( '@stdlib/math/base/assert/is-even' );
|
|
26
|
+
var iteratorSymbol = require( '@stdlib/symbol/iterator' );
|
|
27
|
+
var format = require( '@stdlib/string/format' );
|
|
28
|
+
var sinpi = require( '@stdlib/math/base/special/sinpi' );
|
|
29
|
+
var floor = require( '@stdlib/math/base/special/floor' );
|
|
30
|
+
var validate = require( './validate.js' );
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
// MAIN //
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Returns an iterator which generates a periodic sinc waveform.
|
|
37
|
+
*
|
|
38
|
+
* ## Method
|
|
39
|
+
*
|
|
40
|
+
* - The periodic sinc function, or Dirichlet function, is defined as
|
|
41
|
+
*
|
|
42
|
+
* ```tex
|
|
43
|
+
* D_N(x; A) = \begin{cases}
|
|
44
|
+
* A \cdot \frac{\sin(Nx/2)}{N\sin(x/2)} & x \neq 2\pi k\ \textrm{for} k = 0, \pm 1, \pm 2, \pm 3, \ldots \\
|
|
45
|
+
* A \cdot (-1)^{k(N-1)} & x = 2\pi k\ \textrm{for} k = 0, \pm 1, \pm 2, \pm 3, \ldots
|
|
46
|
+
* \end{cases}
|
|
47
|
+
* ```
|
|
48
|
+
*
|
|
49
|
+
* where, for odd \\( N \\), the waveform period is \\( 2\pi \\), and, for even \\( N \\), the waveform period is \\( 4\pi \\).
|
|
50
|
+
*
|
|
51
|
+
* - In order to evaluate the periodic sinc function in terms of an iteration number \\( t \\) and a specified period (period \\( \tau \\)), rather than radians, for odd \\( N \\), we define
|
|
52
|
+
*
|
|
53
|
+
* ```tex
|
|
54
|
+
* x = \frac{2\pi(t-\varphi)}{\tau}
|
|
55
|
+
* ```
|
|
56
|
+
*
|
|
57
|
+
* and, for even \\( N \\), we define
|
|
58
|
+
*
|
|
59
|
+
* ```tex
|
|
60
|
+
* x = \frac{4\pi(t-\varphi)}{\tau}
|
|
61
|
+
* ```
|
|
62
|
+
*
|
|
63
|
+
* and substitute accordingly.
|
|
64
|
+
*
|
|
65
|
+
* @param {PositiveInteger} n - order
|
|
66
|
+
* @param {Options} [options] - function options
|
|
67
|
+
* @param {PositiveInteger} [options.period=10] - number of iterations before a waveform repeats
|
|
68
|
+
* @param {NonNegativeNumber} [options.amplitude=1.0] - peak amplitude
|
|
69
|
+
* @param {integer} [options.offset=0] - phase offset (in units of iterations; zero-based)
|
|
70
|
+
* @param {NonNegativeInteger} [options.iter=1e308] - number of iterations
|
|
71
|
+
* @throws {TypeError} first argument must be a positive integer
|
|
72
|
+
* @throws {TypeError} options argument must be an object
|
|
73
|
+
* @throws {TypeError} must provide valid options
|
|
74
|
+
* @returns {Iterator} iterator
|
|
75
|
+
*
|
|
76
|
+
* @example
|
|
77
|
+
* var iter = iterPeriodicSinc( 7 );
|
|
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 iterPeriodicSinc( n, options ) {
|
|
91
|
+
var opts;
|
|
92
|
+
var iter;
|
|
93
|
+
var FLG;
|
|
94
|
+
var err;
|
|
95
|
+
var sgn;
|
|
96
|
+
var hwf;
|
|
97
|
+
var hw;
|
|
98
|
+
var t;
|
|
99
|
+
var s;
|
|
100
|
+
var i;
|
|
101
|
+
|
|
102
|
+
if ( !isPositiveInteger( n ) ) {
|
|
103
|
+
throw new TypeError( format( 'invalid argument. First argument must be a positive integer. Value: `%s`.', n ) );
|
|
104
|
+
}
|
|
105
|
+
opts = {
|
|
106
|
+
'period': 100,
|
|
107
|
+
'amplitude': 1.0,
|
|
108
|
+
'offset': 0,
|
|
109
|
+
'iter': 1e308
|
|
110
|
+
};
|
|
111
|
+
if ( arguments.length > 1 ) {
|
|
112
|
+
err = validate( opts, options );
|
|
113
|
+
if ( err ) {
|
|
114
|
+
throw err;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
t = ( opts.period-opts.offset ) % opts.period;
|
|
118
|
+
if ( t < 0 ) {
|
|
119
|
+
t += opts.period; // normalize such that t ϵ [0,τ]
|
|
120
|
+
}
|
|
121
|
+
if ( isEven( n ) ) {
|
|
122
|
+
if ( opts.offset >= 0 ) {
|
|
123
|
+
sgn = -1.0;
|
|
124
|
+
} else {
|
|
125
|
+
sgn = 1.0;
|
|
126
|
+
}
|
|
127
|
+
// Note: when `n` is even, the waveform period (in radians) is 4π, so we need to adjust the "period" parameter to ensure that the waveform repeats within the specified number of iterations:
|
|
128
|
+
hw = opts.period / 2;
|
|
129
|
+
hwf = floor( hw ); // note: τ could be an odd number; in which case, negative peaks happen "between" two iterations (t%τ and t%(τ+1))
|
|
130
|
+
s = n / hw;
|
|
131
|
+
} else {
|
|
132
|
+
s = n / opts.period;
|
|
133
|
+
}
|
|
134
|
+
t -= 1;
|
|
135
|
+
i = 0;
|
|
136
|
+
|
|
137
|
+
// Create an iterator protocol-compliant object:
|
|
138
|
+
iter = {};
|
|
139
|
+
setReadOnly( iter, 'next', ( sgn === void 0 ) ? next2 : next1 );
|
|
140
|
+
setReadOnly( iter, 'return', end );
|
|
141
|
+
|
|
142
|
+
// If an environment supports `Symbol.iterator`, make the iterator iterable:
|
|
143
|
+
if ( iteratorSymbol ) {
|
|
144
|
+
setReadOnly( iter, iteratorSymbol, factory );
|
|
145
|
+
}
|
|
146
|
+
return iter;
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Returns an iterator protocol-compliant object containing the next iterated value.
|
|
150
|
+
*
|
|
151
|
+
* @private
|
|
152
|
+
* @returns {Object} iterator protocol-compliant object
|
|
153
|
+
*/
|
|
154
|
+
function next1() {
|
|
155
|
+
var v;
|
|
156
|
+
i += 1;
|
|
157
|
+
if ( FLG || i > opts.iter ) {
|
|
158
|
+
return {
|
|
159
|
+
'done': true
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
t += 1;
|
|
163
|
+
t %= opts.period;
|
|
164
|
+
if ( t === 0 || t === hw ) {
|
|
165
|
+
sgn *= -1.0;
|
|
166
|
+
v = sgn * opts.amplitude;
|
|
167
|
+
} else {
|
|
168
|
+
if ( t === hwf ) {
|
|
169
|
+
// We just passed a negative peak, so we need flip the sign in order to ensure that the waveform at `t%τ=0` is the correct sign:
|
|
170
|
+
sgn *= -1.0;
|
|
171
|
+
}
|
|
172
|
+
v = opts.amplitude * sinpi(s*t) / ( n*sinpi(t/hw) );
|
|
173
|
+
}
|
|
174
|
+
return {
|
|
175
|
+
'value': v,
|
|
176
|
+
'done': false
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* Returns an iterator protocol-compliant object containing the next iterated value.
|
|
182
|
+
*
|
|
183
|
+
* @private
|
|
184
|
+
* @returns {Object} iterator protocol-compliant object
|
|
185
|
+
*/
|
|
186
|
+
function next2() {
|
|
187
|
+
var v;
|
|
188
|
+
i += 1;
|
|
189
|
+
if ( FLG || i > opts.iter ) {
|
|
190
|
+
return {
|
|
191
|
+
'done': true
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
t += 1;
|
|
195
|
+
t %= opts.period;
|
|
196
|
+
if ( t === 0 ) {
|
|
197
|
+
v = opts.amplitude;
|
|
198
|
+
} else {
|
|
199
|
+
v = opts.amplitude * sinpi(s*t) / ( n*sinpi(t/opts.period) );
|
|
200
|
+
}
|
|
201
|
+
return {
|
|
202
|
+
'value': v,
|
|
203
|
+
'done': false
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Finishes an iterator.
|
|
209
|
+
*
|
|
210
|
+
* @private
|
|
211
|
+
* @param {*} [value] - value to return
|
|
212
|
+
* @returns {Object} iterator protocol-compliant object
|
|
213
|
+
*/
|
|
214
|
+
function end( value ) {
|
|
215
|
+
FLG = true;
|
|
216
|
+
if ( arguments.length ) {
|
|
217
|
+
return {
|
|
218
|
+
'value': value,
|
|
219
|
+
'done': true
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
return {
|
|
223
|
+
'done': true
|
|
224
|
+
};
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* Returns a new iterator.
|
|
229
|
+
*
|
|
230
|
+
* @private
|
|
231
|
+
* @returns {Iterator} iterator
|
|
232
|
+
*/
|
|
233
|
+
function factory() {
|
|
234
|
+
return iterPeriodicSinc( n, opts );
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
// EXPORTS //
|
|
240
|
+
|
|
241
|
+
module.exports = iterPeriodicSinc;
|
|
@@ -0,0 +1,90 @@
|
|
|
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 isInteger = require( '@stdlib/assert/is-integer' ).isPrimitive;
|
|
26
|
+
var isPositiveInteger = require( '@stdlib/assert/is-positive-integer' ).isPrimitive;
|
|
27
|
+
var isNonNegativeInteger = require( '@stdlib/assert/is-nonnegative-integer' ).isPrimitive;
|
|
28
|
+
var isNonNegativeNumber = require( '@stdlib/assert/is-nonnegative-number' ).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 {NonNegativeNumber} [options.amplitude] - peak amplitude
|
|
42
|
+
* @param {integer} [options.offset] - phase offset (in units of iterations)
|
|
43
|
+
* @param {NonNegativeInteger} [options.iter] - number of iterations
|
|
44
|
+
* @returns {(Error|null)} null or an error object
|
|
45
|
+
*
|
|
46
|
+
* @example
|
|
47
|
+
* var opts = {};
|
|
48
|
+
* var options = {
|
|
49
|
+
* 'iter': 100
|
|
50
|
+
* };
|
|
51
|
+
* var err = validate( opts, options );
|
|
52
|
+
* if ( err ) {
|
|
53
|
+
* throw err;
|
|
54
|
+
* }
|
|
55
|
+
*/
|
|
56
|
+
function validate( opts, options ) {
|
|
57
|
+
if ( !isPlainObject( options ) ) {
|
|
58
|
+
return new TypeError( format( 'invalid argument. Options argument must be an object. Value: `%s`.', options ) );
|
|
59
|
+
}
|
|
60
|
+
if ( hasOwnProp( options, 'period' ) ) {
|
|
61
|
+
opts.period = options.period;
|
|
62
|
+
if ( !isPositiveInteger( options.period ) ) {
|
|
63
|
+
return new TypeError( format( 'invalid option. `%s` option must be an positive integer. Option: `%s`.', 'period', options.period ) );
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
if ( hasOwnProp( options, 'amplitude' ) ) {
|
|
67
|
+
opts.amplitude = options.amplitude;
|
|
68
|
+
if ( !isNonNegativeNumber( options.amplitude ) ) {
|
|
69
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative number. Option: `%s`.', 'amplitude', options.amplitude ) );
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if ( hasOwnProp( options, 'offset' ) ) {
|
|
73
|
+
opts.offset = options.offset;
|
|
74
|
+
if ( !isInteger( options.offset ) ) {
|
|
75
|
+
return new TypeError( format( 'invalid option. `%s` option must be an integer. Option: `%s`.', 'offset', options.offset ) );
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
if ( hasOwnProp( options, 'iter' ) ) {
|
|
79
|
+
opts.iter = options.iter;
|
|
80
|
+
if ( !isNonNegativeInteger( options.iter ) ) {
|
|
81
|
+
return new TypeError( format( 'invalid option. `%s` option must be a nonnegative integer. Option: `%s`.', 'iter', options.iter ) );
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
|
|
88
|
+
// EXPORTS //
|
|
89
|
+
|
|
90
|
+
module.exports = validate;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@stdlib/simulate/iter/periodic-sinc",
|
|
3
|
+
"version": "0.0.0",
|
|
4
|
+
"description": "Create an iterator which generates a periodic sinc 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
|
+
"sinc",
|
|
56
|
+
"cardinal",
|
|
57
|
+
"sine",
|
|
58
|
+
"dirichlet",
|
|
59
|
+
"diric",
|
|
60
|
+
"wave",
|
|
61
|
+
"signal",
|
|
62
|
+
"processing",
|
|
63
|
+
"waveform",
|
|
64
|
+
"periodic",
|
|
65
|
+
"iterator",
|
|
66
|
+
"iterate",
|
|
67
|
+
"iteration",
|
|
68
|
+
"iter"
|
|
69
|
+
]
|
|
70
|
+
}
|