1

I have to go through a large array (86 464 resulted from reading a audio file ) with a kiss_fft window of 2048 samples from 100 to 100 and to put each of the results (a 2048 array) as columns in a matrix. The goal is to get a image of a voice from the audio file .

I did this in Matlab:

for i=0:len-1
window = x((i*100+1):(i*100)+2048);    % getting 2048 samples from array
real = abs(fft(window));               % appling FFT and take the real part of it
matrix(1:2048,i+1) = real;             % adding result to matrix

It is working very well but i have problems with my C implementation:

`kiss_fft_cpx* copycpx(double *mat, int nframe)
{
int i;
kiss_fft_cpx *mat2;
mat2=(kiss_fft_cpx*)KISS_FFT_MALLOC(sizeof(kiss_fft_cpx)*nframe);
    kiss_fft_scalar zero;
    memset(&zero,0,sizeof(zero) );
for(i=0; i<nframe ; i++)
{
    mat2[i].r = mat[i];
    mat2[i].i = zero;
}
return mat2;
}
`

int main(void)

{
int i;
double adoublevariable ;
int dimens = 0;
char line[100];
double window[2048];
int f;
int j;
int len =0;
FILE *vector;

vector=fopen("1.txt", "r");
while( fgets( line,100,vector ))
        dimens++;
fclose(vector);



double v[dimens];
vector=fopen("1.txt", "r");
i=0;
while( fgets( line,100,vector ) )
    if( 1==sscanf(line,"%lf",&adoublevariable) )
        {
            v[i] = adoublevariable;
            i++;
        }
    else
        puts("not a double variable");
fclose(vector);



len = int(floor((dimens-2048)/100+1));
double **mat;
mat = (double **)malloc(2048*sizeof(double*));
for(j=0;j<2048;j++)
    mat[j]=(double*)malloc(len*sizeof(double));

kiss_fft_cfg   cfg = kiss_fft_alloc( 2048 ,0 ,0,0 );
kiss_fft_cpx   out_cpx[2048],*cpx_buf;

for(i=0 ;i < len ;i++)
{
    for(j=0 ;j < 2048 ;j++)
        {
            window[j]=v[i*100+j];
        }


    cpx_buf = copycpx(window,2048);
    kiss_fft( cfg ,cpx_buf, out_cpx );
    free(cfg);

    for(f=0;f<2048;f++)
        {
           mat[f][i] = fabs(out_cpx[f].r);
        }

    free(cfg);
}
system("pause");
return 0;
}

I have no errors or warnings but it crushes.

0 Answers0