📄 cyclint.c
字号:
// ------------------------------------------------------------------------
// File: cyclint.c
// Date: April 5, 2002
// Description: Generate a CYCLIC interleaver. The output is an interleaver
// array in a file with name specified at command input line.
//
// NOTE: This is equivalent to a Ramsey/convolutional interleaver with
// delay D. (See text, p. 116)
//
// Example: N1=3 N2=5 D=2
//
// 0 3 6 9 12
// 1 4 7 10 13
// 2 5 8 11 14
//
// Delay:
// 0 3 6 9 12
// 10 13 1 4 7
// 5 8 11 14 2
//
// i 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14
// interleaver[i] 0 10 5 3 13 8 6 1 11 9 4 14 12 7 2
// ------------------------------------------------------------------------
// This program is complementary material for the book:
//
// R.H. Morelos-Zaragoza, The Art of Error Correcting Coding, Wiley, 2002.
//
// ISBN 0471 49581 6
//
// This and other programs are available at http://the-art-of-ecc.com
//
// You may use this program for academic and personal purposes only.
// If this program is used to perform simulations whose results are
// published in a journal or book, please refer to the book above.
//
// The use of this program in a commercial product requires explicit
// written permission from the author. The author is not responsible or
// liable for damage or loss that may be caused by the use of this program.
//
// Copyright (c) 2002. Robert H. Morelos-Zaragoza. All rights reserved.
// ------------------------------------------------------------------------
#include <stdio.h>
#include <math.h>
#include <float.h>
#include <limits.h>
#define NMAX 16384
#define NM2 512
main(int argc, char *argv[])
{
int interleaver[NMAX];
int array[NM2][NM2];
int temp[NMAX];
int i, j, position;
int N1, N2;
int N; // Interleaver length
int D; // Delay, see text p. 116
char name1[40];
FILE *fp1;
// Command line processing
if (argc != 5)
{
printf("Usage %s N1 N2 D INT_file\n", argv[0]);
exit(0);
}
sscanf(argv[1],"%d", &N1);
sscanf(argv[2],"%d", &N2);
sscanf(argv[3],"%d", &D);
sscanf(argv[4],"%s", name1);
N = N1*N2;
fp1 = fopen(name1,"w");
// Write columnwise
for (i=0; i<N; i++)
array[i%N1][i/N1] = i;
for (i=0; i<N1; i++) {
for (j=0; j<N2; j++)
printf("%3d ", array[i][j]);
printf("\n");
}
printf("\n");
for (i=0; i<N1; i++)
{
for (j=0; j<N2; j++)
temp[j] = array[i][j];
for (j=0; j<N2; j++)
array[i][(i*D+j)%N2] = temp[j];
}
for (i=0; i<N1; i++) {
for (j=0; j<N2; j++)
printf("%3d ", array[i][j]);
printf("\n");
}
printf("\n");
// Read off columnwise
for (i=0; i<N; i++)
{
position = array[i%N1][i/N1];
interleaver[i] = position;
}
for (i=0; i<N; i++)
{
fprintf(fp1, "%d\n", interleaver[i]);
printf("%5d -> %5d\n",i,interleaver[i]);
}
fclose(fp1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -