DSPRelated.com
Forums

How to produce output file (.dat) using DSP

Started by bayu...@yahoo.com April 11, 2008
Hi!
I'm working on DMT simulation using TMS320C5416 as my final project. I have a problem on making output file. I build this small chunk of program using turbo C and I put it on 5416 "DSK CCStudio v3.1". I can show the output on CCStudio, but the output file always returns empty. The output file exists, but it's empty.
The program list is as the following:

----
#include
#include
#include
#include

#define B 4
#define C 16
#define S 64
#define L 16
#define noise 0.0001
#define sN 0
#define N 16
#define F 32

int (*bits);
FILE *fp;

void a2d()
{
int i,j,k,sisa,hasil,bil,(*p)[B];
float (*z),max,min,temp,qinterval,bagi,(*q),(*x),(*mutlak);

x=malloc (S * sizeof(float));
if(!(fp = fopen("handel.txt", "r")))
{
exit(EXIT_FAILURE);
}
else
{
for(i=0; i fscanf(fp,"%f", &x[i]);
}
fclose(fp);
z=malloc (S * sizeof(float));
mutlak=malloc (S * sizeof(float));
for(i=0;i {
if (x[i]<0)
mutlak[i]=(-1)*x[i];
else
mutlak[i]=x[i];
z[i]=mutlak[i]/(16-1);
}
max=z[0];
for(i=0;i {
if(z[i]>max)
max=z[i];
}
qinterval=2*max;
q=malloc (S * sizeof(float));
bits=malloc (B* S * sizeof(int));
if(B<=1)
{
for (i=0;i {
if (x[i]<=0)
bits[i]=0;
else
bits[i]=1;
}
}
else
{
min=x[0];
for(i=1;i {
if(x[i] min=x[i];
}
for(i=0;i {
temp=x[i]-min;
bagi=temp/qinterval;
if (bagi-abs(bagi) <0.5)
bagi=floor(bagi);
else
bagil(bagi);
q[i]gi*qinterval;
}
p=malloc (B*pow(2,B) * sizeof(int));
for (k=0;k {
bil=k;
for (i=B-1;i>=0;i--)
{
hasil=bil/2;
sisa=bil%2;
p[k][i]=sisa;
bil=hasil;
}
}
for (i=0;i for (k=0;k if (floor(q[i]/qinterval)==k)
for (j=0;j bits[B*i+j]=p[k][j];
}

if(!(fp = fopen("p.txt", "w")))
puts("error");
else
{
for(i=0; i {
fprintf(fp, "%d%d%d%d \n", p[i][0], p[i][1], p[i][2], p[i][3]);
printf("%d%d%d%d \n", p[i][0], p[i][1], p[i][2], p[i][3]);
}
fclose(fp);
}
free(p);
free(bits);
free(z);
free(q);
free(x);
free(mutlak);
}

main()
{
a2d();
}

--

It's working on turbo C and CCStudio, both result:

--------
0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111
--------

I suppose the problem maybe in include library or the 'fprintf' command, but it's just my guess. Cab anyone help me to make an unempty output file?

Thank You very much.

Bayu P.