rf-touchstone 0.0.0 → 0.0.2

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.
@@ -0,0 +1,394 @@
1
+ /**
2
+ * Frequency units: 'Hz', 'kHz', 'MHz', 'GHz'
3
+ * Touchstone standard doesn't support THz as the frequency unit in Touchstone file
4
+ */
5
+ export declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
6
+ /**
7
+ * Type definition for frequency units
8
+ * - Hz: Hertz (cycles per second)
9
+ * - kHz: Kilohertz (10³ Hz)
10
+ * - MHz: Megahertz (10⁶ Hz)
11
+ * - GHz: Gigahertz (10⁹ Hz)
12
+ * Touchstone standard doesn't support THz as the frequency unit in Touchstone file
13
+ */
14
+ export type FrequencyUnit = (typeof FrequencyUnits)[number];
15
+ /**
16
+ * Speed of light in m/s
17
+ */
18
+ export declare const SPEED_OF_LIGHT = 299792458;
19
+ /**
20
+ * Multipliers for converting from any FrequencyUnit or THz to Hz
21
+ */
22
+ export declare const FREQUENCY_MULTIPLIERS: Record<FrequencyUnit | 'THz', number>;
23
+ /**
24
+ * Multipliers for converting from other wavelength units to meters
25
+ */
26
+ export declare const WAVELENGTH_MULTIPLIERS_TO_M: Record<string, number>;
27
+ /**
28
+ * Class representing frequency data in RF and microwave engineering
29
+ *
30
+ * @remarks
31
+ * The Frequency class manages frequency-related data, including:
32
+ * - Frequency unit management
33
+ * - Storage of frequency points
34
+ * - Unit conversion capabilities
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * const freq = new Frequency();
39
+ * freq.unit = 'GHz';
40
+ * freq.f_scale = [1.0, 2.0, 3.0];
41
+ * ```
42
+ */
43
+ export declare class Frequency {
44
+ /**
45
+ * Internal storage for frequency unit
46
+ * Defaults to 'Hz' as the base SI unit for frequency
47
+ */
48
+ private _unit;
49
+ /**
50
+ * Sets the frequency unit for the instance
51
+ *
52
+ * @param newUnit - The frequency unit to set
53
+ * @throws {Error} If the provided unit is not one of the supported frequency units
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * const freq = new Frequency();
58
+ * freq.unit = 'MHz'; // Sets unit to Megahertz
59
+ * ```
60
+ */
61
+ set unit(newUnit: FrequencyUnit);
62
+ /**
63
+ * Gets the current frequency unit
64
+ *
65
+ * @returns The current frequency unit
66
+ *
67
+ * @example
68
+ * ```typescript
69
+ * const freq = new Frequency();
70
+ * console.log(freq.unit); // Outputs: 'Hz'
71
+ * ```
72
+ */
73
+ get unit(): FrequencyUnit;
74
+ /**
75
+ * Internal storage for frequency points array
76
+ * Each element represents a frequency point in the specified unit
77
+ * @private
78
+ */
79
+ private _f_scaled;
80
+ /**
81
+ * Array of frequency points in the current frequency unit
82
+ * Each element represents a discrete frequency point for measurement or analysis
83
+ *
84
+ * @param value - Array of frequency points
85
+ * @throws {Error} If the input is not an array
86
+ * @throws {Error} If any element in the array is not a number
87
+ * @throws {Error} If the array contains negative frequencies
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * const freq = new Frequency();
92
+ * freq.unit = 'GHz';
93
+ * freq.f_scaled = [1.0, 1.5, 2.0]; // Sets frequency points in GHz
94
+ * ```
95
+ */
96
+ set f_scaled(value: number[]);
97
+ /**
98
+ * Gets the array of frequency points
99
+ * @returns Array of frequency points in the current unit
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * const freq = new Frequency();
104
+ * freq.unit = 'MHz';
105
+ * freq.f_scaled = [100, 200, 300];
106
+ * console.log(freq.f_scaled); // Outputs: [100, 200, 300]
107
+ * ```
108
+ */
109
+ get f_scaled(): number[];
110
+ /**
111
+ * Private helper method to get frequency values in a target unit.
112
+ * @param targetUnit - The key of the target frequency unit in FREQUENCY_MULTIPLIERS.
113
+ * @returns Array of frequency points in the target unit.
114
+ */
115
+ private _getFrequencyInTargetUnit;
116
+ /**
117
+ * Private helper method to set frequency values from a source unit.
118
+ * @param values - Array of frequency points in the source unit.
119
+ * @param sourceUnit - The key of the source frequency unit in FREQUENCY_MULTIPLIERS.
120
+ */
121
+ private _setFrequencyFromTargetUnit;
122
+ /**
123
+ * Gets frequency points in Hz
124
+ * @returns Array of frequency points in Hz
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * const freq = new Frequency();
129
+ * freq.unit = 'GHz';
130
+ * freq.f_scaled = [1, 2, 3]; // 1 GHz, 2 GHz, 3 GHz
131
+ * console.log(freq.f_Hz); // Outputs: [1e9, 2e9, 3e9]
132
+ * ```
133
+ */
134
+ get f_Hz(): number[];
135
+ /**
136
+ * Sets frequency points assuming input is in Hz
137
+ * @param values - Array of frequency points in Hz
138
+ *
139
+ * @example
140
+ * ```typescript
141
+ * const freq = new Frequency();
142
+ * freq.unit = 'MHz';
143
+ * freq.f_Hz = [1e9, 2e9, 3e9]; // Sets frequencies as 1 GHz, 2 GHz, 3 GHz
144
+ * console.log(freq.f_scaled); // Outputs: [1000, 2000, 3000] (in MHz)
145
+ * ```
146
+ */
147
+ set f_Hz(values: number[]);
148
+ /**
149
+ * Gets frequency points in kHz
150
+ * @returns Array of frequency points in kHz
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const freq = new Frequency();
155
+ * freq.unit = 'Hz';
156
+ * freq.f_scaled = [1000, 2000, 3000]; // 1 kHz, 2 kHz, 3 kHz
157
+ * console.log(freq.f_kHz); // Outputs: [1, 2, 3]
158
+ * ```
159
+ */
160
+ get f_kHz(): number[];
161
+ /**
162
+ * Sets frequency points assuming input is in kHz
163
+ * @param values - Array of frequency points in kHz
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * const freq = new Frequency();
168
+ * freq.unit = 'Hz';
169
+ * freq.f_kHz = [1, 2, 3]; // Sets frequencies as 1 kHz, 2 kHz, 3 kHz
170
+ * console.log(freq.f_scaled); // Outputs: [1000, 2000, 3000] (in Hz)
171
+ * ```
172
+ */
173
+ set f_kHz(values: number[]);
174
+ /**
175
+ * Gets frequency points in MHz
176
+ * @returns Array of frequency points in MHz
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * const freq = new Frequency();
181
+ * freq.unit = 'GHz';
182
+ * freq.f_scaled = [0.1, 0.2, 0.3]; // 0.1 GHz, 0.2 GHz, 0.3 GHz
183
+ * console.log(freq.f_MHz); // Outputs: [100, 200, 300]
184
+ * ```
185
+ */
186
+ get f_MHz(): number[];
187
+ /**
188
+ * Sets frequency points assuming input is in MHz
189
+ * @param values - Array of frequency points in MHz
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * const freq = new Frequency();
194
+ * freq.unit = 'GHz';
195
+ * freq.f_MHz = [100, 200, 300]; // Sets frequencies as 100 MHz, 200 MHz, 300 MHz
196
+ * console.log(freq.f_scaled); // Outputs: [0.1, 0.2, 0.3] (in GHz)
197
+ * ```
198
+ */
199
+ set f_MHz(values: number[]);
200
+ /**
201
+ * Gets frequency points in GHz
202
+ * @returns Array of frequency points in GHz
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const freq = new Frequency();
207
+ * freq.unit = 'MHz';
208
+ * freq.f_scaled = [1000, 2000, 3000]; // 1000 MHz, 2000 MHz, 3000 MHz
209
+ * console.log(freq.f_GHz); // Outputs: [1, 2, 3]
210
+ * ```
211
+ */
212
+ get f_GHz(): number[];
213
+ /**
214
+ * Sets frequency points assuming input is in GHz
215
+ * @param values - Array of frequency points in GHz
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * const freq = new Frequency();
220
+ * freq.unit = 'MHz';
221
+ * freq.f_GHz = [1, 2, 3]; // Sets frequencies as 1 GHz, 2 GHz, 3 GHz
222
+ * console.log(freq.f_scaled); // Outputs: [1000, 2000, 3000] (in MHz)
223
+ * ```
224
+ */
225
+ set f_GHz(values: number[]);
226
+ /**
227
+ * Gets frequency points in THz
228
+ * @returns Array of frequency points in THz
229
+ *
230
+ * @example
231
+ * ```typescript
232
+ * const freq = new Frequency();
233
+ * freq.unit = 'GHz';
234
+ * freq.f_scaled = [1000, 2000, 3000]; // 1000 GHz, 2000 GHz, 3000 GHz
235
+ * console.log(freq.f_THz); // Outputs: [1, 2, 3]
236
+ * ```
237
+ */
238
+ get f_THz(): number[];
239
+ /**
240
+ * Sets frequency points assuming input is in THz
241
+ * @param values - Array of frequency points in THz
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * const freq = new Frequency();
246
+ * freq.unit = 'GHz';
247
+ * freq.f_THz = [1, 2, 3]; // Sets frequencies as 1 THz, 2 THz, 3 THz
248
+ * console.log(freq.f_scaled); // Outputs: [1000, 2000, 3000] (in GHz)
249
+ * ```
250
+ */
251
+ set f_THz(values: number[]);
252
+ /**
253
+ * Private helper method to get wavelength values in a target unit.
254
+ * @param targetWavelengthUnit - The key of the target wavelength unit in WAVELENGTH_MULTIPLIERS_TO_M.
255
+ * @returns Array of wavelength points in the target unit.
256
+ */
257
+ private _getWavelengthInTargetUnit;
258
+ /**
259
+ * Private helper method to set frequency values from wavelength values in a source unit.
260
+ * @param values - Array of wavelength points in the source unit.
261
+ * @param sourceWavelengthUnit - The key of the source wavelength unit in WAVELENGTH_MULTIPLIERS_TO_M.
262
+ */
263
+ private _setWavelengthFromTargetUnit;
264
+ /**
265
+ * Gets wavelength in meters
266
+ * @returns Array of wavelength values in meters
267
+ *
268
+ * @example
269
+ * ```typescript
270
+ * const freq = new Frequency();
271
+ * freq.unit = 'GHz';
272
+ * freq.f_scaled = [1, 2, 3]; // Frequencies in GHz
273
+ * console.log(freq.wavelength_m); // Outputs: Wavelengths in meters
274
+ * ```
275
+ */
276
+ get wavelength_m(): number[];
277
+ /**
278
+ * Sets wavelength in meters. Converts to frequency and stores.
279
+ * @param values - Array of wavelength values in meters
280
+ *
281
+ * @example
282
+ * ```typescript
283
+ * const freq = new Frequency();
284
+ * freq.unit = 'GHz';
285
+ * freq.wavelength_m = [0.3, 0.15, 0.1]; // Wavelengths in meters
286
+ * console.log(freq.f_scaled); // Outputs: Frequencies in GHz
287
+ * ```
288
+ */
289
+ set wavelength_m(values: number[]);
290
+ /**
291
+ * Gets wavelength in centimeters
292
+ * @returns Array of wavelength values in centimeters
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * const freq = new Frequency();
297
+ * freq.unit = 'GHz';
298
+ * freq.f_scaled = [10, 20, 30]; // Frequencies in GHz
299
+ * console.log(freq.wavelength_cm); // Outputs: Wavelengths in centimeters
300
+ * ```
301
+ */
302
+ get wavelength_cm(): number[];
303
+ /**
304
+ * Sets wavelength in centimeters. Converts to frequency and stores.
305
+ * @param values - Array of wavelength values in centimeters
306
+ *
307
+ * @example
308
+ * ```typescript
309
+ * const freq = new Frequency();
310
+ * freq.unit = 'GHz';
311
+ * freq.wavelength_cm = [30, 15, 10]; // Wavelengths in centimeters
312
+ * console.log(freq.f_scaled); // Outputs: Frequencies in GHz
313
+ * ```
314
+ */
315
+ set wavelength_cm(values: number[]);
316
+ /**
317
+ * Gets wavelength in millimeters
318
+ * @returns Array of wavelength values in millimeters
319
+ *
320
+ * @example
321
+ * ```typescript
322
+ * const freq = new Frequency();
323
+ * freq.unit = 'GHz';
324
+ * freq.f_scaled = [100, 200, 300]; // Frequencies in GHz
325
+ * console.log(freq.wavelength_mm); // Outputs: Wavelengths in millimeters
326
+ * ```
327
+ */
328
+ get wavelength_mm(): number[];
329
+ /**
330
+ * Sets wavelength in millimeters. Converts to frequency and stores.
331
+ * @param values - Array of wavelength values in millimeters
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * const freq = new Frequency();
336
+ * freq.unit = 'GHz';
337
+ * freq.wavelength_mm = [300, 150, 100]; // Wavelengths in millimeters
338
+ * console.log(freq.f_scaled); // Outputs: Frequencies in GHz
339
+ * ```
340
+ */
341
+ set wavelength_mm(values: number[]);
342
+ /**
343
+ * Gets wavelength in micrometers
344
+ * @returns Array of wavelength values in micrometers
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * const freq = new Frequency();
349
+ * freq.unit = 'GHz';
350
+ * freq.f_scaled = [1000, 2000, 3000]; // Frequencies in GHz
351
+ * console.log(freq.wavelength_um); // Outputs: Wavelengths in micrometers
352
+ * ```
353
+ */
354
+ get wavelength_um(): number[];
355
+ /**
356
+ * Sets wavelength in micrometers. Converts to frequency and stores.
357
+ * @param values - Array of wavelength values in micrometers
358
+ *
359
+ * @example
360
+ * ```typescript
361
+ * const freq = new Frequency();
362
+ * freq.unit = 'GHz';
363
+ * freq.wavelength_um = [300000, 150000, 100000]; // Wavelengths in micrometers
364
+ * console.log(freq.f_scaled); // Outputs: Frequencies in GHz
365
+ * ```
366
+ */
367
+ set wavelength_um(values: number[]);
368
+ /**
369
+ * Gets wavelength in nanometers
370
+ * @returns Array of wavelength values in nanometers
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * const freq = new Frequency();
375
+ * freq.unit = 'THz';
376
+ * freq.f_scaled = [100, 200, 300]; // Frequencies in THz
377
+ * console.log(freq.wavelength_nm); // Outputs: Wavelengths in nanometers
378
+ * ```
379
+ */
380
+ get wavelength_nm(): number[];
381
+ /**
382
+ * Sets wavelength in nanometers. Converts to frequency and stores.
383
+ * @param values - Array of wavelength values in nanometers
384
+ *
385
+ * @example
386
+ * ```typescript
387
+ * const freq = new Frequency();
388
+ * freq.unit = 'THz';
389
+ * freq.wavelength_nm = [300, 150, 100]; // Wavelengths in nanometers
390
+ * console.log(freq.f_scaled); // Outputs: Frequencies in THz
391
+ * ```
392
+ */
393
+ set wavelength_nm(values: number[]);
394
+ }
@@ -0,0 +1,24 @@
1
+ import { abs, add, arg, log10, index, multiply, pi, pow, round, subset } from 'mathjs';
2
+ /**
3
+ * Creates a complex value or converts a value to a complex value.
4
+ *
5
+ * @see {@link https://mathjs.org/docs/reference/functions/complex.html | Math.js documentation for complex}
6
+ */
7
+ export declare const complex: {
8
+ (arg?: import('mathjs').MathNumericType | string | import('mathjs').PolarCoordinates): import('mathjs').Complex;
9
+ (arg?: import('mathjs').MathCollection): import('mathjs').MathCollection;
10
+ (re: number, im: number): import('mathjs').Complex;
11
+ };
12
+ /**
13
+ * Create an array or matrix with a range of numbers.
14
+ *
15
+ * @see {@link https://mathjs.org/docs/reference/functions/range.html | Math.js documentation for range}
16
+ */
17
+ export declare const range: {
18
+ (str: string, includeEnd?: boolean): import('mathjs').Matrix;
19
+ (start: number | import('mathjs').BigNumber, end: number | import('mathjs').BigNumber, includeEnd?: boolean): import('mathjs').Matrix;
20
+ (start: number | import('mathjs').BigNumber | import('mathjs').Unit, end: number | import('mathjs').BigNumber | import('mathjs').Unit, step: number | import('mathjs').BigNumber | import('mathjs').Unit, includeEnd?: boolean): import('mathjs').Matrix;
21
+ };
22
+ export { abs, add, arg, log10, index, multiply, pi, pow, round, subset };
23
+ export * from './frequency';
24
+ export * from './touchstone';