kopia lustrzana https://github.com/Dsplib/libdspl-2.0
added function for 3d plot data saving
rodzic
56fa160cb7
commit
c1e475064c
|
|
@ -26,10 +26,12 @@
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
|
||||
/******************************************************************************
|
||||
Complex frequency response of an analog filter H(s)
|
||||
***************************************************************************************************/
|
||||
int DSPL_API freqs(double* b, double* a, int ord, double* w, int n, complex_t *h)
|
||||
*******************************************************************************/
|
||||
int DSPL_API freqs(double* b, double* a, int ord,
|
||||
double* w, int n, complex_t *h)
|
||||
{
|
||||
complex_t jw;
|
||||
complex_t *bc = NULL;
|
||||
|
|
@ -77,7 +79,6 @@ int DSPL_API freqs(double* b, double* a, int ord, double* w, int n, complex_t *h
|
|||
mag = 1.0 / mag;
|
||||
RE(h[k]) = CMCONJRE(num, den) * mag;
|
||||
IM(h[k]) = CMCONJIM(num, den) * mag;
|
||||
|
||||
}
|
||||
res = RES_OK;
|
||||
exit_label:
|
||||
|
|
@ -92,10 +93,78 @@ exit_label:
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
|
||||
/******************************************************************************
|
||||
* Complex frequency response of an analog filter H(s), s is complex variable
|
||||
******************************************************************************/
|
||||
int DSPL_API freqs_cmplx(double* b, double* a, int ord,
|
||||
complex_t* s, int n, complex_t *h)
|
||||
{
|
||||
complex_t *bc = NULL;
|
||||
complex_t *ac = NULL;
|
||||
complex_t num, den;
|
||||
double mag;
|
||||
int k;
|
||||
int res;
|
||||
|
||||
if(!b || !a || !s || !h)
|
||||
return ERROR_PTR;
|
||||
if(ord<0)
|
||||
return ERROR_FILTER_ORD;
|
||||
if(n<1)
|
||||
return ERROR_SIZE;
|
||||
|
||||
|
||||
bc = (complex_t*) malloc((ord+1) * sizeof(complex_t));
|
||||
res = re2cmplx(b, ord+1, bc);
|
||||
|
||||
if( res!=RES_OK )
|
||||
goto exit_label;
|
||||
|
||||
ac = (complex_t*) malloc((ord+1) * sizeof(complex_t));
|
||||
res = re2cmplx(a, ord+1, ac);
|
||||
if( res!=RES_OK )
|
||||
goto exit_label;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
{
|
||||
res = polyval_cmplx(bc, ord, s+k, 1, &num);
|
||||
if(res != RES_OK)
|
||||
goto exit_label;
|
||||
res = polyval_cmplx(ac, ord, s+k, 1, &den);
|
||||
if(res != RES_OK)
|
||||
goto exit_label;
|
||||
mag = ABSSQR(den);
|
||||
if(mag == 0.0)
|
||||
{
|
||||
res = ERROR_DIV_ZERO;
|
||||
goto exit_label;
|
||||
}
|
||||
mag = 1.0 / mag;
|
||||
RE(h[k]) = CMCONJRE(num, den) * mag;
|
||||
IM(h[k]) = CMCONJIM(num, den) * mag;
|
||||
|
||||
}
|
||||
res = RES_OK;
|
||||
exit_label:
|
||||
if(bc)
|
||||
free(bc);
|
||||
if(ac)
|
||||
free(ac);
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
impulse response of an analog filter H(s)
|
||||
***************************************************************************************************/
|
||||
int DSPL_API freqs2time(double* b, double* a, int ord, double fs, int n, fft_t* pfft, double *t, double *h)
|
||||
*******************************************************************************/
|
||||
int DSPL_API freqs2time(double* b, double* a, int ord, double fs,
|
||||
int n, fft_t* pfft, double *t, double *h)
|
||||
{
|
||||
double *w = NULL;
|
||||
complex_t *hs = NULL;
|
||||
|
|
@ -149,17 +218,17 @@ exit_label:
|
|||
if(ht)
|
||||
free(ht);
|
||||
return err;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
/******************************************************************************
|
||||
Magnitude, phase response and group delay of an analog filter H(s)
|
||||
***************************************************************************************************/
|
||||
int DSPL_API freqs_resp(double* b, double* a, int ord, double* w, int n, int flag,
|
||||
*******************************************************************************/
|
||||
int DSPL_API freqs_resp(double* b, double* a, int ord,
|
||||
double* w, int n, int flag,
|
||||
double *h, double* phi, double* tau)
|
||||
{
|
||||
int res, k;
|
||||
|
|
@ -210,7 +279,6 @@ int DSPL_API freqs_resp(double* b, double* a, int ord, double* w, int n, int fla
|
|||
if(res != RES_OK)
|
||||
goto exit_label;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -229,15 +297,16 @@ int DSPL_API freqs_resp(double* b, double* a, int ord, double* w, int n, int fla
|
|||
w0[k] = w[k] - (w[k] - w[k-1])*0.02;
|
||||
w1[k] = w[k] + (w[k] - w[k-1])*0.02;
|
||||
}
|
||||
res = freqs_resp(b, a, ord, w0, n, DSPL_FLAG_UNWRAP, NULL, phi0, NULL);
|
||||
res = freqs_resp(b, a, ord, w0, n, DSPL_FLAG_UNWRAP,
|
||||
NULL, phi0, NULL);
|
||||
if(res != RES_OK)
|
||||
goto exit_label;
|
||||
res = freqs_resp(b, a, ord, w1, n, DSPL_FLAG_UNWRAP, NULL, phi1, NULL);
|
||||
res = freqs_resp(b, a, ord, w1, n, DSPL_FLAG_UNWRAP,
|
||||
NULL, phi1, NULL);
|
||||
if(res != RES_OK)
|
||||
goto exit_label;
|
||||
for(k = 0; k < n; k++)
|
||||
tau[k] = (phi0[k] - phi1[k])/(w1[k] - w0[k]);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -260,12 +329,12 @@ exit_label:
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
/*******************************************************************************
|
||||
Complex frequency response of a digital filter H(z)
|
||||
**************************************************************************************************/
|
||||
int DSPL_API freqz(double* b, double* a, int ord, double* w, int n, complex_t *h)
|
||||
*******************************************************************************/
|
||||
int DSPL_API freqz(double* b, double* a, int ord, double* w,
|
||||
int n, complex_t *h)
|
||||
{
|
||||
|
||||
complex_t jw;
|
||||
complex_t *bc = NULL;
|
||||
complex_t *ac = NULL;
|
||||
|
|
@ -343,9 +412,9 @@ exit_label:
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
/*******************************************************************************
|
||||
Unwrap function
|
||||
**************************************************************************************************/
|
||||
*******************************************************************************/
|
||||
int DSPL_API unwrap(double* phi, int n, double lev, double mar)
|
||||
{
|
||||
double a[2] = {0.0, 0.0};
|
||||
|
|
|
|||
|
|
@ -25,13 +25,13 @@
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
/*******************************************************************************
|
||||
Print DSPL info
|
||||
**************************************************************************************************/
|
||||
*******************************************************************************/
|
||||
void DSPL_API dspl_info()
|
||||
{
|
||||
printf("\n\n D S P L - 2.0\n");
|
||||
printf(" version 2.18.5.3\n");
|
||||
printf(" version 2.18.6.14\n");
|
||||
printf("\n Сopyright (C) 2015-2018\n");
|
||||
printf(" Sergey Bakhurin www.dsplib.org\n\n");
|
||||
}
|
||||
|
|
@ -41,9 +41,9 @@ void DSPL_API dspl_info()
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
/******************************************************************************
|
||||
Write a real array to the binary file "fn"
|
||||
***************************************************************************************************/
|
||||
*******************************************************************************/
|
||||
int DSPL_API writebin(void* x, int n, int dtype, char* fn)
|
||||
{
|
||||
int k, res;
|
||||
|
|
@ -91,7 +91,8 @@ int DSPL_API writebin(void* x, int n, int dtype, char* fn)
|
|||
}
|
||||
break;
|
||||
case DAT_COMPLEX:
|
||||
if(fwrite((complex_t*)x, sizeof(complex_t), n, pFile) != n)
|
||||
if(fwrite((complex_t*)x,
|
||||
sizeof(complex_t), n, pFile) != n)
|
||||
{
|
||||
res = ERROR_FWRITE_SIZE;
|
||||
goto exit_label;
|
||||
|
|
@ -113,9 +114,9 @@ exit_label:
|
|||
|
||||
|
||||
|
||||
/**************************************************************************************************
|
||||
/******************************************************************************
|
||||
Write a real arrays to the text file "fn"
|
||||
***************************************************************************************************/
|
||||
*******************************************************************************/
|
||||
int DSPL_API writetxt(double* x, double *y, int n, char* fn)
|
||||
{
|
||||
int k;
|
||||
|
|
@ -144,3 +145,71 @@ int DSPL_API writetxt(double* x, double *y, int n, char* fn)
|
|||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Write a 3d plot data to file "fn" (pgfplots3d accepteble)
|
||||
******************************************************************************/
|
||||
int DSPL_API writetxt_3d(double* x, int nx, double *y, int ny,
|
||||
double* z, char* fn)
|
||||
{
|
||||
int k, n;
|
||||
FILE* pFile = NULL;
|
||||
|
||||
if(!x || !y || !z)
|
||||
return ERROR_PTR;
|
||||
if(nx < 1 || ny < 1)
|
||||
return ERROR_SIZE;
|
||||
if(!fn)
|
||||
return ERROR_FNAME;
|
||||
|
||||
pFile = fopen(fn, "w+");
|
||||
if(pFile == NULL)
|
||||
return ERROR_FOPEN;
|
||||
|
||||
for(k = 0; k < ny; k++)
|
||||
{
|
||||
for(n = 0; n < nx; n++)
|
||||
fprintf(pFile, "%+.12E\t%+.12E\t%+.12E\n",
|
||||
x[n], y[k], z[n+k*nx]);
|
||||
fprintf(pFile, "\n");
|
||||
|
||||
}
|
||||
fclose(pFile);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/******************************************************************************
|
||||
* Write a 3d line data to file "fn" (pgfplots3d accepteble)
|
||||
******************************************************************************/
|
||||
int DSPL_API writetxt_3dline(double* x, double *y, double* z, int n, char* fn)
|
||||
{
|
||||
int k;
|
||||
FILE* pFile = NULL;
|
||||
|
||||
if(!x || !y || !z)
|
||||
return ERROR_PTR;
|
||||
if(n < 1)
|
||||
return ERROR_SIZE;
|
||||
if(!fn)
|
||||
return ERROR_FNAME;
|
||||
|
||||
pFile = fopen(fn, "w+");
|
||||
if(pFile == NULL)
|
||||
return ERROR_FOPEN;
|
||||
|
||||
for(k = 0; k < n; k++)
|
||||
fprintf(pFile, "%+.12E\t%+.12E\t%+.12E\n", x[k], y[k], z[k]);
|
||||
fprintf(pFile, "\n");
|
||||
fclose(pFile);
|
||||
return RES_OK;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ p_flipip_cmplx flipip_cmplx ;
|
|||
p_fourier_series_dec fourier_series_dec ;
|
||||
p_fourier_series_rec fourier_series_rec ;
|
||||
p_freqs freqs ;
|
||||
p_freqs_cmplx freqs_cmplx ;
|
||||
p_freqs_resp freqs_resp ;
|
||||
p_freqs2time freqs2time ;
|
||||
p_freqz freqz ;
|
||||
|
|
@ -107,6 +108,8 @@ p_trapint_cmplx trapint_cmplx ;
|
|||
p_unwrap unwrap ;
|
||||
p_writebin writebin ;
|
||||
p_writetxt writetxt ;
|
||||
p_writetxt_3d writetxt_3d ;
|
||||
p_writetxt_3dline writetxt_3dline ;
|
||||
|
||||
#endif //BUILD_LIB
|
||||
|
||||
|
|
@ -209,6 +212,7 @@ void* dspl_load()
|
|||
LOAD_FUNC(fourier_series_rec);
|
||||
LOAD_FUNC(freqz);
|
||||
LOAD_FUNC(freqs);
|
||||
LOAD_FUNC(freqs_cmplx);
|
||||
LOAD_FUNC(freqs_resp);
|
||||
LOAD_FUNC(freqs2time);
|
||||
LOAD_FUNC(goertzel);
|
||||
|
|
@ -230,6 +234,8 @@ void* dspl_load()
|
|||
LOAD_FUNC(unwrap);
|
||||
LOAD_FUNC(writebin);
|
||||
LOAD_FUNC(writetxt);
|
||||
LOAD_FUNC(writetxt_3d);
|
||||
LOAD_FUNC(writetxt_3dline);
|
||||
|
||||
|
||||
#ifdef WIN_OS
|
||||
|
|
|
|||
|
|
@ -460,6 +460,13 @@ DECLARE_FUNC(int, freqs, double*
|
|||
COMMA int
|
||||
COMMA complex_t*);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, freqs_cmplx, double* b
|
||||
COMMA double* a
|
||||
COMMA int ord
|
||||
COMMA complex_t* s
|
||||
COMMA int n
|
||||
COMMA complex_t* h);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, freqs_resp, double*
|
||||
COMMA double*
|
||||
COMMA int
|
||||
|
|
@ -584,7 +591,19 @@ DECLARE_FUNC(int, writetxt, double*
|
|||
COMMA int
|
||||
COMMA char*);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
DECLARE_FUNC(int, writetxt_3d, double* x
|
||||
COMMA int nx
|
||||
COMMA double* y
|
||||
COMMA int ny
|
||||
COMMA double* z
|
||||
COMMA char* fn);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, writetxt_3dline, double* x
|
||||
COMMA double* y
|
||||
COMMA double* z
|
||||
COMMA int n
|
||||
COMMA char* fn);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
|
|
@ -85,6 +85,7 @@ p_flipip_cmplx flipip_cmplx ;
|
|||
p_fourier_series_dec fourier_series_dec ;
|
||||
p_fourier_series_rec fourier_series_rec ;
|
||||
p_freqs freqs ;
|
||||
p_freqs_cmplx freqs_cmplx ;
|
||||
p_freqs_resp freqs_resp ;
|
||||
p_freqs2time freqs2time ;
|
||||
p_freqz freqz ;
|
||||
|
|
@ -107,6 +108,8 @@ p_trapint_cmplx trapint_cmplx ;
|
|||
p_unwrap unwrap ;
|
||||
p_writebin writebin ;
|
||||
p_writetxt writetxt ;
|
||||
p_writetxt_3d writetxt_3d ;
|
||||
p_writetxt_3dline writetxt_3dline ;
|
||||
|
||||
#endif //BUILD_LIB
|
||||
|
||||
|
|
@ -209,6 +212,7 @@ void* dspl_load()
|
|||
LOAD_FUNC(fourier_series_rec);
|
||||
LOAD_FUNC(freqz);
|
||||
LOAD_FUNC(freqs);
|
||||
LOAD_FUNC(freqs_cmplx);
|
||||
LOAD_FUNC(freqs_resp);
|
||||
LOAD_FUNC(freqs2time);
|
||||
LOAD_FUNC(goertzel);
|
||||
|
|
@ -230,6 +234,8 @@ void* dspl_load()
|
|||
LOAD_FUNC(unwrap);
|
||||
LOAD_FUNC(writebin);
|
||||
LOAD_FUNC(writetxt);
|
||||
LOAD_FUNC(writetxt_3d);
|
||||
LOAD_FUNC(writetxt_3dline);
|
||||
|
||||
|
||||
#ifdef WIN_OS
|
||||
|
|
|
|||
|
|
@ -460,6 +460,13 @@ DECLARE_FUNC(int, freqs, double*
|
|||
COMMA int
|
||||
COMMA complex_t*);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, freqs_cmplx, double* b
|
||||
COMMA double* a
|
||||
COMMA int ord
|
||||
COMMA complex_t* s
|
||||
COMMA int n
|
||||
COMMA complex_t* h);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, freqs_resp, double*
|
||||
COMMA double*
|
||||
COMMA int
|
||||
|
|
@ -584,7 +591,19 @@ DECLARE_FUNC(int, writetxt, double*
|
|||
COMMA int
|
||||
COMMA char*);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
DECLARE_FUNC(int, writetxt_3d, double* x
|
||||
COMMA int nx
|
||||
COMMA double* y
|
||||
COMMA int ny
|
||||
COMMA double* z
|
||||
COMMA char* fn);
|
||||
//------------------------------------------------------------------------------
|
||||
DECLARE_FUNC(int, writetxt_3dline, double* x
|
||||
COMMA double* y
|
||||
COMMA double* z
|
||||
COMMA int n
|
||||
COMMA char* fn);
|
||||
//------------------------------------------------------------------------------
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
|||
Ładowanie…
Reference in New Issue