rf-touchstone 0.0.2 → 0.0.4

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.
@@ -1,15 +1,14 @@
1
1
  /**
2
- * Frequency units: 'Hz', 'kHz', 'MHz', 'GHz'
3
- * Touchstone standard doesn't support THz as the frequency unit in Touchstone file
2
+ * Supported frequency units in the Touchstone specification.
3
+ * Note: THz is not officially supported as a file header unit in Touchstone v1.x/v2.x.
4
4
  */
5
5
  export declare const FrequencyUnits: readonly ["Hz", "kHz", "MHz", "GHz"];
6
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
7
+ * Type representing the frequency unit.
8
+ * - Hz: Hertz ($10^0$ Hz)
9
+ * - kHz: Kilohertz ($10^3$ Hz)
10
+ * - MHz: Megahertz ($10^6$ Hz)
11
+ * - GHz: Gigahertz ($10^9$ Hz)
13
12
  */
14
13
  export type FrequencyUnit = (typeof FrequencyUnits)[number];
15
14
  /**
@@ -25,19 +24,29 @@ export declare const FREQUENCY_MULTIPLIERS: Record<FrequencyUnit | 'THz', number
25
24
  */
26
25
  export declare const WAVELENGTH_MULTIPLIERS_TO_M: Record<string, number>;
27
26
  /**
28
- * Class representing frequency data in RF and microwave engineering
27
+ * Represents frequency data and provides utility methods for unit conversion and wavelength calculation.
29
28
  *
30
29
  * @remarks
31
- * The Frequency class manages frequency-related data, including:
32
- * - Frequency unit management
33
- * - Storage of frequency points
34
- * - Unit conversion capabilities
30
+ * The `Frequency` class is designed to handle frequency points commonly used in RF, microwave,
31
+ * and high-speed digital engineering. It maintains an internal unit and a set of frequency points,
32
+ * allowing for seamless conversion between different frequency and wavelength units.
33
+ *
34
+ * ##### Key Features:
35
+ * - **Unit Awareness**: Keeps track of whether frequencies are defined in Hz, MHz, GHz, etc.
36
+ * - **Automatic Conversion**: Automatically scales frequency points when the `unit` property is changed.
37
+ * - **Wavelength Utilities**: Provides getters and setters for wavelength ($\lambda = c/f$) in various metric units.
35
38
  *
36
39
  * @example
40
+ * #### Basic Usage
37
41
  * ```typescript
42
+ * import { Frequency } from 'rf-touchstone';
43
+ *
38
44
  * const freq = new Frequency();
39
45
  * freq.unit = 'GHz';
40
- * freq.f_scale = [1.0, 2.0, 3.0];
46
+ * freq.f_scaled = [1.0, 2.0, 5.0];
47
+ *
48
+ * console.log(freq.f_Hz); // [1e9, 2e9, 5e9]
49
+ * console.log(freq.wavelength_mm); // [299.79, 149.90, 59.96]
41
50
  * ```
42
51
  */
43
52
  export declare class Frequency {
@@ -47,28 +56,15 @@ export declare class Frequency {
47
56
  */
48
57
  private _unit;
49
58
  /**
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
59
+ * Sets the frequency unit. If frequency points already exist, they will be
60
+ * automatically rescaled to the new unit.
54
61
  *
55
- * @example
56
- * ```typescript
57
- * const freq = new Frequency();
58
- * freq.unit = 'MHz'; // Sets unit to Megahertz
59
- * ```
62
+ * @param newUnit - The target frequency unit (Hz, kHz, MHz, or GHz).
63
+ * @throws Error if the provided unit is invalid.
60
64
  */
61
65
  set unit(newUnit: FrequencyUnit);
62
66
  /**
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
- * ```
67
+ * Gets the current frequency unit.
72
68
  */
73
69
  get unit(): FrequencyUnit;
74
70
  /**
@@ -78,33 +74,14 @@ export declare class Frequency {
78
74
  */
79
75
  private _f_scaled;
80
76
  /**
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
77
+ * Sets the array of frequency points in the current frequency unit.
88
78
  *
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
- * ```
79
+ * @param value - Array of numerical frequency points.
80
+ * @throws Error if the input is not a non-negative number array.
95
81
  */
96
82
  set f_scaled(value: number[]);
97
83
  /**
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
- * ```
84
+ * Gets the array of frequency points in the current unit.
108
85
  */
109
86
  get f_scaled(): number[];
110
87
  /**
@@ -114,139 +91,49 @@ export declare class Frequency {
114
91
  */
115
92
  private _getFrequencyInTargetUnit;
116
93
  /**
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.
94
+ * Internal helper to set frequency values from a source unit.
95
+ * @param values - Array of frequency points.
96
+ * @param sourceUnit - The source frequency unit key.
120
97
  */
121
98
  private _setFrequencyFromTargetUnit;
122
99
  /**
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
- * ```
100
+ * Gets the frequency points in Hertz (Hz).
133
101
  */
134
102
  get f_Hz(): number[];
135
103
  /**
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
- * ```
104
+ * Sets the frequency points in Hertz (Hz).
146
105
  */
147
106
  set f_Hz(values: number[]);
148
107
  /**
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
- * ```
108
+ * Gets the frequency points in Kilohertz (kHz).
159
109
  */
160
110
  get f_kHz(): number[];
161
111
  /**
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
- * ```
112
+ * Sets the frequency points in Kilohertz (kHz).
172
113
  */
173
114
  set f_kHz(values: number[]);
174
115
  /**
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
- * ```
116
+ * Gets the frequency points in Megahertz (MHz).
185
117
  */
186
118
  get f_MHz(): number[];
187
119
  /**
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
- * ```
120
+ * Sets the frequency points in Megahertz (MHz).
198
121
  */
199
122
  set f_MHz(values: number[]);
200
123
  /**
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
- * ```
124
+ * Gets the frequency points in Gigahertz (GHz).
211
125
  */
212
126
  get f_GHz(): number[];
213
127
  /**
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
- * ```
128
+ * Sets the frequency points in Gigahertz (GHz).
224
129
  */
225
130
  set f_GHz(values: number[]);
226
131
  /**
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
- * ```
132
+ * Gets the frequency points in Terahertz (THz).
237
133
  */
238
134
  get f_THz(): number[];
239
135
  /**
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
- * ```
136
+ * Sets the frequency points in Terahertz (THz).
250
137
  */
251
138
  set f_THz(values: number[]);
252
139
  /**
@@ -262,133 +149,44 @@ export declare class Frequency {
262
149
  */
263
150
  private _setWavelengthFromTargetUnit;
264
151
  /**
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
- * ```
152
+ * Gets the wavelength in meters (m).
275
153
  */
276
154
  get wavelength_m(): number[];
277
155
  /**
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
- * ```
156
+ * Sets the wavelength in meters (m).
157
+ * Note: Changing wavelengths will update the underlying frequency points.
288
158
  */
289
159
  set wavelength_m(values: number[]);
290
160
  /**
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
- * ```
161
+ * Gets the wavelength in centimeters (cm).
301
162
  */
302
163
  get wavelength_cm(): number[];
303
164
  /**
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
- * ```
165
+ * Sets the wavelength in centimeters (cm).
314
166
  */
315
167
  set wavelength_cm(values: number[]);
316
168
  /**
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
- * ```
169
+ * Gets the wavelength in millimeters (mm).
327
170
  */
328
171
  get wavelength_mm(): number[];
329
172
  /**
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
- * ```
173
+ * Sets the wavelength in millimeters (mm).
340
174
  */
341
175
  set wavelength_mm(values: number[]);
342
176
  /**
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
- * ```
177
+ * Gets the wavelength in micrometers (μm).
353
178
  */
354
179
  get wavelength_um(): number[];
355
180
  /**
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
- * ```
181
+ * Sets the wavelength in micrometers (μm).
366
182
  */
367
183
  set wavelength_um(values: number[]);
368
184
  /**
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
- * ```
185
+ * Gets the wavelength in nanometers (nm).
379
186
  */
380
187
  get wavelength_nm(): number[];
381
188
  /**
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
- * ```
189
+ * Sets the wavelength in nanometers (nm).
392
190
  */
393
191
  set wavelength_nm(values: number[]);
394
192
  }
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import { abs, add, arg, log10, index, multiply, pi, pow, round, subset } from 'mathjs';
2
1
  /**
3
2
  * Creates a complex value or converts a value to a complex value.
4
3
  *
@@ -19,6 +18,7 @@ export declare const range: {
19
18
  (start: number | import('mathjs').BigNumber, end: number | import('mathjs').BigNumber, includeEnd?: boolean): import('mathjs').Matrix;
20
19
  (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
20
  };
22
- export { abs, add, arg, log10, index, multiply, pi, pow, round, subset };
21
+ export { abs, add, arg, log10, index, multiply, pi, pow, round, subset, } from 'mathjs';
22
+ export type { Complex } from 'mathjs';
23
23
  export * from './frequency';
24
24
  export * from './touchstone';