Sunday, April 5, 2015

Re: [Discuss-gnuradio] \"make\" error while making detector (howto_detect_ff) block.

/* -*- c++ -*- */
/*
* Copyright 2015 <+YOU OR YOUR COMPANY+>.
*
* This 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.
*
* This software 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 this software; 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 <gnuradio/io_signature.h>
#include "howto_detect_ff_impl.h"
#include <stdio.h>
#include <gsl/gsl_matrix.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_linalg.h>

namespace gr {
namespace howto {

howto_detect_ff::sptr
howto_detect_ff::make(float pfa, int L, int samples)
{
return gnuradio::get_initial_sptr
(new howto_detect_ff_impl(pfa, L, samples));
}
float mem = 0; //Global Variable
/*
* The private constructor
*/
howto_detect_ff_impl::howto_detect_ff_impl(float pfa, int L, int samples)
: gr::block("howto_detect_ff",
gr::io_signature::make(1, 1, sizeof(float)),
gr::io_signature::make(1, 1, sizeof(float))),
d_pfa(pfa), d_L(L), d_samples(samples)
{}

/*
* Our virtual destructor.
*/
howto_detect_ff_impl::~howto_detect_ff_impl()
{
}


//------------functions---------------
/*This function gives the CDF value for the pfa in input*/
float TracyWidom (float p){
float pd, tw;
tw = 0.45;
pd = 1 - p;
if (pd >= 0.01 && pd <= 0.05){
tw = 18*(pd - (17/75)); printf("a - %f\n", tw);
}else if (pd >= 0.05 && pd <= 0.1){
tw = 8*(pd - (179/400)); printf("b - %f\n", tw);
}else if (pd >= 0.1 && pd <= 0.3){
tw = (87/20)*(pd - (643/870)); printf("c - %f\n", tw);
}else if (pd >= 0.3 && pd <= 0.5){
tw = (16/5)*(pd - (287/320)); printf("d - %f\n", tw);
}else if (pd >= 0.5 && pd <= 0.7){
tw = (17/5)*(pd - (297/340)); printf("e - %f\n", tw);
}else if (pd >= 0.7 && pd <= 0.9){
tw = (5.2)*(pd - (0.813)); printf("f - %f\n", tw);
}else if (pd >= 0.9 && pd <= 0.95){
tw = (53/5)*(pd - (909/1060)); printf("g - %f\n", tw);
}else if (pd >= 0.95 && pd <= 1){
tw = 26*(pd - (593/650)); printf("h - %f\n", tw);
}else{
printf ("wrong pfa value: it must be between 0 and 1\n");
printf ("the pfa value standard is 0.1\n");
tw = (53/5)*(0.9 - (909/1060));
}
return tw;
}

/*this function calculates the threshold for the test
the inputs are: ns = numbers of samples;
L = length of the correlation function;
pfa = probability of false alarm*/
float gamma (int ns, int L, float pfa){
float A, B, C, ratio1, ratio2, g;
A = sqrt(ns)+sqrt(L);
B = sqrt(ns)-sqrt(L);
C = ns*L;
ratio1 = pow(A,2)/pow(B,2);
ratio2 = 1+( pow(A,-0.667) / pow(C,0.167) )*pfa;
g = ratio1*ratio2;
return g;
}
/*This function makes the detection test*/
float test (float r, float t){
float decision;
if(r > -1){
if(r <= t){
decision = 0;
}else{
decision = 1;
}
}
return decision;}
//-------------end functions-----------
int
howto_detect_ff_impl::general_work (int noutput_items,
gr_vector_int &ninput_items,
gr_vector_const_void_star &input_items,
gr_vector_void_star &output_items)
{
const float *in = (const float *) input_items[0];
float *out = (float *) output_items[0];
float vett [d_samples];
int lenght = floor(d_samples / d_L) * d_L;
int p, j, k;
float thr, lmax, lmin, ratio, TW;
// char c[1];
gsl_matrix * hankel = gsl_matrix_alloc (lenght,d_L);
gsl_matrix * V = gsl_matrix_alloc (d_L,d_L);
gsl_vector * S = gsl_vector_alloc (d_L);
gsl_vector * temp = gsl_vector_alloc (d_L);
FILE *story;

k=0; ratio = -1;
gsl_matrix_set_zero (hankel);
TW = TracyWidom (d_pfa);
thr = gamma(lenght, d_L, TW);

for (int i = 0; i < noutput_items; i++){
vett[k]=in[i];
k++;

if (k >= lenght){
k = 0;
story = fopen("filestory.txt", "a");

for( p=0; p<lenght; p++ ){
for( j=0; j<d_L; j++ ){
gsl_matrix_set (hankel, p, j, vett[p+j]);
}

}
gsl_linalg_SV_decomp (hankel, V, S, temp);
lmax = gsl_vector_get(S, 0);
lmin = gsl_vector_get(S, (d_L -1));
ratio = lmax/lmin;
mem = test(ratio, thr);

fprintf(story, "%f - ratio=%f - soglia=%f\n ", mem, ratio, thr);
fclose(story);
}
out[i] = mem;
}
// Do <+signal processing+>
// Tell runtime system how many input items we consumed on
// each input stream.
consume_each (noutput_items);

// Tell runtime system how many output items we produced.
return noutput_items;
}

} /* namespace howto */
} /* namespace gr */

hey Marcus,
Now, I am able to import detect_ff block. But while running an example using that block, i am stuck with a runtime error

  File "/usr/local/lib/python2.7/dist-packages/howto/howto_swig.py", line 24, in swig_import_helper
    _mod = imp.load_module('_howto_swig', fp, pathname, description)
ImportError: /usr/local/lib/libgnuradio-howto.so: undefined symbol: gsl_matrix_alloc

>>> Done

Hence not able to generate flow graph. Screen shot of given example is attached.
Also i have attached .cc file of detect_ff block.
Would you please help me out with this error.
Thanks in advance,
Abhishek 

On Wed, Apr 1, 2015 at 1:44 PM, Marcus Müller <marcus.mueller@ettus.com> wrote:
Hi Abhishek,

that guide refers to a somewhat outdated API, so it doesn't apply to
your case (that guide refers to an architecture where there was no
separate _impl class).

Have you read the guided tutorials and their chapter on C++ blocks? It's
explaining how you can add functions to blocks.
I'd personally recommend just starting anew, sticking to the guided
tutorials; wherever you got your guidance from, it mixes things that
apply to different versions of GNU Radio, and debugging this is really
not worth it when you could as well just start with a clean slate and
learn things *right*.

Best regards,
Marcus
On 04/01/2015 06:28 AM, abhishek wrote:
> hey marcus,
> here error given is, could not insert function, but we can according
> to
> "http://gnuradio.org/redmine/projects/gnuradio/wiki/BlocksCodingGuide#Public-Header-Files".
> Even i am not able to get last and second last error of expected "("
> and "{", but in the code all brackets are up to the mark and used
> properly.
>
> abhishek@abhishek-Inspiron-N5110:~/gr-howto/build$ make
> Scanning dependencies of target gnuradio-howto
> [  5%] Building CXX object
> lib/CMakeFiles/gnuradio-howto.dir/howto_detect_ff_impl.cc.o
> In file included from
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc:27:0:
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.h:40:7: error:
> 'gr::howto::howto_detect_ff_impl::howto_detect_ff_impl(float, int,
> int)' cannot be overloaded
>        howto_detect_ff_impl(float pfa, int L, int samples);
>        ^
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.h:37:6: error: with
> 'gr::howto::howto_detect_ff_impl::howto_detect_ff_impl(float, int, int)'
>       howto_detect_ff_impl (float pfa, int L, int samples);
>       ^
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc:37:27: error:
> prototype for 'gr::howto::howto_detect_ff::sptr
> gr::howto::howto_detect_ff::make(float, int, int)' does not match any
> in class 'gr::howto::howto_detect_ff'
>      howto_detect_ff::sptr howto_detect_ff::make(float pfa, int L, int
> samples)
>                            ^
> In file included from
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.h:24:0,
>                  from
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc:27:
> /home/abhishek/gr-howto/include/howto/howto_detect_ff.h:49:19: error:
> candidate is: static gr::howto::howto_detect_ff::sptr
> gr::howto::howto_detect_ff::make()
>        static sptr make();
>                    ^
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc: In constructor
> 'gr::howto::howto_detect_ff_impl::howto_detect_ff_impl(float, int, int)':
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc:57:71: warning:
> extended initializer lists only available with -std=c++11 or
> -std=gnu++11 [enabled by default]
>                gr::io_signature::make (MIN_OUT, MAX_OUT, sizeof(float)),
> ^
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc:66:5: error:
> expected ')' before '(' token
>      (howto_detect_ff_impl()::~howto_detect_ff_impl())
>      ^
> /home/abhishek/gr-howto/lib/howto_detect_ff_impl.cc:187:1: error:
> expected '{' before '}' token
>  }   /* namespace howto */
>  ^
> make[2]: ***
> [lib/CMakeFiles/gnuradio-howto.dir/howto_detect_ff_impl.cc.o] Error 1
> make[1]: *** [lib/CMakeFiles/gnuradio-howto.dir/all] Error 2
> make: *** [all] Error 2
>
> Could you please help me out with all individual errors. Attachment of
> al the 3 files are provided.
> Thanks in advance,
> Abhishek.


No comments:

Post a Comment