Re: results with strange floating-point number bias

[email protected] Wed, 6 Aug 2003 11:49:13 -0300
Newsgroups gmane.comp.gnu.octave.sources
Message-ID <[email protected]>
Here is the source code of the funtion.  I'm compiling it with


	mkoctfile-2.1.50 fftnic.cc -L$(HOME)/lib -I$(HOME)/include -lfftw3 -lstdc++-3-libc6.2-2-2.10.0

-- 
Nicolau Werneck <[email protected]>         9F99 25AB E47E 8724 2F71
http://cefala.org/~nwerneck                   EA40 DC23 42CE 6B76 B07F
"To his dog, every man is Napoleon; hence the constant popularity of dogs."
-- Aldous Huxley
fftnic.cc (text/x-c++src, 1.7 KB)
#include "/home/nwerneck/include/octave-2.1.50/octave/oct.h"
#include "/home/nwerneck/include/octave-2.1.50/octave/oct-cmplx.h"

#include "/home/nwerneck/include/fftw3.h"


DEFUN_DLD(fftnic, args, ,
"-*- texinfo -*-\n\
@deftypefn {Loadable Function} {} overdrive (@var{signal}, @var{a}, @var{b})\n\
Distorted amplification function. This function emulates an overdriven\n\
amplifier circuit or speaker, multiplying the input signal by @var{b}/@var{a}\n\
when the absolute value of the signal is smaller than @var{a}, and by a smaller\n\
amount when the signal exceeds the linearity treshold.\n\
\n\
The resulting input-output characteristic curve is simply a straight line\n\
from (0,0) to (@var{a},@var{b}) and then to (1,1).\n\

The command\n\

> plot(overdrive([-1:0.1:1]', 0.25, 0.75));

will produce a example plot of the input-output characteristic curve of an\n\
overdrive effect.\n\

> overdrive(sin([0:0.1:2*pi]'), 0, 1)

will produce a square wave, Cross-over occurs when @var{a} > @var{b}. The command\n\

> overdrive(sin([0:0.1:2*pi]'), 0.1, 0)

will return a sinusoidal signal with cross-over distortion.
@end deftypefn")

{

//	double * teste;
	octave_value retval;
	
	fftw_plan ftp;
	
	if (args.length () != 1)  {
		print_usage ("fftnic");
		return retval;
	}

	if(!args(0).is_real_matrix())  {
		gripe_wrong_type_arg("fftnic", args(0));
		return retval;
	}

	Matrix m = args(0).matrix_value();
	ComplexMatrix sai;
	ComplexColumnVector ccv( (m.rows()/2)+1 );

	ftp = fftw_plan_dft_r2c_1d(m.column(0).length(), \
		m.column(0).fortran_vec(), \
		reinterpret_cast<fftw_complex *> (ccv.fortran_vec() ),\
	        FFTW_ESTIMATE );

	fftw_execute(ftp);
	
	//sai = ComplexMatrix(ccv);
	fftw_destroy_plan(ftp);

	
	return octave_value(ccv);
}