Skip to main content
Glama
nbiish
by nbiish

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
NameRequiredDescriptionDefault
expressionYesFunction of time
timeVarYesTime variable
freqVarYesFrequency variable

Implementation Reference

  • 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}`;
      }
    };
  • 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);
      }
    );

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/nbiish/mcp-calc-tools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server