fourier_transform
Calculate the Fourier transform of a function to analyze signals in the frequency domain. Convert time-domain expressions to frequency-domain representations for signal processing applications.
Instructions
Calculate the Fourier transform of a function
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Function of time | |
| timeVar | Yes | Time variable | |
| freqVar | Yes | Frequency variable |
Implementation Reference
- index.js:392-420 (handler)Core handler function that computes the Fourier transform using numerical integration approximating the integral from -inf to inf with symmetric limits.const fourierTransform = (expr, t, omega) => { try { const node = math.parse(expr); // Using numerical integration for a basic approximation const limit = 50; // Approximation of infinity const steps = 1000; const dt = (2 * limit) / steps; let result = math.complex(0, 0); for (let i = 0; i < steps; i++) { const time = -limit + i * dt; const scope = { [t]: time }; const ft = math.evaluate(node, scope); const expTerm = math.exp( math.multiply( math.complex(0, -1), omega, time ) ); result = math.add(result, math.multiply(ft, expTerm, dt)); } return result.toString(); } catch (e) { return `Error: ${e.message}`; } };
- index.js:458-467 (schema)Tool schema defining input parameters (expression, timeVar, freqVar) and string output.{ name: 'fourier_transform', description: 'Calculate the Fourier transform of a function', inputSchema: z.object({ expression: z.string().describe('Function of time'), timeVar: z.string().describe('Time variable'), freqVar: z.string().describe('Frequency variable') }), outputSchema: z.string(), },
- index.js:457-471 (registration)Registers the fourier_transform tool using ai.defineTool, including schema and thin handler wrapper that delegates to the core fourierTransform function.ai.defineTool( { name: 'fourier_transform', description: 'Calculate the Fourier transform of a function', inputSchema: z.object({ expression: z.string().describe('Function of time'), timeVar: z.string().describe('Time variable'), freqVar: z.string().describe('Frequency variable') }), outputSchema: z.string(), }, async ({ expression, timeVar, freqVar }) => { return fourierTransform(expression, timeVar, freqVar); } );