fourier_transform
Transform time-domain functions into frequency-domain representations using the Fourier transform. Input a function, specify time and frequency variables, and generate precise results for advanced analysis.
Instructions
Calculate the Fourier transform of a function
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Function of time | |
| freqVar | Yes | Frequency variable | |
| timeVar | Yes | Time variable |
Implementation Reference
- index.js:392-420 (handler)Core implementation of the fourier_transform tool logic using numerical integration to approximate the Fourier transform.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:457-471 (registration)Registration of the fourier_transform tool with Genkit's ai.defineTool, including schema definitions and handler 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); } );
- index.js:461-466 (schema)Input and output schema definitions for the fourier_transform tool using Zod validation.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(),