src/interleaver.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 /*
00021   Interleavers 
00022   Copyright (C) 2005 Herve Jegou, Vivien Chappelier
00023 */
00024 
00025 #include <it/interleaver.h>
00026 
00027 
00028 Vec Vec_new_interleave_block (Vec v, size_t width)
00029 {
00030   size_t c, j, b = 0;
00031   size_t el_size = Vec_element_size (v);
00032   Vec  w = __Vec_new (el_size, Vec_length (v));
00033 
00034   for (c = 0; c < width; c++)
00035     for (j = c; j < Vec_length (v); j += width) {
00036       memcpy ((byte *) w + b * el_size, (byte *) v + j * el_size, el_size);
00037       b++;
00038     }
00039 
00040   return w;
00041 }
00042 
00043 
00044 Vec Vec_new_deinterleave_block (Vec v, size_t width)
00045 {
00046   size_t c, j, b = 0;
00047   size_t el_size = Vec_element_size (v);
00048   Vec  w = __Vec_new (el_size, Vec_length (v));
00049 
00050   for (c = 0; c < width; c++)
00051     for (j = c; j < Vec_length (v); j += width) {
00052       memcpy ((byte *) w + j * el_size, (byte *) v + b * el_size, el_size);
00053       b++;
00054     }
00055 
00056   return w;
00057 }
00058 
00059 
00060 vec vec_new_interleave_block (vec v, size_t width)
00061 {
00062   size_t c, j, b = 0;
00063   vec  w = vec_new (vec_length (v));
00064 
00065   for (c = 0; c < width; c++)
00066     for (j = c; j < vec_length (v); j += width)
00067       w[b++] = v[j];
00068 
00069   return w;
00070 }
00071 
00072 
00073 vec vec_new_deinterleave_block (vec w, size_t width)
00074 {
00075   size_t c, j, b = 0;
00076   vec  v = vec_new (vec_length (w));
00077 
00078   for (c = 0; c < width; c++)
00079     for (j = c; j < vec_length (w); j += width)
00080       v[j] = w[b++];
00081 
00082   return v;
00083 }
00084 
00085 
00086 ivec ivec_new_interleave_block (ivec v, size_t width)
00087 {
00088   size_t c, j, b = 0;
00089   ivec w = ivec_new (ivec_length (v));
00090 
00091   for (c = 0; c < width; c++)
00092     for (j = c; j < ivec_length (v); j += width)
00093       w[b++] = v[j];
00094 
00095   return w;
00096 }
00097 
00098 
00099 ivec ivec_new_deinterleave_block (ivec w, size_t width)
00100 {
00101   size_t c, j, b = 0;
00102   ivec v = ivec_new (ivec_length (w));
00103 
00104   for (c = 0; c < width; c++)
00105     for (j = c; j < ivec_length (w); j += width)
00106       v[j] = w[b++];
00107 
00108   return v;
00109 }
00110 
00111 
00112 bvec bvec_new_interleave_block (bvec v, size_t width)
00113 {
00114   size_t c, j, b = 0;
00115   bvec w = bvec_new (bvec_length (v));
00116 
00117   for (c = 0; c < width; c++)
00118     for (j = c; j < bvec_length (v); j += width)
00119       w[b++] = v[j];
00120 
00121   return w;
00122 }
00123 
00124 
00125 bvec bvec_new_deinterleave_block (bvec w, size_t width)
00126 {
00127   size_t c, j, b = 0;
00128   bvec v = bvec_new (bvec_length (w));
00129 
00130   for (c = 0; c < width; c++)
00131     for (j = c; j < bvec_length (w); j += width)
00132       v[j] = w[b++];
00133 
00134   return v;
00135 }
00136 
00137 
00138 Vec __Vec_interleave_block (Vec v, size_t width)
00139 {
00140   Vec  w = Vec_new_interleave_block (v, width);
00141   Vec_delete (v);
00142   return w;
00143 }
00144 
00145 
00146 vec __vec_interleave_block (vec v, size_t width)
00147 {
00148   vec  w = vec_new_interleave_block (v, width);
00149   vec_delete (v);
00150   return w;
00151 }
00152 
00153 
00154 ivec __ivec_interleave_block (ivec v, size_t width)
00155 {
00156   ivec w = ivec_new_interleave_block (v, width);
00157   ivec_delete (v);
00158   return w;
00159 }
00160 
00161 
00162 bvec __bvec_interleave_block (bvec v, size_t width)
00163 {
00164   bvec w = bvec_new_interleave_block (v, width);
00165   bvec_delete (v);
00166   return w;
00167 }
00168 
00169 
00170 Vec __Vec_deinterleave_block (Vec v, size_t width)
00171 {
00172   Vec  w = Vec_new_deinterleave_block (v, width);
00173   Vec_delete (v);
00174   return w;
00175 }
00176 
00177 
00178 vec __vec_deinterleave_block (vec v, size_t width)
00179 {
00180   vec  w = vec_new_deinterleave_block (v, width);
00181   vec_delete (v);
00182   return w;
00183 }
00184 
00185 
00186 ivec __ivec_deinterleave_block (ivec v, size_t width)
00187 {
00188   ivec w = ivec_new_deinterleave_block (v, width);
00189   ivec_delete (v);
00190   return w;
00191 }
00192 
00193 
00194 bvec __bvec_deinterleave_block (bvec v, size_t width)
00195 {
00196   bvec w = bvec_new_deinterleave_block (v, width);
00197   bvec_delete (v);
00198   return w;
00199 }
00200 
00201 
00202 /*------------------------------------------------------------------*/
00203 /* Matrix interleaver (compatible with the block vector interleaver)*/
00204 
00205 Mat __Mat_new_interleave_block (Mat m, size_t width)
00206 {
00207   size_t c, j, b = 0;
00208   size_t el_size = Mat_element_size (m);
00209   Mat  w = __Mat_new (el_size, Mat_height (m), Mat_width (m));
00210 
00211   for (c = 0; c < width; c++)
00212     for (j = c; j < Mat_height (m); j += width)
00213       Vec_copy (w[b++], m[j]);
00214 
00215   return w;
00216 }
00217 
00218 
00219 Mat __Mat_new_deinterleave_block (Mat m, size_t width)
00220 {
00221   size_t c, j, b = 0;
00222   size_t el_size = Mat_element_size (m);
00223   Mat  w = __Mat_new (el_size, Mat_height (m), Mat_width (m));
00224 
00225   for (c = 0; c < width; c++)
00226     for (j = c; j < Mat_height (m); j += width)
00227       Vec_copy (w[j], m[b++]);
00228 
00229   return w;
00230 }
00231 
00232 
00233 mat mat_new_interleave_block (mat m, size_t width)
00234 {
00235   return ((mat) Mat_new_interleave_block ((Mat) m, width));
00236 }
00237 
00238 
00239 mat mat_new_deinterleave_block (mat w, size_t width)
00240 {
00241   return ((mat) Mat_new_deinterleave_block ((Mat) w, width));
00242 }
00243 
00244 
00245 imat imat_new_interleave_block (imat m, size_t width)
00246 {
00247   return ((imat) Mat_new_interleave_block ((Mat) m, width));
00248 }
00249 
00250 
00251 imat imat_new_deinterleave_block (imat w, size_t width)
00252 {
00253   return ((imat) Mat_new_deinterleave_block ((Mat) w, width));
00254 }
00255 
00256 
00257 bmat bmat_new_interleave_block (bmat m, size_t width)
00258 {
00259   return ((bmat) Mat_new_interleave_block ((Mat) m, width));
00260 }
00261 
00262 
00263 bmat bmat_new_deinterleave_block (bmat w, size_t width)
00264 {
00265   return ((bmat) Mat_new_deinterleave_block ((Mat) w, width));
00266 }
00267 
00268 
00269 Mat __Mat_interleave_block (Mat m, size_t width)
00270 {
00271   Mat  w = Mat_new_interleave_block (m, width);
00272   Mat_copy (m, w);
00273   Mat_delete (w);
00274   return m;
00275 }
00276 
00277 
00278 mat mat_interleave_block (mat m, size_t width)
00279 {
00280   mat  w = mat_new_interleave_block (m, width);
00281   mat_copy (m, w);
00282   mat_delete (w);
00283   return m;
00284 }
00285 
00286 
00287 imat imat_interleave_block (imat m, size_t width)
00288 {
00289   imat w = imat_new_interleave_block (m, width);
00290   imat_copy (m, w);
00291   imat_delete (w);
00292   return m;
00293 }
00294 
00295 
00296 bmat bmat_interleave_block (bmat m, size_t width)
00297 {
00298   bmat w = bmat_new_interleave_block (m, width);
00299   bmat_copy (m, w);
00300   bmat_delete (w);
00301   return m;
00302 }
00303 
00304 
00305 Mat __Mat_deinterleave_block (Mat m, size_t width)
00306 {
00307   Mat  w = Mat_new_deinterleave_block (m, width);
00308   Mat_copy (m, w);
00309   Mat_delete (w);
00310   return m;
00311 }
00312 
00313 
00314 mat mat_deinterleave_block (mat m, size_t width)
00315 {
00316   mat  w = mat_new_deinterleave_block (m, width);
00317   mat_copy (m, w);
00318   mat_delete (w);
00319   return m;
00320 }
00321 
00322 
00323 imat imat_deinterleave_block (imat m, size_t width)
00324 {
00325   imat w = imat_new_deinterleave_block (m, width);
00326   imat_copy (m, w);
00327   imat_delete (w);
00328   return m;
00329 }
00330 
00331 
00332 bmat bmat_deinterleave_block (bmat m, size_t width)
00333 {
00334   bmat w = bmat_new_deinterleave_block (m, width);
00335   bmat_copy (m, w);
00336   bmat_delete (w);
00337   return m;
00338 }

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