buffer (signal)?

View: New views
8 Messages — Rating Filter:   Alert me  

buffer (signal)?

by Sciss-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

hi,

i am trying to run a function that was written for matlab. it breaks  
because the function 'buffer' is missing, something that creates an  
overlapped-chunk version of a vector. on octave-forge's documentation  
site, it is stated:

"buffer  [signal] -- not implemented"

... so i assume this function is missing? i installed the signal  
package but no luck. any clues how i can get a 'buffer' function for  
octave?

thanks a lot! cheers, -sciss-


_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: buffer (signal)?

by Sciss-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

(in the meantime i coded a quick version that works ok with overlap,  
ignoring underlap which i don't need at the moment)


Am 10.04.2008 um 18:31 schrieb Sciss:

> hi,
>
> i am trying to run a function that was written for matlab. it breaks
> because the function 'buffer' is missing, something that creates an
> overlapped-chunk version of a vector. on octave-forge's documentation
> site, it is stated:
>
> "buffer  [signal] -- not implemented"
>
> ... so i assume this function is missing? i installed the signal
> package but no luck. any clues how i can get a 'buffer' function for
> octave?
>
> thanks a lot! cheers, -sciss-
>
>
> _______________________________________________
> Help-octave mailing list
> Help-octave@...
> https://www.cae.wisc.edu/mailman/listinfo/help-octave

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: buffer (signal)?

by dbateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Sciss wrote:
... so i assume this function is missing? i installed the signal  
package but no luck. any clues how i can get a 'buffer' function for  
octave?

Yes, write it :-) Well sorry to be flippant.. However looking at

http://www.mathworks.com/access/helpdesk/help/toolbox/signal/index.html?/access/helpdesk/help/toolbox/signal/buffer.html

in fact it doesn't look all that hard to write this function. One of the forms "y = buffer(x,n)" might be trivially written as

x = x(:);
l = length (x);
m = ceil (l / n);
y = zeros (n, m);
y(1:l) = x;

and the additional arguments aren't that hard to implement either.

Cheers
David

Re: buffer (signal)?

by Ben Abbott :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Thursday, April 10, 2008, at 12:59PM, "Sciss" <contact@...> wrote:

>hi,
>
>i am trying to run a function that was written for matlab. it breaks  
>because the function 'buffer' is missing, something that creates an  
>overlapped-chunk version of a vector. on octave-forge's documentation  
>site, it is stated:
>
>"buffer  [signal] -- not implemented"
>
>... so i assume this function is missing? i installed the signal  
>package but no luck. any clues how i can get a 'buffer' function for  
>octave?
>
>thanks a lot! cheers, -sciss-
>
>

>From the most recent Matlab (7.6)

>> which buffer
'buffer' not found.
>>

Apparently "buffer" is not a core Matlab function.

By chance is the function you're looking for actually a class? ... for example,

http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=14087

If not, can you tell us what "buffer" is supposed to do?

Ben
_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: buffer (signal)?

by Sciss-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

the description is here:

http://www.mathworks.com/access/helpdesk/help/toolbox/signal/buffer.html

meanwhile i started to write something based on that doc. beware as  
i'm absolutely bad with matlab/octave syntax and i stopped to  
implement it when it did it's job (see below) ;-)


%%% begin buffer.m

function [y, z, opt] = buffer( x, n, p, opt )
disp( "WARNING: buffer is a quick hack, don't use for continuous  
buffering" );

if nargin < 3, p = 0; end;
L = length(x);
if p <= 0
        if nargin < 4, skip = 0; else skip = opt; end;
        pre = [];
        m = floor((L-skip)/(n-p)) + (rem((L-skip),(n-p)) >= n);
        z = zeros( (L-skip) - m*(n-p) );
else
        if nargin < 4, pre = zeros( p, 1 ); else pre = opt; end;
        skip = 0;
        if strcmp( pre, 'nodelay' )
                pre = 0;
                m = floor((L-n)/(n-p))+1;
                z = zeros( L - ((m-1)*(n-p)+n) );
        else
                m = floor(L/(n-p));
                z = zeros( L - m*(n-p) );
        end;
end;
y = zeros( n, m );
q = n * m;
y(1:length(pre))=pre;
i = length(pre);
j = skip;
while (i < q && j < L)
        nn = min( min( n, q - i ), L - j );
        y((i+1):(i+nn))=x((j+1):(j+nn));
        i = i + n;
        j = j + n - p;
endwhile

%%% end buffer.m


i used this with a very interesting tool from

http://cosmal.ucsd.edu/cal/projects/CATbox/catbox.htm

--> the ConstQ spectrum analysis tool. all i had to change is to  
comment out the line

progressbar(i/N);

in cqgram.m since it produces some errors with gnuplot. i get  
impressive results, like:

x = auload( '/Users/rutz/Desktop/SineSweep.wav' );
cqgram( x, 16384, 16384-256, 32, 22050, 24, 44100 );


ciao, -sciss-




Am 10.04.2008 um 22:25 schrieb Ben Abbott:

> On Thursday, April 10, 2008, at 12:59PM, "Sciss" <contact@...>  
> wrote:
>> hi,
>>
>> i am trying to run a function that was written for matlab. it breaks
>> because the function 'buffer' is missing, something that creates an
>> overlapped-chunk version of a vector. on octave-forge's documentation
>> site, it is stated:
>>
>> "buffer  [signal] -- not implemented"
>>
>> ... so i assume this function is missing? i installed the signal
>> package but no luck. any clues how i can get a 'buffer' function for
>> octave?
>>
>> thanks a lot! cheers, -sciss-
>>
>>
>
> From the most recent Matlab (7.6)
>
>>> which buffer
> 'buffer' not found.
>>>
>
> Apparently "buffer" is not a core Matlab function.
>
> By chance is the function you're looking for actually a class? ...  
> for example,
>
> http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?
> objectId=14087
>
> If not, can you tell us what "buffer" is supposed to do?
>
> Ben

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave

Re: buffer (signal)?

by dbateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

The below also implements the p argument though is untested as I don't have a machine to test with at the moment, It also doesn't implement the opts arg or the additional output args. Basically just a good start to get the real function written or something to get your script going

D.


function [y, z, opts] = buffer (x, n, p, opts)

  if (nargin < 2 || nargin > 4)
    print_usage ();
  endif
  if (nargin < 3)
    p = 0;
  endif
  if (nargin <  4)
    opts = zeros (1, p);
  endif
  if (nargin == 4)
    error ("unimplemented");
  endif
  if (nargout > 1)
    error ("unimplemented")
  endif

  x = x(:);
  l = length (x);
  m = ceil (l / n);
  y = zeros (n, m);
  y (1 : l) = x;
  if (p < 0)
    y (end + p + 1 : end, :) = [];
  elseif (p > 0)
    y = [zeros(p, m); y];
    y (1 : p, 2 : end) = y (end - p + 1 : end, 1 : end -1);
  endif
endfunction

Re: buffer (signal)?

by dbateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I should read more carefully what I write, the previous version was wrong. Ok I've rewritten it and now actually tested it a little and the attached appears to be a complete implementation of buffer. There might be some corner cases where this function won't work however. For example if the overlap is greater then the number of rows, though I have tested it. This will need additional test code before inclusion in octave-forge.

D.

function [y, z, opt] = buffer (x, n, p, opt)

  if (nargin < 2 || nargin > 4)
    print_usage ();
  endif
  if (nargin < 3)
    p = 0;
  endif
  if (nargin <  4)
    if (p < 0)
      opt = 0;
    else
      opt = zeros (1, p);
    endif
  endif

  x = x (:);
  l = length (x);
  if (p < 0 && opt != 0)
    ## Special case
    if (isscalar (opt) && opt == floor (opt) && opt > 0 && opt <= -p)
      m = ceil ((l + opt) / n);
      y = zeros (n, m);
      y (1 + opt : l + opt) = x;
      y (end + p + 1 : end, :) = [];
      lopt = opt;
    else
      error ("buffer: expecting fourth argument to be and integer between 0 and -p");
    endif
  else
    m = ceil (l / (n - p));
    y = zeros (n - p, m);
    y (1 : l) = x;
    lopt = 0;
    if (p < 0)
      y (end + p + 1 : end, :) = [];
    elseif (p > 0)
      if (ischar (opt))
        if (strcmp (opt, "nodelay"))
          y = [y ; zeros(p, m)];
          y (end - p + 1 : end, 1 : end - 1) = y (1 : p, 2 : end);
          if (sub2ind([n-p, m], p, m) >= l)
            y (:, end) = [];
          endif
        else
          error ("buffer: unexpected string argument");
        endif
      elseif (isvector (opt))
        if (length (opt) == p)
          y = [zeros(p, m); y];
          y (1 : p) = opt;
          y (1 : p, 2 : end) = y (end - p + 1 : end, 1 : end - 1);
          lopt = p;
        else
          error ("buffer: opt vector must be of length p");
        endif
      else
        error ("buffer: unrecognized fourth argument");
      endif
    endif
  endif
  if (nargout > 1)
    [i, j] = ind2sub (size(y), l + lopt + p * (size (y, 2) - 1));
    if (any ([i, j] != size (y)))
       z = y (1 : i, end);
       y (:, end) = [];
    else
       z = zeros (0, 1);
    endif
  endif
endfunction

Re: buffer (signal)?

by David Bateman :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I didn't see your code before I started writing mine.. In any case I
believe I have a fully compatible version of this function, and have
committed it to octave-forge. This includes extensive test code that
I've validated against the matlab version of this function. There are a
lot of weird corner cases to get right in the test code. Maybe you'd
like to check this code out (I'll send it to you offline so that you
don't need to get it from the SVN)

Regards
David

--
David Bateman                                David.Bateman@...
Motorola Labs - Paris                        +33 1 69 35 48 04 (Ph)
Parc Les Algorithmes, Commune de St Aubin    +33 6 72 01 06 33 (Mob)
91193 Gif-Sur-Yvette FRANCE                  +33 1 69 35 77 01 (Fax)

The information contained in this communication has been classified as:

[x] General Business Information
[ ] Motorola Internal Use Only
[ ] Motorola Confidential Proprietary

_______________________________________________
Help-octave mailing list
Help-octave@...
https://www.cae.wisc.edu/mailman/listinfo/help-octave