C中的傅里叶变换 [英] Fourier transformation in C

查看:89
本文介绍了C中的傅里叶变换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include <stdio.h>
#include <math.h>
#include <stdlib.h>

void main()
{

    int func (double x[], int n);
    int N,i,t,n,m;
    double f;
    printf("input N\n");
    scanf(" %d",&N);
    printf("f=%lf\n",f);
    printf("t=%lf\n",t);

    double PI= 4.0*atan(1.0);

    for(i=1; i<=N; i+2);
    {
        for(t=0; t<=n; t++);
        {
        srand(time(NULL));
        double f = rand();

     x[t]=(4/PI)*((1/i)*sin(2*i*PI*f*t));
     x[t]>-10||x<10;
    }
    }


}





这是我的代码这样的任务 https://imagizer.imageshack.us/v2/1244x699q90/673/af9sg9.jpg [ ^ ]



你能告诉我第1部分我错在哪里吗?



在公式中,它会增加2,所以我应该怎么存储呢?

现在我有这样的东西







Here is My code to such a task https://imagizer.imageshack.us/v2/1244x699q90/673/af9sg9.jpg[^]

Could you tell me where am I wrong for Part 1?

It is in the formula that it icreases by 2, so how should I store it?
Now I have something like this


#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include "time.h"

int func(double x[], int n);
int main()
{

int func (double x[], int n);
int N,i,t,n,m;
double f,x[1000];
printf("input N\n");
scanf(" %d",&N);


double PI= 4.0*atan(1.0);

for(i=1; i<=N; i+2)
{
for(t=0; t<=n; t++)
{
srand(time(NULL));
double f = rand();


x[t]=(4/PI)*((1/i)*sin(2*i*PI*f*t));

if(x[t]>-10||x<10)
printf("%lf\n",x[t]);
}
}

return 0;
}





所以我认为我已经提出了第1部分解决方案,但我仍在计算第2部分/>
到目前为止我有这个,你能指出我错在哪里吗?





So I think I have come up with part 1 solution, but I am still figuring out part 2
I have this so far, can you point me where I am wrong?

#include <stdio.h>
#include <math.h>
#include "winbgi2.h"
#include "time.h"
#include <stdlib.h>

int main()
{	int N ;
printf("input N\n");
	scanf(" %d",&N);
	graphics(1000,200);
int n = 10000;
double f = 0.01;
double PI= 4.0*atan(1.0);
 
for(int t=0; t<=n; t++)
{
double y;
y=(4/PI)*sin(2*PI*f*t);
 int p;
 if (y>0)
 p=50;
 
 else
 p=70;
circle(t,p,1);
}
	wait();

	

	for(int i=1; i<=N; i+2)
	{
		for(int t=0; t<=n; t++)
		{
		
     double x;
	 x=(4/PI)*((1/i)*sin(2*i*PI*f*t));
	 circle(t,x,1);
		}
	}
return 0;
}

推荐答案

Quote:

你能告诉我第1部分我错在哪里吗?

Could you tell me where am I wrong for Part 1?

你的代码与第1部分无关。你应该绘制一个任意频率的方波。我在你的代码中看不到任何相关内容。看起来你试图通过拟议的傅立叶展开来近似方波。但是,您的代码没有正确实现这样的近似值。

Your code has nothing to do with Part 1. You should have drawn a square wave of arbitrary frequency. I see nothing of that in your code. It looks you are trying to approximate the square wave with the proposed Fourier expansion. However your code doesn't implement correctly such an approximation.


这篇关于C中的傅里叶变换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆