kopia lustrzana https://github.com/Dsplib/libdspl-2.0
fixed randgen bugs
rodzic
1e9430426d
commit
4e259f742f
|
@ -1,5 +1,6 @@
|
||||||
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
|
||||||
<CodeBlocks_workspace_layout_file>
|
<CodeBlocks_workspace_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveProject path="examples/examples.cbp" />
|
<ActiveProject path="lapack/lapack_double.cbp" />
|
||||||
|
<PreferredTarget name="Debug" />
|
||||||
</CodeBlocks_workspace_layout_file>
|
</CodeBlocks_workspace_layout_file>
|
||||||
|
|
|
@ -2,31 +2,6 @@
|
||||||
<CodeBlocks_layout_file>
|
<CodeBlocks_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveTarget name="Debug" />
|
<ActiveTarget name="Debug" />
|
||||||
<File name="..\include\dspl.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="10057" topLine="192" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="..\include\dspl.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="8601" topLine="219" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="src\fft.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="1917" topLine="33" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="src\randgen.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="5" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="4569" topLine="53" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="src\matrix.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
|
||||||
<Cursor>
|
|
||||||
<Cursor1 position="4148" topLine="155" />
|
|
||||||
</Cursor>
|
|
||||||
</File>
|
|
||||||
<File name="src\inout.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
|
<File name="src\inout.c" open="1" top="0" tabpos="7" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="1882" topLine="0" />
|
<Cursor1 position="1882" topLine="0" />
|
||||||
|
@ -37,9 +12,19 @@
|
||||||
<Cursor1 position="2457" topLine="53" />
|
<Cursor1 position="2457" topLine="53" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="src\filter_ft.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="src\fft.c" open="1" top="0" tabpos="3" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="651" topLine="129" />
|
<Cursor1 position="1917" topLine="33" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="..\include\dspl.c" open="1" top="0" tabpos="5" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="10057" topLine="192" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="src\matrix.c" open="1" top="0" tabpos="6" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="4148" topLine="155" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
<File name="src\cheby.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="src\cheby.c" open="1" top="0" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
@ -47,4 +32,24 @@
|
||||||
<Cursor1 position="2438" topLine="60" />
|
<Cursor1 position="2438" topLine="60" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
|
<File name="..\include\dspl.h" open="1" top="0" tabpos="4" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="48641" topLine="784" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="src\mt19937.c" open="1" top="0" tabpos="13" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="5094" topLine="30" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="src\filter_ft.c" open="1" top="0" tabpos="8" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="651" topLine="129" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
|
<File name="src\randgen.c" open="1" top="0" tabpos="9" split="0" active="1" splitpos="0" zoom_1="3" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="1170" topLine="26" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|
|
@ -74,6 +74,8 @@ void mt19937_init_genrand64(unsigned long long seed, random_t* prnd)
|
||||||
mt[0] = seed;
|
mt[0] = seed;
|
||||||
for (mti=1; mti<NN; mti++)
|
for (mti=1; mti<NN; mti++)
|
||||||
mt[mti] = (6364136223846793005ULL * (mt[mti-1] ^ (mt[mti-1] >> 62)) + mti);
|
mt[mti] = (6364136223846793005ULL * (mt[mti-1] ^ (mt[mti-1] >> 62)) + mti);
|
||||||
|
|
||||||
|
prnd->mt19937_mti = mti;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* initialize by an array with array-length */
|
/* initialize by an array with array-length */
|
||||||
|
@ -149,6 +151,7 @@ unsigned long long mt19937_genrand64_int64(random_t* prnd)
|
||||||
x ^= (x << 37) & 0xFFF7EEE000000000ULL;
|
x ^= (x << 37) & 0xFFF7EEE000000000ULL;
|
||||||
x ^= (x >> 43);
|
x ^= (x >> 43);
|
||||||
|
|
||||||
|
prnd->mt19937_mti = mti;
|
||||||
return x;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,24 +32,35 @@
|
||||||
/******************************************************************************
|
/******************************************************************************
|
||||||
random generator initialization
|
random generator initialization
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
int DSPL_API random_init(random_t* prnd, int type)
|
int DSPL_API random_init(random_t* prnd, int type, void* seed)
|
||||||
{
|
{
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
|
if(!prnd)
|
||||||
|
return RES_OK;
|
||||||
|
|
||||||
switch(type)
|
switch(type)
|
||||||
{
|
{
|
||||||
case RAND_TYPE_MRG32K3A:
|
case RAND_TYPE_MRG32K3A:
|
||||||
/* MRG32k3a init */
|
/* MRG32k3a init */
|
||||||
prnd->mrg32k3a_x[0] = prnd->mrg32k3a_x[1] = 1.0;
|
prnd->mrg32k3a_x[0] = prnd->mrg32k3a_x[1] = 1.0;
|
||||||
prnd->mrg32k3a_y[0] = prnd->mrg32k3a_y[1] = prnd->mrg32k3a_y[2] = 1.0;
|
prnd->mrg32k3a_y[0] = prnd->mrg32k3a_y[1] = prnd->mrg32k3a_y[2] = 1.0;
|
||||||
prnd->mrg32k3a_x[2] = rand();
|
if(seed)
|
||||||
|
prnd->mrg32k3a_x[2] = *((double*)seed);
|
||||||
|
else
|
||||||
|
prnd->mrg32k3a_x[2] = (double) rand() * rand();
|
||||||
break;
|
break;
|
||||||
case RAND_TYPE_MT19937:
|
case RAND_TYPE_MT19937:
|
||||||
|
if(seed)
|
||||||
|
mt19937_init_genrand64(*((unsigned long long*)seed), prnd);
|
||||||
|
else
|
||||||
mt19937_init_genrand64((unsigned long long)rand()*rand(), prnd);
|
mt19937_init_genrand64((unsigned long long)rand()*rand(), prnd);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return ERROR_RAND_TYPE;
|
return ERROR_RAND_TYPE;
|
||||||
}
|
}
|
||||||
prnd->type = type;
|
prnd->type = type;
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -118,7 +129,7 @@ int DSPL_API randu(double* x, int n, random_t* prnd)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(!x || !prnd)
|
if(!x)
|
||||||
return ERROR_PTR;
|
return ERROR_PTR;
|
||||||
if(n < 0)
|
if(n < 0)
|
||||||
return ERROR_SIZE;
|
return ERROR_SIZE;
|
||||||
|
@ -144,7 +155,7 @@ int DSPL_API randu(double* x, int n, random_t* prnd)
|
||||||
if(n<1)
|
if(n<1)
|
||||||
return ERROR_SIZE;
|
return ERROR_SIZE;
|
||||||
for(i = 0; i < n; i++)
|
for(i = 0; i < n; i++)
|
||||||
x[n] = (double)rand()/RAND_MAX;
|
x[i] = (double)rand()/RAND_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
return RES_OK;
|
return RES_OK;
|
||||||
|
|
|
@ -20,3 +20,18 @@
|
||||||
<string.h>
|
<string.h>
|
||||||
"dspl.h"
|
"dspl.h"
|
||||||
|
|
||||||
|
1572196728 source:f:\dsplib.org\libdspl-2.0\include\dspl.c
|
||||||
|
<windows.h>
|
||||||
|
<dlfcn.h>
|
||||||
|
<stdio.h>
|
||||||
|
"dspl.h"
|
||||||
|
|
||||||
|
1572200729 f:\dsplib.org\libdspl-2.0\include\dspl.h
|
||||||
|
<math.h>
|
||||||
|
|
||||||
|
1572200804 source:f:\dsplib.org\libdspl-2.0\examples\src\filter_iir_test.c
|
||||||
|
<stdio.h>
|
||||||
|
<stdlib.h>
|
||||||
|
<string.h>
|
||||||
|
"dspl.h"
|
||||||
|
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
</File>
|
</File>
|
||||||
<File name="src\filter_iir_test.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
<File name="src\filter_iir_test.c" open="1" top="1" tabpos="1" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
<Cursor>
|
<Cursor>
|
||||||
<Cursor1 position="936" topLine="8" />
|
<Cursor1 position="826" topLine="28" />
|
||||||
</Cursor>
|
</Cursor>
|
||||||
</File>
|
</File>
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|
|
@ -4,7 +4,11 @@
|
||||||
#include "dspl.h"
|
#include "dspl.h"
|
||||||
|
|
||||||
#define ORD 6
|
#define ORD 6
|
||||||
#define N 1000
|
#define N 2000
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
{
|
{
|
||||||
void* handle; /* DSPL handle */
|
void* handle; /* DSPL handle */
|
||||||
|
@ -15,30 +19,38 @@ int main(int argc, char* argv[])
|
||||||
int k;
|
int k;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
handle = dspl_load(); /* Load DSPL function */
|
/* Load DSPL function */
|
||||||
|
handle = dspl_load();
|
||||||
|
|
||||||
random_init(&rnd, RAND_TYPE_MRG32K3A); /* random generator init */
|
/* random generator init */
|
||||||
linspace(0, N, N, DSPL_PERIODIC, t); /* fill t vector */
|
random_init(&rnd, RAND_TYPE_MT19937, NULL);
|
||||||
randn(n, N, 0, 1.0, &rnd); /* generate noise */
|
|
||||||
|
/* fill time vector */
|
||||||
|
linspace(0, N, N, DSPL_PERIODIC, t);
|
||||||
|
|
||||||
|
/* generate noise */
|
||||||
|
randn(n, N, 0, 1.0, &rnd);
|
||||||
|
|
||||||
/* input signal s = sin(2*pi*t) + n(t) */
|
/* input signal s = sin(2*pi*t) + n(t) */
|
||||||
for(k = 0; k < N; k++)
|
for(k = 0; k < N; k++)
|
||||||
s[k] = sin(M_2PI*0.02*t[k]) + n[k];
|
s[k] = sin(M_2PI*0.02*t[k]) + n[k];
|
||||||
|
|
||||||
/* iir filter calculation */
|
/* IIR filter coefficients calculation */
|
||||||
iir(1.0, 70.0, ORD, 0.06, 0.0, DSPL_FILTER_ELLIP | DSPL_FILTER_LPF, b, a);
|
iir(1.0, 70.0, ORD, 0.06, 0.0, DSPL_FILTER_ELLIP | DSPL_FILTER_LPF, b, a);
|
||||||
|
|
||||||
// input signal filtration
|
/* input signal filtration */
|
||||||
filter_iir(b, a, ORD, s, N, sf);
|
filter_iir(b, a, ORD, s, N, sf);
|
||||||
|
|
||||||
// save input signal and filter output to the txt-files
|
/* save input signal and filter output to the txt-files */
|
||||||
writetxt(t,s, N, "dat/s.txt");
|
writetxt(t,s, N, "dat/s.txt");
|
||||||
writetxt(t,sf,N, "dat/sf.txt");
|
writetxt(t,sf,N, "dat/sf.txt");
|
||||||
|
|
||||||
|
/* run GNUPLOT script */
|
||||||
err = gnuplot_script(argc, argv, "gnuplot/filter_iir.plt");
|
err = gnuplot_script(argc, argv, "gnuplot/filter_iir.plt");
|
||||||
dspl_free(handle); // free dspl handle
|
|
||||||
|
|
||||||
// run GNUPLOT script
|
/* free DSPL handle */
|
||||||
|
dspl_free(handle);
|
||||||
|
|
||||||
|
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
|
|
|
@ -799,7 +799,8 @@ DECLARE_FUNC(int, randn, double*
|
||||||
COMMA random_t* prnd);
|
COMMA random_t* prnd);
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
DECLARE_FUNC(int, random_init, random_t* prnd
|
DECLARE_FUNC(int, random_init, random_t* prnd
|
||||||
COMMA int type);
|
COMMA int type
|
||||||
|
COMMA void* seed);
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
DECLARE_FUNC(int, randu, double*
|
DECLARE_FUNC(int, randu, double*
|
||||||
COMMA int
|
COMMA int
|
||||||
|
|
|
@ -2,4 +2,9 @@
|
||||||
<CodeBlocks_layout_file>
|
<CodeBlocks_layout_file>
|
||||||
<FileVersion major="1" minor="0" />
|
<FileVersion major="1" minor="0" />
|
||||||
<ActiveTarget name="Debug" />
|
<ActiveTarget name="Debug" />
|
||||||
|
<File name="src\dgbbrd.f" open="0" top="0" tabpos="0" split="0" active="1" splitpos="0" zoom_1="0" zoom_2="0">
|
||||||
|
<Cursor>
|
||||||
|
<Cursor1 position="16592" topLine="517" />
|
||||||
|
</Cursor>
|
||||||
|
</File>
|
||||||
</CodeBlocks_layout_file>
|
</CodeBlocks_layout_file>
|
||||||
|
|
Ładowanie…
Reference in New Issue