结构体动态内存分配问题
代码及错误如下,,求大神指点一二,感激不尽,,楼主不是特别深入,很多东西理解不透彻,,主要是红字部分,,1,输入N,f,fs;
2,sig(i)=exp(j*2*PI*f/fs*i)=cos(-x)+sin(-x)*j;
3,s(w)=FFT(sig)=∑(i=0~N-1)[exp(-j*2PI*i*w/N)*sig(i)];
4,求取模|s(w)| w=(0~N-1);
5,求取|s(w)|的最大值及相应坐标index;
6,fest=index/N*fs;
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#define PI 3.1415926
struct complex
{
double Real;
double Imag;
};
struct complex Plus(struct complex, struct complex);
struct complex Multi(struct complex, struct complex);
double Modulo(struct complex);
void sig(struct complex, int, double, double);
void FFT(struct complex, int, struct complex);
void Msw(struct complex, int, double);
double Max(double, int, int);
int main()
{
int N,index=0;
double f, fs,Smax,fest;
printf("请输入需要测试的N,f,fs的值\n");
scanf_s("%d,%1f,%1f", &N, &f, &fs);
struct complex *p;
p = (struct complex*)malloc(512*sizeof(struct complex));
struct complex *p1;
p1 = (struct complex*)malloc(512*sizeof(struct complex));
double *pm;
pm = (double*)malloc(512*sizeof(double));
sig(p,N,f,fs);
FFT(p,N,p1);
Msw(p1,N,pm);
Smax=Max(pm,N,index);
fest = index / N*fs;
printf("|sw|的最大值是%f\n与之对应的坐标是%d\n与之对应的fest是%f\n",Smax,index,fest);
return 0;
}
void sig(struct complex *p, int N, double f, double fs)
{
int i;
for (i = 0; i < N; i++)
*(p + i) = { cos(2 * PI*f*i / fs), sin(2 * PI*f*i / fs) };
}
void FFT(struct complex *p, int N, struct complex *p1)
{
int i, w;
struct complex *p2;
p2 = (struct complex*)calloc(512 , sizeof(struct complex));
for (w = 0; w < N; w++)
{
for (i = 0; i <= N; i++)
{
*(p2 + i) = { cos(-2 * PI*w*i / N), sin(2 * PI*w*i / N) };
*(p1 + w) = Plus(Multi(*(p2 + i), *(p + i)), *(p1 + w));
}
}
}
void Msw(struct complex *p1, int N, double *pm)
{
int i;
for (i = 0; i < N; i++)
{
*(pm + i) = Modulo(*(p1 + i));
}
}
double Max(double *pm, int N, int index)
{
int i;
double Smax = *pm;
for (i = 1; i < N; i++)
{
if (*(pm + i)>Smax) Smax = *(pm + i);
index = i;
}
return Smax;
}
struct complex Plus(struct complex a, struct complex b)
{
struct complex answer;
answer.Real = a.Real + b.Real;
answer.Imag = a.Imag + b.Imag;
return answer;
}
struct complex Multi(struct complex a, struct complex b)
{
struct complex answer;
answer.Real = a.Real * b.Real - a.Imag * b.Imag;
answer.Imag = a.Imag * b.Real + b.Imag * a.Real;
return answer;
}
double Modulo(struct complex a)
{
double m;
m = sqrt(a.Real*a.Real + a.Imag*a.Imag);
return m;
}
1>c:\users\kylin\source\repos\c语言学习\discrete fourier transform\source.cpp(38): error C2664: “void sig(complex,int,double,double)”: 无法将参数 1 从“complex *”转换为“complex”
1> 无构造函数可以接受源类型,或构造函数重载决策不明确
1>c:\users\kylin\source\repos\c语言学习\discrete fourier transform\source.cpp(40): error C2664: “void FFT(complex,int,complex)”: 无法将参数 1 从“complex *”转换为“complex”
1> 无构造函数可以接受源类型,或构造函数重载决策不明确
1>c:\users\kylin\source\repos\c语言学习\discrete fourier transform\source.cpp(42): error C2664: “void Msw(complex,int,double)”: 无法将参数 1 从“complex *”转换为“complex”
1> 无构造函数可以接受源类型,或构造函数重载决策不明确
1>c:\users\kylin\source\repos\c语言学习\discrete fourier transform\source.cpp(44): error C2664: “double Max(double,int,int)”: 无法将参数 1 从“double *”转换为“double”
1> 没有使该转换得以执行的上下文
[ 本帖最后由 荆棘之心 于 2015-3-23 16:33 编辑 ]