gaussmar.c
来自「This program reads iid zero-mean unit-va」· C语言 代码 · 共 38 行
C
38 行
#include <math.h>
#include <stdio.h>
#define PMODE 0644
float x[1048576] ;
/* This program reads iid zero-mean unit-variance Gaussian variates,
and converts them into first-order Gauss-Markov with correlation
coefficient of rho, and variance of 1. To run the program use:
markov <input file name> <N> <rho> <output file name>
Nader Moayeri ; 2/13/85 */
main(argc,argv)
int argc ;
char *argv[] ;
{ int i, n, fd ;
double a, rho ;
n = atoi(argv[2]) ;
rho = atof(argv[3]) ;
a = sqrt(1.-rho*rho) ;
if ( ( fd = open(argv[1],0) ) == -1 )
{ printf("Error in opening the input file.\n") ;
exit(1) ;
}
if ( ( i = read(fd,x,4*n) ) != (4*n) )
{ printf("Error in reading the training sequence.\n") ;
exit(1) ;
}
if (( fd = creat(argv[4],PMODE )) == -1)
{ printf("Error in creating the output file.\n") ;
exit(1) ;
}
for ( i = 1; i < n; ++i )
x[i] = rho*x[i-1] + a*x[i] ;
if (( i = write(fd,x,4*n) ) != (4*n) )
{ printf("Error in writing onto the output file.\n") ;
exit(1) ;
}
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?