diff options
Diffstat (limited to 'src/c')
-rw-r--r-- | src/c/elementaryFunctions/includes/linspace.h | 3 | ||||
-rw-r--r-- | src/c/elementaryFunctions/interfaces/int_linspace.h | 4 | ||||
-rw-r--r-- | src/c/elementaryFunctions/linspace/slinspacea.c | 49 | ||||
-rw-r--r-- | src/c/elementaryFunctions/linspace/slinspaces.c | 33 | ||||
-rw-r--r-- | src/c/interpolation/includes/interp1.h | 2 | ||||
-rw-r--r-- | src/c/interpolation/interfaces/int_interp1.h | 8 | ||||
-rw-r--r-- | src/c/interpolation/interp1/sinterp13a.c | 75 | ||||
-rw-r--r-- | src/c/signalProcessing/includes/dct.h | 2 | ||||
-rw-r--r-- | src/c/signalProcessing/includes/idct.h | 2 | ||||
-rw-r--r-- | src/c/signalProcessing/interfaces/int_dct.h | 4 | ||||
-rw-r--r-- | src/c/signalProcessing/interfaces/int_idct.h | 2 | ||||
-rw-r--r-- | src/c/signalProcessing/transforms/dct/sdcta.c | 160 | ||||
-rw-r--r-- | src/c/signalProcessing/transforms/idct/sidcta.c | 83 |
13 files changed, 425 insertions, 2 deletions
diff --git a/src/c/elementaryFunctions/includes/linspace.h b/src/c/elementaryFunctions/includes/linspace.h index 92fe10e..62d4501 100644 --- a/src/c/elementaryFunctions/includes/linspace.h +++ b/src/c/elementaryFunctions/includes/linspace.h @@ -21,8 +21,11 @@ extern "C" { EXTERN_ELEMFUNCT void dlinspaces(double low_limit,double up_limit,double range_num, double* out); +EXTERN_ELEMFUNCT void slinspaces(float low_limit,float up_limit,float range_num, float* out); + EXTERN_ELEMFUNCT void dlinspacea(double *low_limit,int row,double *up_limit,double range_num, double* out); +EXTERN_ELEMFUNCT void slinspacea(float *low_limit,int row,float *up_limit,float range_num, float* out); diff --git a/src/c/elementaryFunctions/interfaces/int_linspace.h b/src/c/elementaryFunctions/interfaces/int_linspace.h index f8af947..15ea269 100644 --- a/src/c/elementaryFunctions/interfaces/int_linspace.h +++ b/src/c/elementaryFunctions/interfaces/int_linspace.h @@ -15,6 +15,10 @@ #define d0d0d0linspaced2(in1,in2,in3,out) dlinspaces(in1,in2,in3,out) +#define s0s0s0linspaces2(in1,in2,in3,out) slinspaces(in1,in2,in3,out) + #define d2d2d0linspaced2(in1,size1,in2,size2,in3,out) dlinspacea(in1,size1[0],in2,in3,out) +#define s2s2s0linspaces2(in1,size1,in2,size2,in3,out) slinspacea(in1,size1[0],in2,in3,out) + #endif diff --git a/src/c/elementaryFunctions/linspace/slinspacea.c b/src/c/elementaryFunctions/linspace/slinspacea.c new file mode 100644 index 0000000..38af394 --- /dev/null +++ b/src/c/elementaryFunctions/linspace/slinspacea.c @@ -0,0 +1,49 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ukasha Noor + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ +#include <stdlib.h> +#include "linspace.h" + +void slinspacea(float *low_limit,int _row,float *up_limit,float range_num,float *out) +{ + int i,j,k; + float temp; + float *step_iterate; /* for each row the spacing between two values is different.*/ + step_iterate = (float*) malloc((float)_row*sizeof(float)); + for(i=0;i<_row;i++) + { + + step_iterate[i] = (up_limit[i]-low_limit[i])/(range_num-1); + + } + for(j=0;j < _row;j++) + { + out[j] = low_limit[j]; /* For every row first element is the first value of low_limit array*/ + temp = low_limit[j]; + for(k=1;k < (float)range_num;k++ ) + { + out[(_row*k)+j] = temp + step_iterate[j]; /* Output matrix positions for 3 X 5 matrix are [0 3 6 9 12;1 4 7 10 13;2 5 8 11 14] so (_row*k)+j) used*/ + temp = out[(_row*k)+j]; + if(k == (float)range_num-1 ) + { + out[(_row*k)+j] = (float)up_limit[j]; /* Last value of output is equal to first value of up_limit array*/ + } + + } + + + } + + + + +} + diff --git a/src/c/elementaryFunctions/linspace/slinspaces.c b/src/c/elementaryFunctions/linspace/slinspaces.c new file mode 100644 index 0000000..2404f4d --- /dev/null +++ b/src/c/elementaryFunctions/linspace/slinspaces.c @@ -0,0 +1,33 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ukasha Noor + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + +#include "linspace.h" +void slinspaces(float low_limit,float up_limit,float range_num,float *out) +{ + int j; + float temp = low_limit; + float step_iterate = (up_limit-low_limit)/(range_num-1); + out[0] = low_limit; /*First value of output is equal to low_limit value*/ + for(j=1; j<(float)range_num; j++) + { + out[j] = temp + step_iterate; + temp = out[j]; + if(j == (float)range_num-1 ) + { + out[j] = (float)up_limit; /* Last value of output is equal to up_limit value*/ + } + } + + + +} + diff --git a/src/c/interpolation/includes/interp1.h b/src/c/interpolation/includes/interp1.h index 1c01417..738bfe6 100644 --- a/src/c/interpolation/includes/interp1.h +++ b/src/c/interpolation/includes/interp1.h @@ -23,6 +23,8 @@ extern "C" { //void dinterp13a(double *x,double *fx,double *q,int size,double *out); void dinterp13a(double *x,int size1,double *fx,int size2,double *q,int size3,char *a,int size4,double *out); +void sinterp13a(float *x,int size1,float *fx,int size2,float *q,int size3,char *a,int size4,float *out); + #ifdef __cplusplus } /* extern "C" */ #endif diff --git a/src/c/interpolation/interfaces/int_interp1.h b/src/c/interpolation/interfaces/int_interp1.h index 6d579e1..07d8ece 100644 --- a/src/c/interpolation/interfaces/int_interp1.h +++ b/src/c/interpolation/interfaces/int_interp1.h @@ -19,9 +19,13 @@ #include "interp1.h" #include <string.h> -#define d2d2d2interp1d2(x,size1,fx,size2,q,size3,out) dinterp13a(x,size1[0]*size1[1],fx,size2[0]*size1[1],q,size3[0]*size3[1],"linear",6,out) +#define d2d2d2interp1d2(x,size1,fx,size2,q,size3,out) dinterp13a(x,size1[0]*size1[1],fx,size2[0]*size2[1],q,size3[0]*size3[1],"linear",6,out) -#define d2d2d2g2interp1d2(x,size1,fx,size2,q,size3,ch,size4,out) dinterp13a(x,size1[0]*size1[1],fx,size2[0]*size1[1],q,size3[0]*size3[1],ch,size4[0]*size4[1],out) +#define d2d2d2g2interp1d2(x,size1,fx,size2,q,size3,ch,size4,out) dinterp13a(x,size1[0]*size1[1],fx,size2[0]*size2[1],q,size3[0]*size3[1],ch,size4[0]*size4[1],out) + +#define s2s2s2interp1s2(x,size1,fx,size2,q,size3,out) sinterp13a(x,size1[0]*size1[1],fx,size2[0]*size2[1],q,size3[0]*size3[1],"linear",6,out) + +#define s2s2s2g2interp1s2(x,size1,fx,size2,q,size3,ch,size4,out) sinterp13a(x,size1[0]*size1[1],fx,size2[0]*size2[1],q,size3[0]*size3[1],ch,size4[0]*size4[1],out) #endif diff --git a/src/c/interpolation/interp1/sinterp13a.c b/src/c/interpolation/interp1/sinterp13a.c new file mode 100644 index 0000000..b8cb085 --- /dev/null +++ b/src/c/interpolation/interp1/sinterp13a.c @@ -0,0 +1,75 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ukasha Noor + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + + +#include "interp1.h" +#include <string.h> + +void sinterp13a(float *x,int size1,float *fx,int size2,float *q,int size3,char *ch,int size4,float *out) +{ + int i,j,k,f; + float a,b; + if(strcmp(ch,"linear")==0) + { + for(i=0;i<size3;i++) + { + f=0; + for(j=0;j<size1;j++) + { + if(q[i]==x[j]) + { + out[i]=fx[j]; + f=1; + break; + } + } + if(f==0) + { + j=0; + while(q[i]>x[j]) + { + j++; + } + a=x[j-1]; + b=x[j]; + out[i]=fx[j-1]+(q[i]-a)*((fx[j]-fx[j-1])/(b-a)); + } + } + } + else if(strcmp(ch,"nearest")==0) + { + for(i=0;i<size3;i++) + { + f=0; + for(j=0;j<size1;j++) + { + if(q[i]==x[j]) + { + out[i]=fx[j]; + f=1; + break; + } + } + if(f==0) + { + j=0; + while(q[i]>x[j]) + { + j++; + } + out[i]=fx[j]; + } + } + } +} + + diff --git a/src/c/signalProcessing/includes/dct.h b/src/c/signalProcessing/includes/dct.h index 5255241..80668ff 100644 --- a/src/c/signalProcessing/includes/dct.h +++ b/src/c/signalProcessing/includes/dct.h @@ -25,6 +25,8 @@ extern "C" { void ddcta(double *in,int row,int col,int sign,double *out); +void sdcta(float *in,int row,int col,int sign,float *out); + void zdcta(doubleComplex *in,int row,int col,int sign,doubleComplex *out); void cdcta(floatComplex *in,int row,int col,int sign,floatComplex *out); diff --git a/src/c/signalProcessing/includes/idct.h b/src/c/signalProcessing/includes/idct.h index 13458b7..1e7b85b 100644 --- a/src/c/signalProcessing/includes/idct.h +++ b/src/c/signalProcessing/includes/idct.h @@ -25,6 +25,8 @@ extern "C" { void didcta(double *in,int row,int col,double *out); +void sidcta(float *in,int row,int col,float *out); + void zidcta(doubleComplex *in,int row,int col,doubleComplex *out); void cidcta(floatComplex *in,int row,int col,floatComplex *out); diff --git a/src/c/signalProcessing/interfaces/int_dct.h b/src/c/signalProcessing/interfaces/int_dct.h index 6cfb21c..3481c4d 100644 --- a/src/c/signalProcessing/interfaces/int_dct.h +++ b/src/c/signalProcessing/interfaces/int_dct.h @@ -21,6 +21,10 @@ #define d2d0dctd2(in,size,sign,out) ddcta(in,size[0],size[1],sign,out) +#define s2dcts2(in,size,out) sdcta(in,size[0],size[1],-1,out) + +#define s2s0dcts2(in,size,sign,out) sdcta(in,size[0],size[1],sign,out) + #define z2dctz2(in,size,out) zdcta(in,size[0],size[1],-1,out) #define z2d0dctz2(in,size,sign,out) zdcta(in,size[0],size[1],sign,out) diff --git a/src/c/signalProcessing/interfaces/int_idct.h b/src/c/signalProcessing/interfaces/int_idct.h index c3a174a..f705fe2 100644 --- a/src/c/signalProcessing/interfaces/int_idct.h +++ b/src/c/signalProcessing/interfaces/int_idct.h @@ -19,6 +19,8 @@ #define d2idctd2(in,size,out) didcta(in,size[0],size[1],out) +#define s2idcts2(in,size,out) sidcta(in,size[0],size[1],out) + #define z2idctz2(in,size,out) zidcta(in,size[0],size[1],out) #define c2idctc2(in,size,out) cidcta(in,size[0],size[1],out) diff --git a/src/c/signalProcessing/transforms/dct/sdcta.c b/src/c/signalProcessing/transforms/dct/sdcta.c new file mode 100644 index 0000000..9f380e8 --- /dev/null +++ b/src/c/signalProcessing/transforms/dct/sdcta.c @@ -0,0 +1,160 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ukasha Noor + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + + +#include "dct.h" +/*#include <fftw3.h>*/ +#include <math.h> + +void sdcta(float *in,int row,int col,int sign,float *out) +{ + int i,j,k,u,v; + int n; + int x,y; + float res,ress; + float re,z,q,m; + if(sign==-1) + { + if(row==1) + { + n=col; + for(u=0;u<row;u++) + { + for(v=0;v<col;v++) + { + x=v*row+u; + out[x]=0; + for(i=0;i<row;i++) + { + for(j=0;j<col;j++) + { + y=row*j+i; + out[x]+=in[y]*(cos(((M_PI)*(y+1-1./2.)*(x))/n)); + } + } + if(x==0) + out[x]*=1./(sqrt(n)); + else + { + float res=2./n; + out[x]*=sqrt(res); + } + } + } + } + else + { + n=col*row; + for(u=0;u<row;u++) + { + for(v=0;v<col;v++) + { + x=v*row+u; + out[x]=0; + for(i=0;i<row;i++) + { + re=0; + for(j=0;j<col;j++) + { + m=(float)in[j*row+i]; + z=(float)(((float)j+1.0/2.0)*(float)v); + q=(float)(M_PI/(float)col); + re+=m*(cos(q*z)); + } + z=(float)(((float)i+1.0/2.0)*(float)u); + q=(float)(M_PI/(float)row); + out[x]+=re*(cos(q*z)); + } + if(u==0) + { + out[x]/=sqrt((float)row); + if(v==0) + out[x]/=sqrt((float)col); + else + out[x]*=sqrt(2./col); + } + else + { + out[x]*=sqrt(2./row); + if(v==0) + out[x]/=sqrt((float)col); + else + out[x]*=sqrt(2./col); + } + } + } + + } + } + else if(sign==1) + { + n=col; + if(row==1) + { + res=1./sqrt(n); + ress=sqrt(2./n); + for(u=0;u<row;u++) + { + for(v=0;v<col;v++) + { + x=v*row+u; + out[x]=0; + for(i=0;i<row;i++) + { + for(j=0;j<col;j++) + { + y=row*j+i; + if(y==0) + out[x]+=res*in[y]*(cos(((M_PI)*(j)*(v+1./2.))/n)); + else + out[x]+=ress*in[y]*(cos(((M_PI)*(j)*(v+1./2.))/n)); + } + } + } + + } + } + else + { + for(u=0;u<row;u++) + { + for(v=0;v<col;v++) + { + x=v*row+u; + out[x]=0; + for(i=0;i<row;i++) + { + re=0; + for(j=0;j<col;j++) + { + y=row*j+i; + m=(float)in[j*row+i]; + z=(float)(((float)v+1.0/2.0)*(float)j); + q=(float)(M_PI/(float)col); + m=m*(cos(q*z)); + if(j==0) + re+=m/sqrt((float)col); + else + re+=m*sqrt(2./col); + } + z=(float)(((float)u+1.0/2.0)*(float)i); + q=(float)(M_PI/(float)row); + if(i==0) + out[x]+=(re*(cos(z*q)))/sqrt((float)row); + else + out[x]+=(re*(cos(z*q))*sqrt(2./row)); + } + } + } + } + } +} diff --git a/src/c/signalProcessing/transforms/idct/sidcta.c b/src/c/signalProcessing/transforms/idct/sidcta.c new file mode 100644 index 0000000..62f85da --- /dev/null +++ b/src/c/signalProcessing/transforms/idct/sidcta.c @@ -0,0 +1,83 @@ +/* Copyright (C) 2016 - IIT Bombay - FOSSEE + + This file must be used under the terms of the CeCILL. + This source file is licensed as described in the file COPYING, which + you should have received as part of this distribution. The terms + are also available at + http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt + Author: Ukasha Noor + Organization: FOSSEE, IIT Bombay + Email: toolbox@scilab.in +*/ + + +#include "idct.h" +/*#include <fftw3.h>*/ +#include <math.h> + +void sidcta(float *in,int row,int col,float *out) +{ + int i,j,k,u,v; + int n=col; + int x,y; + float res,ress; + float re,z,q,m; + if(row==1) + { + res=1./sqrt(n); + ress=sqrt(2./n); + for(u=0;u<row;u++) + { + for(v=0;v<col;v++) + { + x=v*row+u; + out[x]=0; + for(i=0;i<row;i++) + { + for(j=0;j<col;j++) + { + y=row*j+i; + if(y==0) + out[x]+=res*in[y]*(cos(((M_PI)*(j)*(v+1./2.))/n)); + else + out[x]+=ress*in[y]*(cos(((M_PI)*(j)*(v+1./2.))/n)); + } + } + } + + } + } + else + { + for(u=0;u<row;u++) + { + for(v=0;v<col;v++) + { + x=v*row+u; + out[x]=0; + for(i=0;i<row;i++) + { + re=0; + for(j=0;j<col;j++) + { + y=row*j+i; + m=(float)in[j*row+i]; + z=(float)(((float)v+1.0/2.0)*(float)j); + q=(float)(M_PI/(float)col); + m=m*(cos(q*z)); + if(j==0) + re+=m/sqrt((float)col); + else + re+=m*sqrt(2./col); + } + z=(float)(((float)u+1.0/2.0)*(float)i); + q=(float)(M_PI/(float)row); + if(i==0) + out[x]+=(re*(cos(z*q)))/sqrt((float)row); + else + out[x]+=(re*(cos(z*q))*sqrt(2./row)); + } + } + } + } +} |