added ratcomops and low2low transformation

pull/2/head
Dsplib 2018-07-03 20:26:36 +03:00
rodzic c1e475064c
commit b203899a2d
5 zmienionych plików z 202 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,158 @@
/*
* 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 <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "dspl.h"
/******************************************************************************
low 2 low transformation
*******************************************************************************/
int DSPL_API low2low(double* b, double* a, int ord, double w0, double w1,
double* beta, double* alpha)
{
double num[2] = {0.0, 1.0};
double den[2] = {0.0, 0.0};
if(!b || !a || !beta || !alpha)
return ERROR_PTR;
if(ord < 1)
return ERROR_FILTER_ORD;
if(w0 <= 0.0 || w1 <= 0.0)
return ERROR_FILTER_FT;
den[0] = w0 / w1;
return ratcompos(b, a, ord, num, den, 1, beta, alpha);
}
/******************************************************************************
Rational composition
*******************************************************************************/
int DSPL_API ratcompos( double* b, double* a, int n,
double* c, double* d, int p,
double* beta, double* alpha)
{
int k2, i, k, pn, pd, ln, ld, k2s, nk2s;
double *num = NULL, *den = NULL, *ndn = NULL, *ndd = NULL;
int res;
if (!a || !b || !c || !d || !beta || !alpha)
{
res = ERROR_PTR;
goto exit_label;
}
if(n < 1 || p < 1)
{
res = ERROR_SIZE;
goto exit_label;
}
k2 = (n*p)+1;
k2s = k2*sizeof(double); /* alpha and beta size */
nk2s = (n+1)*k2*sizeof(double); /* num, den, ndn and ndd size */
num = (double*)malloc(nk2s);
den = (double*)malloc(nk2s);
ndn = (double*)malloc(nk2s);
ndd = (double*)malloc(nk2s);
memset(num, 0, nk2s);
memset(den, 0, nk2s);
memset(ndn, 0, nk2s);
memset(ndd, 0, nk2s);
num[0] = den[0] = 1.0;
pn = 0;
ln = 1;
for(i = 1; i < n+1; i++)
{
res = conv(num+pn, ln, c, p+1, num+pn+k2);
if(res!=RES_OK)
goto exit_label;
res = conv(den+pn, ln, d, p+1, den+pn+k2);
if(res!=RES_OK)
goto exit_label;
pn += k2;
ln += p;
}
pn = 0;
pd = n*k2;
ln = 1;
ld = k2;
for (i = 0; i < n+1; i++)
{
res = conv(num + pn, ln, den + pd, ld, ndn + i*k2);
if(res!=RES_OK)
goto exit_label;
ln += p;
ld -= p;
pn += k2;
pd -= k2;
}
for (i = 0; i < n+1; i++)
{
for (k = 0; k < k2; k++)
{
ndd[i*k2 + k] = ndn[i*k2 + k] * a[i];
ndn[i*k2 + k] *= b[i];
}
}
memset(alpha, 0, k2s);
memset(beta, 0, k2s);
for (k = 0; k < k2; k++)
{
for (i = 0; i < n+1; i++)
{
beta[k] += ndn[i*k2 + k];
alpha[k] += ndd[i*k2 + k];
}
}
res = RES_OK;
exit_label:
if(num)
free(num);
if(den)
free(den);
if(ndn)
free(ndn);
if(ndd)
free(ndd);
return res;
}

Wyświetl plik

@ -94,11 +94,13 @@ p_goertzel_cmplx goertzel_cmplx ;
p_linspace linspace ;
p_log_cmplx log_cmplx ;
p_logspace logspace ;
p_low2low low2low ;
p_poly_z2a_cmplx poly_z2a_cmplx ;
p_polyval polyval ;
p_polyval_cmplx polyval_cmplx ;
p_randn randn ;
p_randu randu ;
p_ratcompos ratcompos ;
p_re2cmplx re2cmplx ;
p_signal_pimp signal_pimp ;
p_sin_cmplx sin_cmplx ;
@ -220,11 +222,13 @@ void* dspl_load()
LOAD_FUNC(linspace);
LOAD_FUNC(log_cmplx);
LOAD_FUNC(logspace);
LOAD_FUNC(low2low);
LOAD_FUNC(poly_z2a_cmplx);
LOAD_FUNC(polyval);
LOAD_FUNC(polyval_cmplx);
LOAD_FUNC(randn);
LOAD_FUNC(randu);
LOAD_FUNC(ratcompos);
LOAD_FUNC(re2cmplx);
LOAD_FUNC(signal_pimp);
LOAD_FUNC(sin_cmplx);

Wyświetl plik

@ -84,6 +84,7 @@ typedef struct
#define ERROR_FFT_CREATE 0x06060318
#define ERROR_FFT_SIZE 0x06062021
#define ERROR_FILTER_A0 0x06100100
#define ERROR_FILTER_FT 0x06100620
#define ERROR_FILTER_ORD 0x06101518
#define ERROR_FILTER_RP 0x06101816
#define ERROR_FILTER_RS 0x06101819
@ -521,6 +522,14 @@ DECLARE_FUNC(int, logspace, double
COMMA int
COMMA double*);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, low2low, double* b
COMMA double* a
COMMA int ord
COMMA double w0
COMMA double w1
COMMA double* beta
COMMA double* alpha);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, poly_z2a_cmplx, complex_t*
COMMA int
COMMA int
@ -546,6 +555,15 @@ DECLARE_FUNC(int, randn, double*
DECLARE_FUNC(int, randu, double*
COMMA int);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, ratcompos, double* b
COMMA double* a
COMMA int n
COMMA double* c
COMMA double* d
COMMA int p
COMMA double* beta
COMMA double* alpha);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, re2cmplx, double*
COMMA int
COMMA complex_t*);

Wyświetl plik

@ -94,11 +94,13 @@ p_goertzel_cmplx goertzel_cmplx ;
p_linspace linspace ;
p_log_cmplx log_cmplx ;
p_logspace logspace ;
p_low2low low2low ;
p_poly_z2a_cmplx poly_z2a_cmplx ;
p_polyval polyval ;
p_polyval_cmplx polyval_cmplx ;
p_randn randn ;
p_randu randu ;
p_ratcompos ratcompos ;
p_re2cmplx re2cmplx ;
p_signal_pimp signal_pimp ;
p_sin_cmplx sin_cmplx ;
@ -220,11 +222,13 @@ void* dspl_load()
LOAD_FUNC(linspace);
LOAD_FUNC(log_cmplx);
LOAD_FUNC(logspace);
LOAD_FUNC(low2low);
LOAD_FUNC(poly_z2a_cmplx);
LOAD_FUNC(polyval);
LOAD_FUNC(polyval_cmplx);
LOAD_FUNC(randn);
LOAD_FUNC(randu);
LOAD_FUNC(ratcompos);
LOAD_FUNC(re2cmplx);
LOAD_FUNC(signal_pimp);
LOAD_FUNC(sin_cmplx);

Wyświetl plik

@ -84,6 +84,7 @@ typedef struct
#define ERROR_FFT_CREATE 0x06060318
#define ERROR_FFT_SIZE 0x06062021
#define ERROR_FILTER_A0 0x06100100
#define ERROR_FILTER_FT 0x06100620
#define ERROR_FILTER_ORD 0x06101518
#define ERROR_FILTER_RP 0x06101816
#define ERROR_FILTER_RS 0x06101819
@ -521,6 +522,14 @@ DECLARE_FUNC(int, logspace, double
COMMA int
COMMA double*);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, low2low, double* b
COMMA double* a
COMMA int ord
COMMA double w0
COMMA double w1
COMMA double* beta
COMMA double* alpha);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, poly_z2a_cmplx, complex_t*
COMMA int
COMMA int
@ -546,6 +555,15 @@ DECLARE_FUNC(int, randn, double*
DECLARE_FUNC(int, randu, double*
COMMA int);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, ratcompos, double* b
COMMA double* a
COMMA int n
COMMA double* c
COMMA double* d
COMMA int p
COMMA double* beta
COMMA double* alpha);
//------------------------------------------------------------------------------
DECLARE_FUNC(int, re2cmplx, double*
COMMA int
COMMA complex_t*);