?? hello_led.c
字號:
#include "system.h"
#include "alt_types.h"
#include <math.h>
#define N 2048
struct compx
{ float real;
float imag;
} compx;
struct compx x[N]; /*輸入序列,變換核*/
struct compx W[N]={
#include"wreal.dat"
};
float hanning[2048]={
#include"hanning.dat"
};
float dis[2048];
int size_x=2048;
float PI=3.1416; /*圓周率*/
struct compx EE(struct compx b1,struct compx b2)
{
struct compx b3;
b3.real=b1.real*b2.real-b1.imag*b2.imag;
b3.imag=b1.real*b2.imag+b1.imag*b2.real;
return(b3);
}
void FFT(struct compx* xin,int n)
{
int f,m,LH,nm,k,i,j,L,p;
int le,B,ip;
struct compx t;
LH=n/2;
f=n;
m=11;
for(L=m;L>=1;L--) /*這里和時域的也有差別*/
{
le=(1<<L);
B=le/2; /*每一級碟形運算間隔的點數*/
for(j=0;j<=B-1;j++)
{
p=((1<<(m-L))*j);
for(i=j;i<=N-1;i=i+le)
{
ip=(i+B);
t=xin[i];
xin[i].real=xin[i].real+xin[ip].real;
xin[i].imag=xin[i].imag+xin[ip].imag;
xin[ip].real=xin[ip].real-t.real;
xin[ip].imag=xin[ip].imag-t.imag;
xin[ip]=EE(xin[ip],W[p]);
}
}
}
/*變址運算*/
nm=n-2;
j=n/2;
for(i=1;i<=nm;i++)
{
if(i<j){t=xin[j];xin[j]=xin[i];xin[i]=t;}
k=LH;
while(j>=k){j=j-k;k=k/2;}
j=j+k;
}
}
int main (void)
{
int i=0;
for(i=0;i<N;i++)
{
x[i].real=sin(2*PI*i/1500);
x[i].imag=0;
}
i=0;
for(i=0;i<2048;i++)
{
x[i].real=x[i].real*hanning[i];
}
i=0;
FFT(&x,N);
i=0;
for(i=0;i<1024;i++)
{
dis[i]=x[i].real*x[i].real+x[i].imag*x[i].imag;
}
i=0;
while(1);
return 0;
}
/******************************************************************************
* *
* License Agreement *
* *
* Copyright (c) 2004 Altera Corporation, San Jose, California, USA. *
* All rights reserved. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING *
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER *
* DEALINGS IN THE SOFTWARE. *
* *
* This agreement shall be governed in all respects by the laws of the State *
* of California and by the laws of the United States of America. *
* Altera does not recommend, suggest or require that this reference design *
* file be used in conjunction or combination with any other product. *
******************************************************************************/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -