Problem with gr_vector_float type

Hi all,

I’m having a problem trying to use gr_vector_float type.
I don’t have
any problem to work with streams, but when I try to create a block that
takes a
vector of float numbers on its input and produces a vector of float
numbers on
its output (N:N) I always receive this error:

ValueError: itemsize mismatch:
stream_to_vector(2):0 using 4096, xcor_ff(4):0 using 4

I understood this error
is caused by different vectors’ size, but I don’t understand what I did
wrong
in my code.

This is c++ source of my block (I’m trying to create a block that
compute the autocorrelation of its input vector):

############################################################################################################

/* -- c++ -- /
/

  • Copyright 2005 Free Software Foundation, Inc.

This file is part of GNU Radio
*

  • GNU Radio is free software; you can
    redistribute it and/or modify
  • it under the terms of the GNU General Public
    License as published by
  • the Free Software Foundation; either version 3, or
    (at your option)
  • any later version.
  • GNU Radio is distributed in the
    hope that it will be useful,
  • but WITHOUT ANY WARRANTY; without even the
    implied warranty of
  • MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
    See the
  • GNU General Public License for more details.
  • You should have
    received a copy of the GNU General Public License
  • along with GNU Radio; see
    the file COPYING. If not, write to
  • the Free Software Foundation, Inc., 51
    Franklin Street,
  • Boston, MA 02110-1301, USA.
    */

#ifdef HAVE_CONFIG_H

#include “config.h”
#endif

#include <howto_xcor_ff.h>
#include
<gr_io_signature.h>
#include <gri_fft.h>
#include <math.h>
#include

#include
#include
#include <string.h>
#include <gr_types.h>

howto_xcor_ff_sptr howto_make_xcor_ff (int fftsize)
{
return
howto_xcor_ff_sptr (new howto_xcor_ff (fftsize));
}

howto_xcor_ff::
howto_xcor_ff (int fftsize)
: gr_sync_block (“xcor_ff”,

gr_make_io_signature (1, 1, sizeof (float)),
gr_make_io_signature (1,
1, sizeof (float)))
{
d_fftsize = fftsize;
d_fwdfft = new gri_fft_real_fwd
(d_fftsize);
d_invfft = new gri_fft_real_rev(d_fftsize);

}

howto_xcor_ff::
~howto_xcor_ff ()
{
delete d_fwdfft;
delete d_invfft;
}

int
howto_xcor_ff::
work (int noutput_items,
gr_vector_const_void_star &input_items,

gr_vector_void_star &output_items)
{

const gr_vector_float *in = (const
gr_vector_float *) input_items[0];
gr_vector_float *out = (gr_vector_float *)
output_items[0];

unsigned int input_data_size = input_signature()-

sizeof_stream_item (0);
unsigned int output_data_size = output_signature()-
sizeof_stream_item (0);

int j,i=0;

while (i++ < noutput_items)
{

memcpy(d_fwdfft->get_inbuf(), in, input_data_size);

memcpy

(d_invfft->get_inbuf(), in, input_data_size);

d_fwdfft->execute();  //

compute fwd xform

float scale = 1.0 / d_fftsize;
for (j = 0; j <

d_fftsize; j++)
d_invfft->get_inbuf()[j] = d_invfft->get_outbuf()[j] *
scale;

d_invfft->execute();  // compute inv xform


for (j = 0; j <

d_fftsize; j++)
d_invfft->get_inbuf()[j] = d_fwdfft->get_outbuf()[j] *
d_invfft->get_outbuf()[j];

d_invfft->execute();  // compute inv xform


// copy result to output

memcpy(out, d_invfft->get_outbuf(),
output_data_size);

out += d_fftsize;
in += d_fftsize;
}
return
noutput_items;
}

######################################################################################################

I’m a beginner, so probably my code is full of errors.

Thank you for your
help.

Elettra

On Sun, Dec 13, 2009 at 12:32:17PM +0100, [email protected] wrote:

I understood this error
is caused by different vectors’ size, but I don’t understand what I did wrong
in my code.

This is c++ source of my block (I’m trying to create a block that
compute the autocorrelation of its input vector):

Your i/o signatures are incorrect. They specify that the size of an
item is sizeof(float), but you probably want something like
sizeof(float) * fft_size

Eric