summaryrefslogtreecommitdiff
path: root/src/c/signalProcessing/transforms/dct
diff options
context:
space:
mode:
authorBrijeshcr2017-07-06 15:48:47 +0530
committerGitHub2017-07-06 15:48:47 +0530
commitea958d3c401761dcc24865d9639b2fab31038db8 (patch)
tree8cea93113a46d7015d1a10638778f92275a0ca94 /src/c/signalProcessing/transforms/dct
parentcb1d99232e521c34e9f0c271a6c4176cc7b9cbe4 (diff)
downloadScilab2C_fossee_old-ea958d3c401761dcc24865d9639b2fab31038db8.tar.gz
Scilab2C_fossee_old-ea958d3c401761dcc24865d9639b2fab31038db8.tar.bz2
Scilab2C_fossee_old-ea958d3c401761dcc24865d9639b2fab31038db8.zip
Revert "LinearAlgebra Function Added"
Diffstat (limited to 'src/c/signalProcessing/transforms/dct')
-rw-r--r--src/c/signalProcessing/transforms/dct/cdcta.c230
-rw-r--r--src/c/signalProcessing/transforms/dct/ddcta.c160
-rw-r--r--src/c/signalProcessing/transforms/dct/sdcta.c160
-rw-r--r--src/c/signalProcessing/transforms/dct/zdcta.c230
4 files changed, 780 insertions, 0 deletions
diff --git a/src/c/signalProcessing/transforms/dct/cdcta.c b/src/c/signalProcessing/transforms/dct/cdcta.c
new file mode 100644
index 0000000..7ff8364
--- /dev/null
+++ b/src/c/signalProcessing/transforms/dct/cdcta.c
@@ -0,0 +1,230 @@
+/* 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 "addition.h"
+#include "types.h"
+#include "floatComplex.h"
+#include "multiplication.h"
+/*#include "matrixMultiplication"*/
+/*#include <fftw3.h>*/
+#include <math.h>
+
+void cdcta(floatComplex *in,int row,int col,int sign,floatComplex *out)
+{
+ int i,j,k,u,v;
+ int n;
+ int x,y;
+ float res,ress,vv,ff;
+ float re,z,q,m;
+ floatComplex accu = FloatComplex(0, 0);
+ floatComplex temp,mm,aa,bb,cc;
+ 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]=FloatComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ for(j=0;j<col;j++)
+ {
+ y=row*j+i;
+ vv = cos(((M_PI)*(y+1-1./2.)*(x))/n);
+ aa = FloatComplex(vv,0);
+ temp=cmuls(in[y],aa);
+ out[x]=cadds(out[x],temp);
+ }
+ }
+ if(x==0)
+ {
+ vv = 1./(sqrt(n));
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ }
+ else
+ {
+ float res=2./n;
+ res = sqrt(res);
+ aa = FloatComplex(res,0);
+ out[x]=cmuls(out[x],aa);
+ }
+ }
+ }
+ }
+ else
+ {
+ n=col*row;
+ for(u=0;u<row;u++)
+ {
+ for(v=0;v<col;v++)
+ {
+ x=v*row+u;
+ out[x]=FloatComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ temp=FloatComplex(0,0);
+ mm=FloatComplex(0,0);
+ for(j=0;j<col;j++)
+ {
+ y=j*row+i;
+ z=(float)(((float)j+1.0/2.0)*(float)v);
+ q=(float)(M_PI/(float)col);
+ vv = cos(q*z);
+ aa = FloatComplex(vv,0);
+ mm=cmuls(in[y],aa);
+ temp=cadds(temp,mm);
+ }
+ z=(float)(((float)i+1.0/2.0)*(float)u);
+ q=(float)(M_PI/(float)row);
+ ff = cos(q*z);
+ bb = FloatComplex(ff,0);
+ temp=cmuls(temp,bb);
+ out[x]=cadds(out[x],temp);
+ }
+ if(u==0)
+ {
+ vv = 1./sqrt((float)row);
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ if(v==0)
+ {
+ vv = 1./sqrt((float)col);
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ }
+ else
+ {
+ vv = sqrt(2./col);
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ }
+ }
+ else
+ {
+ vv = sqrt(2./row);
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ if(v==0)
+ {
+ vv = 1./sqrt((float)col);
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ }
+ else
+ {
+ vv = sqrt(2./col);
+ aa = FloatComplex(vv,0);
+ out[x]=cmuls(out[x],aa);
+ }
+ }
+ }
+ }
+ }
+ }
+ 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]=FloatComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ for(j=0;j<col;j++)
+ {
+ y=row*j+i;
+ if(y==0)
+ {
+ q=res*(cos(((M_PI)*(j)*(v+1./2.))/n));
+ aa = FloatComplex(q,0);
+ out[x]=cadds(out[x],cmuls(in[y],aa));
+ }
+ else
+ {
+ q=ress*(cos(((M_PI)*(j)*(v+1./2.))/n));
+ aa = FloatComplex(q,0);
+ out[x]=cadds(out[x],cmuls(in[y],aa));
+ }
+ }
+ }
+ }
+
+ }
+ }
+ else
+ {
+ for(u=0;u<row;u++)
+ {
+ for(v=0;v<col;v++)
+ {
+ x=v*row+u;
+ out[x]=FloatComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ re=0;
+ mm=FloatComplex(0,0);
+ temp=FloatComplex(0,0);
+ for(j=0;j<col;j++)
+ {
+ y=row*j+i;
+ mm=in[j*row+i];
+ z=(float)(((float)v+1.0/2.0)*(float)j);
+ q=(float)(M_PI/(float)col);
+ vv = cos(q*z);
+ aa = FloatComplex(vv,0);
+ mm=cmuls(mm,aa);
+ if(j==0)
+ {
+ vv = 1./sqrt((float)col);
+ aa = FloatComplex(vv,0);
+ temp=cadds(temp,cmuls(mm,aa));
+ }
+ else
+ {
+ vv = sqrt(2./col);
+ aa = FloatComplex(vv,0);
+ temp=cadds(temp,cmuls(mm,aa));
+ }
+ }
+ z=(float)(((float)u+1.0/2.0)*(float)i);
+ q=(float)(M_PI/(float)row);
+ if(i==0)
+ {
+ vv = (cos(z*q))*(1./sqrt(row));
+ aa = FloatComplex(vv,0);
+ out[x]=cadds(out[x],cmuls(temp,aa));
+ }
+ else
+ {
+ vv = (cos(z*q))*sqrt(2./row);
+ aa = FloatComplex(vv,0);
+ out[x]=cadds(out[x],cmuls(temp,aa));
+ }
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/c/signalProcessing/transforms/dct/ddcta.c b/src/c/signalProcessing/transforms/dct/ddcta.c
new file mode 100644
index 0000000..3802c81
--- /dev/null
+++ b/src/c/signalProcessing/transforms/dct/ddcta.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 ddcta(double *in,int row,int col,int sign,double *out)
+{
+ int i,j,k,u,v;
+ int n;
+ int x,y;
+ double res,ress;
+ double 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
+ {
+ double 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=(double)in[j*row+i];
+ z=(double)(((double)j+1.0/2.0)*(double)v);
+ q=(double)(M_PI/(double)col);
+ re+=m*(cos(q*z));
+ }
+ z=(double)(((double)i+1.0/2.0)*(double)u);
+ q=(double)(M_PI/(double)row);
+ out[x]+=re*(cos(q*z));
+ }
+ if(u==0)
+ {
+ out[x]/=sqrt((double)row);
+ if(v==0)
+ out[x]/=sqrt((double)col);
+ else
+ out[x]*=sqrt(2./col);
+ }
+ else
+ {
+ out[x]*=sqrt(2./row);
+ if(v==0)
+ out[x]/=sqrt((double)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=(double)in[j*row+i];
+ z=(double)(((double)v+1.0/2.0)*(double)j);
+ q=(double)(M_PI/(double)col);
+ m=m*(cos(q*z));
+ if(j==0)
+ re+=m/sqrt((double)col);
+ else
+ re+=m*sqrt(2./col);
+ }
+ z=(double)(((double)u+1.0/2.0)*(double)i);
+ q=(double)(M_PI/(double)row);
+ if(i==0)
+ out[x]+=(re*(cos(z*q)))/sqrt((double)row);
+ else
+ out[x]+=(re*(cos(z*q))*sqrt(2./row));
+ }
+ }
+ }
+ }
+ }
+}
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/dct/zdcta.c b/src/c/signalProcessing/transforms/dct/zdcta.c
new file mode 100644
index 0000000..3ae2e33
--- /dev/null
+++ b/src/c/signalProcessing/transforms/dct/zdcta.c
@@ -0,0 +1,230 @@
+/* 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 "addition.h"
+#include "types.h"
+#include "doubleComplex.h"
+#include "multiplication.h"
+/*#include "matrixMultiplication"*/
+/*#include <fftw3.h>*/
+#include <math.h>
+
+void zdcta(doubleComplex *in,int row,int col,int sign,doubleComplex *out)
+{
+ int i,j,k,u,v;
+ int n;
+ int x,y;
+ double res,ress,vv,ff;
+ double re,z,q,m;
+ doubleComplex accu = DoubleComplex(0, 0);
+ doubleComplex temp,mm,aa,bb,cc;
+ 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]=DoubleComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ for(j=0;j<col;j++)
+ {
+ y=row*j+i;
+ vv = cos(((M_PI)*(y+1-1./2.)*(x))/n);
+ aa = DoubleComplex(vv,0);
+ temp=zmuls(in[y],aa);
+ out[x]=zadds(out[x],temp);
+ }
+ }
+ if(x==0)
+ {
+ vv = 1./(sqrt(n));
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ }
+ else
+ {
+ double res=2./n;
+ res = sqrt(res);
+ aa = DoubleComplex(res,0);
+ out[x]=zmuls(out[x],aa);
+ }
+ }
+ }
+ }
+ else
+ {
+ n=col*row;
+ for(u=0;u<row;u++)
+ {
+ for(v=0;v<col;v++)
+ {
+ x=v*row+u;
+ out[x]=DoubleComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ temp=DoubleComplex(0,0);
+ mm=DoubleComplex(0,0);
+ for(j=0;j<col;j++)
+ {
+ y=j*row+i;
+ z=(double )(((double )j+1.0/2.0)*(double )v);
+ q=(double )(M_PI/(double )col);
+ vv = cos(q*z);
+ aa = DoubleComplex(vv,0);
+ mm=zmuls(in[y],aa);
+ temp=zadds(temp,mm);
+ }
+ z=(double )(((double )i+1.0/2.0)*(double )u);
+ q=(double )(M_PI/(double )row);
+ ff = cos(q*z);
+ bb = DoubleComplex(ff,0);
+ temp=zmuls(temp,bb);
+ out[x]=zadds(out[x],temp);
+ }
+ if(u==0)
+ {
+ vv = 1./sqrt((double )row);
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ if(v==0)
+ {
+ vv = 1./sqrt((double )col);
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ }
+ else
+ {
+ vv = sqrt(2./col);
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ }
+ }
+ else
+ {
+ vv = sqrt(2./row);
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ if(v==0)
+ {
+ vv = 1./sqrt((double )col);
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ }
+ else
+ {
+ vv = sqrt(2./col);
+ aa = DoubleComplex(vv,0);
+ out[x]=zmuls(out[x],aa);
+ }
+ }
+ }
+ }
+ }
+ }
+ 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]=DoubleComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ for(j=0;j<col;j++)
+ {
+ y=row*j+i;
+ if(y==0)
+ {
+ q=res*(cos(((M_PI)*(j)*(v+1./2.))/n));
+ aa = DoubleComplex(q,0);
+ out[x]=zadds(out[x],zmuls(in[y],aa));
+ }
+ else
+ {
+ q=ress*(cos(((M_PI)*(j)*(v+1./2.))/n));
+ aa = DoubleComplex(q,0);
+ out[x]=zadds(out[x],zmuls(in[y],aa));
+ }
+ }
+ }
+ }
+
+ }
+ }
+ else
+ {
+ for(u=0;u<row;u++)
+ {
+ for(v=0;v<col;v++)
+ {
+ x=v*row+u;
+ out[x]=DoubleComplex(0,0);
+ for(i=0;i<row;i++)
+ {
+ re=0;
+ mm=DoubleComplex(0,0);
+ temp=DoubleComplex(0,0);
+ for(j=0;j<col;j++)
+ {
+ y=row*j+i;
+ mm=in[j*row+i];
+ z=(double )(((double )v+1.0/2.0)*(double )j);
+ q=(double )(M_PI/(double )col);
+ vv = cos(q*z);
+ aa = DoubleComplex(vv,0);
+ mm=zmuls(mm,aa);
+ if(j==0)
+ {
+ vv = 1./sqrt((double )col);
+ aa = DoubleComplex(vv,0);
+ temp=zadds(temp,zmuls(mm,aa));
+ }
+ else
+ {
+ vv = sqrt(2./col);
+ aa = DoubleComplex(vv,0);
+ temp=zadds(temp,zmuls(mm,aa));
+ }
+ }
+ z=(double )(((double )u+1.0/2.0)*(double )i);
+ q=(double )(M_PI/(double )row);
+ if(i==0)
+ {
+ vv = (cos(z*q))*(1./sqrt(row));
+ aa = DoubleComplex(vv,0);
+ out[x]=zadds(out[x],zmuls(temp,aa));
+ }
+ else
+ {
+ vv = (cos(z*q))*sqrt(2./row);
+ aa = DoubleComplex(vv,0);
+ out[x]=zadds(out[x],zmuls(temp,aa));
+ }
+ }
+ }
+ }
+ }
+ }
+}