z_transform
Calculate the Z-transform of discrete-time functions to analyze signals and systems in the frequency domain. Provide the function expression, time variable, and Z-transform variable for computation.
Instructions
Calculate the Z-transform of a function
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| expression | Yes | Function of discrete time | |
| timeVar | Yes | Discrete time variable | |
| zVar | Yes | Z-transform variable | |
| limit | No | Upper limit for summation (default: 100) |
Implementation Reference
- index.js:422-438 (handler)Core handler function implementing the Z-transform calculation using numerical summation of f[n] * z^{-n} from n=0 to limit.const zTransform = (expr, n, z, limit = 100) => { try { const node = math.parse(expr); let result = math.complex(0, 0); for (let k = 0; k <= limit; k++) { const scope = { [n]: k }; const fn = math.evaluate(node, scope); const zTerm = math.pow(z, -k); result = math.add(result, math.multiply(fn, zTerm)); } return result.toString(); } catch (e) { return `Error: ${e.message}`; } };
- index.js:473-488 (registration)Registers the z_transform tool with Genkit AI, specifying name, description, input/output schemas, and handler.ai.defineTool( { name: 'z_transform', description: 'Calculate the Z-transform of a function', inputSchema: z.object({ expression: z.string().describe('Function of discrete time'), timeVar: z.string().describe('Discrete time variable'), zVar: z.string().describe('Z-transform variable'), limit: z.number().optional().describe('Upper limit for summation (default: 100)') }), outputSchema: z.string(), }, async ({ expression, timeVar, zVar, limit = 100 }) => { return zTransform(expression, timeVar, zVar, limit); } );
- index.js:477-483 (schema)Defines the input schema (expression, timeVar, zVar, optional limit) and output schema (string) for the z_transform tool.inputSchema: z.object({ expression: z.string().describe('Function of discrete time'), timeVar: z.string().describe('Discrete time variable'), zVar: z.string().describe('Z-transform variable'), limit: z.number().optional().describe('Upper limit for summation (default: 100)') }), outputSchema: z.string(),