examples/test_source/test_source.c

Go to the documentation of this file.
00001 /*
00002    libit - Library for basic source and channel coding functions
00003    Copyright (C) 2005-2005 Vivien Chappelier, Herve Jegou
00004 
00005    This library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Library General Public
00007    License as published by the Free Software Foundation; either
00008    version 2 of the License, or (at your option) any later version.
00009 
00010    This library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Library General Public License for more details.
00014 
00015    You should have received a copy of the GNU Library General Public
00016    License along with this library; if not, write to the Free
00017    Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00018 */
00019 
00020 /** @file test_source.c Test program for sources functions */
00021 
00022 #include <it/vec.h>
00023 #include <it/io.h>
00024 #include <it/random.h>
00025 #include <it/source.h>
00026 #include <it/source_func.h>
00027 
00028 int main ()
00029 {
00030   int  N = 10000;
00031   bvec B;
00032   vec  U;
00033   vec  pdf;
00034   ivec S;
00035   ivec H;
00036   vec  NH;
00037 
00038   /*  it_randomize(); */
00039 
00040   /* Binary source */
00041   B = source_binary (20, 0.3);
00042   it_printf ("B   = $b\n", B);
00043 
00044   /* Uniform source */
00045   U = source_uniform (20, -1, 2);
00046   it_printf ("U   = $v\n", U);
00047 
00048   /* Define Maxted and Robinson source */
00049   pdf = vec_new_string ("0.4 0.2 0.2 0.1 0.1");
00050 
00051   /* Generate a vector of N samples */
00052   S = source_memoryless (N, pdf);
00053 
00054   /* Process the histogram and the normalized histrograph of this realization */
00055   H = histogram (vec_length (pdf), S);
00056   NH = histogram_normalized (vec_length (pdf), S);
00057 
00058   /* Display the results */
00059   it_printf ("pdf = $v\nH   = $i\nNH  = $v\n", pdf, H, NH);
00060 
00061   vec_delete (pdf);
00062   vec_delete (NH);
00063   ivec_delete (S);
00064   ivec_delete (H);
00065   vec_delete (U);
00066   bvec_delete (B);
00067   return 0;
00068 }

Hosted by
Copyright (C) 2005-2006 Hervé Jégou
Vivien Chappelier
Francois Cayre
libit logo courtesy of Jonathan Delhumeau