Mentions légales du service

Skip to content
Snippets Groups Projects
Commit bfb0ca39 authored by hhakim's avatar hhakim
Browse files

Implement in C++ and enable in matfaust the default normalization for FaustFactory.dft().

Issue #112 related.
parent 6308c50a
Branches
Tags
No related merge requests found
...@@ -253,7 +253,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -253,7 +253,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
end end
i = i + 1; i = i + 1;
end end
this.assertEqual(full(FaustFactory.wht(n)), full(normalize(FaustFactory.wht(n))), 'AbsTol', 10^-12) this.assertEqual(full(FaustFactory.wht(n)), full(normalize(FaustFactory.wht(n, false))), 'AbsTol', 10^-12)
end end
function testFourier(this) function testFourier(this)
...@@ -266,7 +266,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase ...@@ -266,7 +266,7 @@ classdef FaustFactoryTest < matlab.unittest.TestCase
fftI = fft(eye(n)); fftI = fft(eye(n));
% this.verifyEqual(nnz(fH), numel(fH)); % this.verifyEqual(nnz(fH), numel(fH));
this.verifyEqual(norm(fF-fftI), 0, 'AbsTol', 10^-12); this.verifyEqual(norm(fF-fftI), 0, 'AbsTol', 10^-12);
this.assertEqual(full(FaustFactory.dft(n)), full(normalize(FaustFactory.dft(n))), 'AbsTol', 10^-12) this.assertEqual(full(FaustFactory.dft(n)), full(normalize(FaustFactory.dft(n, false))), 'AbsTol', 10^-12)
end end
end end
......
...@@ -832,20 +832,21 @@ classdef FaustFactory ...@@ -832,20 +832,21 @@ classdef FaustFactory
if(log2n>31) if(log2n>31)
error('Can''t handle a FFT Faust of order larger than 2^31') error('Can''t handle a FFT Faust of order larger than 2^31')
end end
core_obj = mexFaustCplx('fourier', log2n);
is_real = false;
e = MException('FAUST:OOM', 'Out of Memory');
if(core_obj == 0)
throw(e)
end
F = matfaust.Faust(core_obj, is_real);
if(length(varargin) > 0) if(length(varargin) > 0)
if(~ islogical(varargin{1})) if(~ islogical(varargin{1}))
error('wht optional second argument must be a boolean'); error('wht optional second argument must be a boolean');
end end
norma = varargin{1};
else else
F = F*(1/sqrt(n)); norma = true; % normalization by default
end end
core_obj = mexFaustCplx('fourier', log2n, norma);
is_real = false;
e = MException('FAUST:OOM', 'Out of Memory');
if(core_obj == 0)
throw(e)
end
F = matfaust.Faust(core_obj, is_real);
end end
%========================================================================================== %==========================================================================================
......
...@@ -177,12 +177,13 @@ void save(Faust::TransformHelper<SCALAR,Cpu>* core_ptr, int nargs, const mxArray ...@@ -177,12 +177,13 @@ void save(Faust::TransformHelper<SCALAR,Cpu>* core_ptr, int nargs, const mxArray
if(!strcmp("fourier", cmd)){ if(!strcmp("fourier", cmd)){
if(nlhs!=1) if(nlhs!=1)
mexErrMsgTxt("fourier(): 1 variable result is expected."); mexErrMsgTxt("fourier(): 1 variable result is expected.");
if(nrhs < 2) if(nrhs < 3)
mexErrMsgTxt("fourier(): wrong number of arguments (must be 2)"); mexErrMsgTxt("fourier(): wrong number of arguments (must be 2)");
unsigned int n = (unsigned int) mxGetScalar(prhs[1]); unsigned int n = (unsigned int) mxGetScalar(prhs[1]);
bool norma = (bool) mxGetScalar(prhs[2]);
//printf("mexFaust.cpp hadamard(): faust creation\n"); //printf("mexFaust.cpp hadamard(): faust creation\n");
Faust::TransformHelper<complex<FPP>,Cpu>* F = Faust::TransformHelper<complex<FPP>,Cpu>::fourierFaust(n); Faust::TransformHelper<complex<FPP>,Cpu>* F = Faust::TransformHelper<complex<FPP>,Cpu>::fourierFaust(n, norma);
//H->display(); //H->display();
if(F) //not NULL if(F) //not NULL
plhs[0]=convertPtr2Mat<Faust::TransformHelper<complex<FPP>,Cpu> >(F); plhs[0]=convertPtr2Mat<Faust::TransformHelper<complex<FPP>,Cpu> >(F);
...@@ -520,7 +521,7 @@ void save(Faust::TransformHelper<SCALAR,Cpu>* core_ptr, int nargs, const mxArray ...@@ -520,7 +521,7 @@ void save(Faust::TransformHelper<SCALAR,Cpu>* core_ptr, int nargs, const mxArray
if(!strcmp("normalize", cmd)) if(!strcmp("normalize", cmd))
{ {
int ord = (int) mxGetScalar(prhs[2]); int ord = (int) mxGetScalar(prhs[2]);
if(ord == 2) ord = -2; //tmp workaround to the bug in normalization according 2-norm on complex Faust
Faust::TransformHelper<SCALAR,Cpu>* th = core_ptr->normalize(ord); Faust::TransformHelper<SCALAR,Cpu>* th = core_ptr->normalize(ord);
plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th); plhs[0] = convertPtr2Mat<Faust::TransformHelper<SCALAR,Cpu> >(th);
return; return;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment