/* PZT_coeff.h PoZeTools v 0.52, march 31, 2005. Copyright (c) 2002-2005 Pieter Suurmond Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. Any person wishing to distribute modifications to the Software is requested to send the modifications to the original developer so that they can be incorporated into the canonical version. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND ON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ typedef struct /* The 'complexCartesian' struct is extended with an integer member. */ { complexCartesian cartesian; /* Rectangular coordinates of the filter coeficient. */ int delay; /* Time displacement: delay=+1 belongs to time [-1]. */ } cartesian_coeff; /* Non-causal: delay=-1 belongs to time [+1]. */ typedef struct { int number; cartesian_coeff* coeff; } coeff_array; typedef struct { coeff_array a; coeff_array b; } COEFF; /*----------------------------------------------------------------------------*/ /* Calculate filter coefficients, given a set of poles and zeros and a gain parameter. Argument msg may be NULL. Allocates a COEFF structure that must be released after use by the caller! Returns zero on succes, non-zero on failure. */ int COEFF_calc(COEFF** ab, POZE* pz, FILE* msg); /*----------------------------------------------------------------------------*/ /* Releases an allocated COEFF structure and its' substructures. */ void COEFF_free(COEFF** ab); /*----------------------------------------------------------------------------*/ /* Writes the A and B coefficients in cartesion form to the open stream fp. Returns zero on success, non-zero on failure. Argument stamp may be NULL. */ int COEFF_write(const COEFF* ab, const char* stamp, FILE* fp); /*----------------------------------------------------------------------------*/ /* Writes the A and B coefficients in the form of a difference equation to stream fp. Returns zero on success, non-zero on failure. */ int COEFF_write_diff_eq(const COEFF* ab, FILE* fp); /*----------------------------------------------------------------------------*/ /* Reads a set of A and B filter coefficients. Lines look like "a(2) = 0.8j\n". Reads from memory if content=1, or from file if content=0. Writes messages (up to 500 bytes or so) to msg. */ int COEFF_read(COEFF** ab, short content, /* 0 if next arg=file. */ const char* source, /* filename or content */ char* msg);