Код
#include <LPC21xx.H>
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#define PI 3.14159265358979323846
void BPF(float *x, float *y, int N, int I)
{
register float c,s,t1,t2,t3,t4,u1,u2,u3;
register int i,j,p,l,L,M,M1,K;
L=N;
M=N/2;
M1=N-1;
while(L>=2){
l=L/2; u1=1.; u2=0.; t1=PI/(float)l;
c=cos(t1); s=(-1)*I*sin(t1);
for(j=0; j<l;j++)
{
for(i=j;i<N;i+=L)
{
p=i+l;
t1=*(x+i)+*(x+p);
t2=*(y+i)+*(y+p);
t3=*(x+i)-*(x+p);
t4=*(y+i)-*(y+p);
*(x+p)=t3*u1-t4*u2;
*(y+p)=t4*u1+t3*u2;
*(x+i)=t1; *(y+i)=t2;
}
u3=u1*c-u2*s;
u2=u2*c+u1*s; u1=u3;
}
L/=2;
}
j=0;
for(i=0;i<M1;i++)
{
if(i>j)
{
t1=*(x+j); t2=*(y+j);
*(x+j)=*(x+i); *(y+j)=*(y+i);
*(x+i)=t1; *(y+i)=t2;
}
K=M;
while(j >=K)
{
j-=K;K/=2;
}
j+=K;
}
}
int main (void) {
IODIR1 = 0x00FF0000;
int j,N;
float *x,*y,A,Re,Im;
N=8;
x=(float*)calloc(N,sizeof(float));
y=(float*)calloc(N,sizeof(float));
/*x[0]=60; // здесь зависает
x[1]=65;
x[2]=21;
x[3]=-3;
x[4]=15;
x[5]=-45;
x[6]=-20;
x[7]=70; */
BPF(x,y,N,1);
for(j=0;j < N/2;j++)
{
Re=*(x+j);
Im=*(y+j);
A=2.*sqrt(Re*Re+Im*Im)/(float)N;
}
while (1) {
}
}
Программа зависает при попытке записи в x[0]. Если закомментировать, останавливается на строке *(x+p)=t3*u1-t4*u2;
Мне кажется проблема в ф-ии calloc(). Или еще в чем-то? Помогите, пожалуйста.