help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do you pass two Octave functions to an .oct function?


From: Jaroslav Hajek
Subject: Re: How do you pass two Octave functions to an .oct function?
Date: Fri, 16 Oct 2009 07:53:36 +0200

On Thu, Oct 15, 2009 at 3:40 PM, babelproofreader
<address@hidden> wrote:
>
>>Please be more specific and show some code if possible...
>
> My code so far is
>
> #include <octave/oct.h>
> #include <octave/dColVector.h>
> #include <octave/parse.h>
>
> DEFUN_DLD (rollingfft, args, , "Help String")
> {
> octave_value_list retval;
> octave_value_list fft_result_vector;
> octave_value_list ifft_result_vector;
> octave_value_list real_result_vector;
>
>  octave_function *fcn1 = args(0).function_value (); // supply Octave "fft"
> function
>  octave_function *fcn2 = args(1).function_value (); // supply Octave "ifft"
> function
>  octave_function *fcn3 = args(2).function_value (); // supply Octave "real"
> function
>  ColumnVector input_vector = args(3).column_vector_value ();
>  ColumnVector output_vector = args(3).column_vector_value ();
>  OCTAVE_LOCAL_BUFFER( double , rolling_vector , 32 );
>
>   for (octave_idx_type ii (31); ii<input_vector.length (); ii++)
>     {
>       for (octave_idx_type jj (0); jj<(32); jj++)
>         {
>         rolling_vector(jj) = input_vector(ii - (ii - jj));
>         }
>           // detrend rolling vector code here
>
>           fft_result_vector = feval( fcn1 , rolling_vector );
>
>           // fft_result_vector frequency filter code here
>
>           ifft_result_vector = feval( fcn2 , fft_result_vector );
>           real_result_vector = feval( fcn3 , ifft_result_vector );
>
>           // real_result_vector retrend code here
>
>           output_vector(ii) = real_result_vector(31);
>     }
>
>
>  retval = output_vector;
>
> return retval;
> }
>
> but it fails on compile with
>
> octave:1> mkoctfile rollingfft.cc
> rollingfft.cc: In function ‘octave_value_list Frollingfft(const
> octave_value_list&, int)’:
> rollingfft.cc:27: error: call of overloaded ‘feval(octave_function*&,
> double*&)’ is ambiguous
> /usr/include/octave-3.0.1/octave/parse.h:123: note: candidates are:
> octave_value_list feval(octave_function*, const octave_value_list&, int)
> <near match>
> /usr/include/octave-3.0.1/octave/parse.h:126: note:
> octave_value_list feval(const octave_value_list&, int) <near match>
> rollingfft.cc:36: error: cannot convert ‘octave_value’ to ‘double’ in
> assignment
> rollingfft.cc:40: error: no match for ‘operator=’ in ‘retval =
> output_vector’
> /usr/include/octave-3.0.1/octave/oct-obj.h:75: note: candidates are:
> octave_value_list& octave_value_list::operator=(const octave_value_list&)
>

I'd think these messages are pretty understandable.
You simply can't pass a raw double * pointer (the local buffer) to
feval, because it can't handle it. You need to create a valid
octave_value from it. Declare rolling_vector as ColumnVector and it
will likely work.

> What I am attempting to do is to smooth a time series by moving a window
> across the series, and using fft to lowpass filter in the frequency domain.

Have you tried to do this in m-code first? Maybe it could be made fast
enough. Especially if you upgrade Octave (3.0.1 is ancient).

hth

-- 
RNDr. Jaroslav Hajek
computing expert & GNU Octave developer
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz



reply via email to

[Prev in Thread] Current Thread [Next in Thread]