kopia lustrzana https://github.com/Dsplib/libdspl-2.0
				
				
				
			added functions poly_z2a and poly_zp2ab
							rodzic
							
								
									43b72c39bf
								
							
						
					
					
						commit
						6fb251d989
					
				| 
						 | 
				
			
			@ -0,0 +1,71 @@
 | 
			
		|||
/*
 | 
			
		||||
* Copyright (c) 2015-2018 Sergey Bakhurin
 | 
			
		||||
* Digital Signal Processing Library [http://dsplib.org]
 | 
			
		||||
*
 | 
			
		||||
* This file is part of libdspl-2.0.
 | 
			
		||||
*  
 | 
			
		||||
* is free software: you can redistribute it and/or modify
 | 
			
		||||
* it under the terms of the GNU Lesser  General Public License as published by
 | 
			
		||||
* the Free Software Foundation, either version 3 of the License, or
 | 
			
		||||
* (at your option) any later version.
 | 
			
		||||
*
 | 
			
		||||
* DSPL is distributed in the hope that it will be useful,
 | 
			
		||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
 | 
			
		||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 | 
			
		||||
* GNU General Public License for more details.
 | 
			
		||||
*
 | 
			
		||||
* You should have received a copy of the GNU Lesser General Public License
 | 
			
		||||
* along with Foobar.  If not, see <http://www.gnu.org/licenses/>.
 | 
			
		||||
*/
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
#include <stdlib.h>
 | 
			
		||||
#include <string.h>
 | 
			
		||||
#include "dspl.h"
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************************
 | 
			
		||||
Zeros and poles to filter coefficients recalc
 | 
			
		||||
***************************************************************************************************/
 | 
			
		||||
int DSPL_API filter_zp2ab(complex_t *z, int nz, complex_t *p, int np, int ord, double* b, double* a)
 | 
			
		||||
{
 | 
			
		||||
    complex_t *acc = NULL;
 | 
			
		||||
    int res;
 | 
			
		||||
 | 
			
		||||
    if(!z || !p || !b || !a)
 | 
			
		||||
        return ERROR_PTR;
 | 
			
		||||
    if(nz < 0 || np < 0)
 | 
			
		||||
        return ERROR_SIZE;
 | 
			
		||||
    if(nz < ord || np < ord)
 | 
			
		||||
        return ERROR_POLY_ORD;
 | 
			
		||||
 | 
			
		||||
    acc = (complex_t*) malloc((ord+1) * sizeof(complex_t));
 | 
			
		||||
    res = poly_z2a_cmplx(z, nz, ord, acc);
 | 
			
		||||
    if(res != RES_OK)
 | 
			
		||||
        goto exit_label;    
 | 
			
		||||
    res = cmplx2re(acc, ord+1, b, NULL);
 | 
			
		||||
    if(res != RES_OK)
 | 
			
		||||
        goto exit_label;
 | 
			
		||||
 | 
			
		||||
    res = poly_z2a_cmplx(p, np, ord, acc);
 | 
			
		||||
    if(res != RES_OK)
 | 
			
		||||
        goto exit_label;    
 | 
			
		||||
    res = cmplx2re(acc, ord+1, a, NULL);
 | 
			
		||||
    if(res != RES_OK)
 | 
			
		||||
        goto exit_label;
 | 
			
		||||
 | 
			
		||||
exit_label:
 | 
			
		||||
    if(acc)
 | 
			
		||||
        free(acc);
 | 
			
		||||
    return res;
 | 
			
		||||
    
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			@ -25,6 +25,42 @@
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************************
 | 
			
		||||
Polynomial zeros to coefficients
 | 
			
		||||
***************************************************************************************************/
 | 
			
		||||
int DSPL_API poly_z2a_cmplx(complex_t* z, int nz, int ord, complex_t* a)
 | 
			
		||||
{
 | 
			
		||||
    int k, ind, res;
 | 
			
		||||
    complex_t x[2];
 | 
			
		||||
 | 
			
		||||
    if(!z || !a)
 | 
			
		||||
        return ERROR_PTR;
 | 
			
		||||
    if(nz < 1)
 | 
			
		||||
        return ERROR_SIZE;
 | 
			
		||||
    if(nz > ord || ord < 1)
 | 
			
		||||
        return ERROR_POLY_ORD;
 | 
			
		||||
 | 
			
		||||
    RE(x[1]) = 1.0;
 | 
			
		||||
    IM(x[1]) = 0.0;
 | 
			
		||||
 | 
			
		||||
    memset(a, 0, (ord+1) * sizeof(complex_t));
 | 
			
		||||
 | 
			
		||||
    RE(a[0]) = 1.0;
 | 
			
		||||
    ind = 1;
 | 
			
		||||
    for(k = 0; k < nz; k++)
 | 
			
		||||
    {
 | 
			
		||||
        RE(x[0]) = -RE(z[k]);
 | 
			
		||||
        IM(x[0]) = -IM(z[k]);
 | 
			
		||||
        res = conv_cmplx(a, ind, x, 2, a);
 | 
			
		||||
        if(res!=RES_OK)
 | 
			
		||||
            return res;
 | 
			
		||||
        ind++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return RES_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************************
 | 
			
		||||
| 
						 | 
				
			
			@ -88,50 +124,3 @@ int DSPL_API polyval_cmplx(complex_t* a, int ord, complex_t* x, int n, complex_t
 | 
			
		|||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/**************************************************************************************************
 | 
			
		||||
polynomial zeros to coeff reecalc 
 | 
			
		||||
***************************************************************************************************/
 | 
			
		||||
int poly_z2a(complex_t *z, int nz, int ord, complex_t *a)
 | 
			
		||||
{
 | 
			
		||||
    int k, ind, res;
 | 
			
		||||
    complex_t x[2];
 | 
			
		||||
 | 
			
		||||
    if(!z || !a)
 | 
			
		||||
	    return ERROR_PTR;	
 | 
			
		||||
	if(ord<0)
 | 
			
		||||
		return ERROR_POLY_ORD;	
 | 
			
		||||
	if(nz<1 || nz > ord)
 | 
			
		||||
		return ERROR_SIZE;
 | 
			
		||||
 | 
			
		||||
    memset(a, 0, (ord+1) * sizeof(complex_t));
 | 
			
		||||
    RE(a[0]) = 1.0;
 | 
			
		||||
    IM(a[0]) = 0.0;
 | 
			
		||||
 | 
			
		||||
    RE(x[1]) = 1.0;
 | 
			
		||||
    IM(x[1]) = 0.0;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
    ind = 1;
 | 
			
		||||
    for(k=0; k < nz; k++)
 | 
			
		||||
    {
 | 
			
		||||
        RE(x[0]) = -RE(z[k]);
 | 
			
		||||
        IM(x[0]) = -IM(z[k]);
 | 
			
		||||
        res = conv_cmplx(a, ind, x, 2, a);
 | 
			
		||||
        if(res!=RES_OK)
 | 
			
		||||
            return res;        
 | 
			
		||||
        ind++;        
 | 
			
		||||
    }
 | 
			
		||||
    return RES_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,6 +52,7 @@ p_dmod                      dmod                ;
 | 
			
		|||
p_farrow_lagrange           farrow_lagrange     ;
 | 
			
		||||
p_farrow_spline             farrow_spline       ;
 | 
			
		||||
p_filter_iir                filter_iir          ;
 | 
			
		||||
p_filter_zp2ab              filter_zp2ab        ; 
 | 
			
		||||
p_fft                       fft                 ;
 | 
			
		||||
p_fft_cmplx                 fft_cmplx           ;   
 | 
			
		||||
p_fft_create                fft_create          ; 
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +67,7 @@ p_goertzel_cmplx            goertzel_cmplx      ;
 | 
			
		|||
p_linspace                  linspace            ;
 | 
			
		||||
p_log_cmplx                 log_cmplx           ;
 | 
			
		||||
p_logspace                  logspace            ;
 | 
			
		||||
p_poly_z2a_cmplx            poly_z2a_cmplx      ;
 | 
			
		||||
p_polyval                   polyval             ;
 | 
			
		||||
p_polyval_cmplx             polyval_cmplx       ;
 | 
			
		||||
p_randn                     randn               ;
 | 
			
		||||
| 
						 | 
				
			
			@ -144,6 +146,7 @@ void* dspl_load()
 | 
			
		|||
    LOAD_FUNC(farrow_lagrange);
 | 
			
		||||
    LOAD_FUNC(farrow_spline);
 | 
			
		||||
    LOAD_FUNC(filter_iir);
 | 
			
		||||
    LOAD_FUNC(filter_zp2ab);
 | 
			
		||||
    LOAD_FUNC(fft);
 | 
			
		||||
    LOAD_FUNC(fft_cmplx);
 | 
			
		||||
    LOAD_FUNC(fft_create);
 | 
			
		||||
| 
						 | 
				
			
			@ -158,6 +161,7 @@ void* dspl_load()
 | 
			
		|||
    LOAD_FUNC(linspace);
 | 
			
		||||
    LOAD_FUNC(log_cmplx);
 | 
			
		||||
    LOAD_FUNC(logspace);
 | 
			
		||||
    LOAD_FUNC(poly_z2a_cmplx);
 | 
			
		||||
    LOAD_FUNC(polyval);
 | 
			
		||||
    LOAD_FUNC(polyval_cmplx);
 | 
			
		||||
    LOAD_FUNC(randn);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -207,7 +207,7 @@ DECLARE_FUNC(double,dmod,               double      COMMA double);
 | 
			
		|||
DECLARE_FUNC(int,   farrow_lagrange,    double*     COMMA int       COMMA double COMMA double COMMA double COMMA double** COMMA int*);
 | 
			
		||||
DECLARE_FUNC(int,   farrow_spline,      double*     COMMA int       COMMA double COMMA double COMMA double COMMA double** COMMA int*);
 | 
			
		||||
DECLARE_FUNC(int,   filter_iir,         double*     COMMA double*   COMMA int COMMA double* COMMA int COMMA double*);
 | 
			
		||||
 | 
			
		||||
DECLARE_FUNC(int,   filter_zp2ab,       complex_t*  COMMA int       COMMA complex_t* COMMA int COMMA int COMMA double* COMMA double*);
 | 
			
		||||
 | 
			
		||||
DECLARE_FUNC(int,   fft,                double*     COMMA int       COMMA fft_t* COMMA complex_t* );
 | 
			
		||||
DECLARE_FUNC(int,   fft_cmplx,          complex_t*  COMMA int       COMMA fft_t* COMMA complex_t* );
 | 
			
		||||
| 
						 | 
				
			
			@ -223,6 +223,7 @@ DECLARE_FUNC(int,   goertzel_cmplx,     complex_t*  COMMA int       COMMA int* C
 | 
			
		|||
DECLARE_FUNC(int,   linspace,           double      COMMA double    COMMA int COMMA int COMMA double*);
 | 
			
		||||
DECLARE_FUNC(int,   log_cmplx,          complex_t*  COMMA int       COMMA complex_t*);
 | 
			
		||||
DECLARE_FUNC(int,   logspace,           double      COMMA double    COMMA int COMMA int COMMA double*);
 | 
			
		||||
DECLARE_FUNC(int,   poly_z2a_cmplx,     complex_t*  COMMA int       COMMA int COMMA complex_t*);
 | 
			
		||||
DECLARE_FUNC(int,   polyval,            double*     COMMA int       COMMA double* COMMA int COMMA double*);
 | 
			
		||||
DECLARE_FUNC(int,   polyval_cmplx,      complex_t*  COMMA int       COMMA complex_t* COMMA int COMMA complex_t*);
 | 
			
		||||
DECLARE_FUNC(int,   randn,              double*     COMMA int       COMMA double COMMA double);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -52,6 +52,7 @@ p_dmod                      dmod                ;
 | 
			
		|||
p_farrow_lagrange           farrow_lagrange     ;
 | 
			
		||||
p_farrow_spline             farrow_spline       ;
 | 
			
		||||
p_filter_iir                filter_iir          ;
 | 
			
		||||
p_filter_zp2ab              filter_zp2ab        ; 
 | 
			
		||||
p_fft                       fft                 ;
 | 
			
		||||
p_fft_cmplx                 fft_cmplx           ;   
 | 
			
		||||
p_fft_create                fft_create          ; 
 | 
			
		||||
| 
						 | 
				
			
			@ -66,6 +67,7 @@ p_goertzel_cmplx            goertzel_cmplx      ;
 | 
			
		|||
p_linspace                  linspace            ;
 | 
			
		||||
p_log_cmplx                 log_cmplx           ;
 | 
			
		||||
p_logspace                  logspace            ;
 | 
			
		||||
p_poly_z2a_cmplx            poly_z2a_cmplx      ;
 | 
			
		||||
p_polyval                   polyval             ;
 | 
			
		||||
p_polyval_cmplx             polyval_cmplx       ;
 | 
			
		||||
p_randn                     randn               ;
 | 
			
		||||
| 
						 | 
				
			
			@ -144,6 +146,7 @@ void* dspl_load()
 | 
			
		|||
    LOAD_FUNC(farrow_lagrange);
 | 
			
		||||
    LOAD_FUNC(farrow_spline);
 | 
			
		||||
    LOAD_FUNC(filter_iir);
 | 
			
		||||
    LOAD_FUNC(filter_zp2ab);
 | 
			
		||||
    LOAD_FUNC(fft);
 | 
			
		||||
    LOAD_FUNC(fft_cmplx);
 | 
			
		||||
    LOAD_FUNC(fft_create);
 | 
			
		||||
| 
						 | 
				
			
			@ -158,6 +161,7 @@ void* dspl_load()
 | 
			
		|||
    LOAD_FUNC(linspace);
 | 
			
		||||
    LOAD_FUNC(log_cmplx);
 | 
			
		||||
    LOAD_FUNC(logspace);
 | 
			
		||||
    LOAD_FUNC(poly_z2a_cmplx);
 | 
			
		||||
    LOAD_FUNC(polyval);
 | 
			
		||||
    LOAD_FUNC(polyval_cmplx);
 | 
			
		||||
    LOAD_FUNC(randn);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -207,7 +207,7 @@ DECLARE_FUNC(double,dmod,               double      COMMA double);
 | 
			
		|||
DECLARE_FUNC(int,   farrow_lagrange,    double*     COMMA int       COMMA double COMMA double COMMA double COMMA double** COMMA int*);
 | 
			
		||||
DECLARE_FUNC(int,   farrow_spline,      double*     COMMA int       COMMA double COMMA double COMMA double COMMA double** COMMA int*);
 | 
			
		||||
DECLARE_FUNC(int,   filter_iir,         double*     COMMA double*   COMMA int COMMA double* COMMA int COMMA double*);
 | 
			
		||||
 | 
			
		||||
DECLARE_FUNC(int,   filter_zp2ab,       complex_t*  COMMA int       COMMA complex_t* COMMA int COMMA int COMMA double* COMMA double*);
 | 
			
		||||
 | 
			
		||||
DECLARE_FUNC(int,   fft,                double*     COMMA int       COMMA fft_t* COMMA complex_t* );
 | 
			
		||||
DECLARE_FUNC(int,   fft_cmplx,          complex_t*  COMMA int       COMMA fft_t* COMMA complex_t* );
 | 
			
		||||
| 
						 | 
				
			
			@ -223,6 +223,7 @@ DECLARE_FUNC(int,   goertzel_cmplx,     complex_t*  COMMA int       COMMA int* C
 | 
			
		|||
DECLARE_FUNC(int,   linspace,           double      COMMA double    COMMA int COMMA int COMMA double*);
 | 
			
		||||
DECLARE_FUNC(int,   log_cmplx,          complex_t*  COMMA int       COMMA complex_t*);
 | 
			
		||||
DECLARE_FUNC(int,   logspace,           double      COMMA double    COMMA int COMMA int COMMA double*);
 | 
			
		||||
DECLARE_FUNC(int,   poly_z2a_cmplx,     complex_t*  COMMA int       COMMA int COMMA complex_t*);
 | 
			
		||||
DECLARE_FUNC(int,   polyval,            double*     COMMA int       COMMA double* COMMA int COMMA double*);
 | 
			
		||||
DECLARE_FUNC(int,   polyval_cmplx,      complex_t*  COMMA int       COMMA complex_t* COMMA int COMMA complex_t*);
 | 
			
		||||
DECLARE_FUNC(int,   randn,              double*     COMMA int       COMMA double COMMA double);
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											Plik binarny nie jest wyświetlany.
										
									
								
							
		Ładowanie…
	
		Reference in New Issue