
欢迎加入技术交流QQ群(2000人):电力电子技术与新能源 905724684
高可靠新能源行业顶尖自媒体
在这里有电力电子、新能源干货、行业发展趋势分析、最新产品介绍、众多技术达人与您分享经验,欢迎关注我们,搜索微信公众号:电力电子技术与新能源(Micro_Grid),与中国新能源行业共成长!

电力电子技术与新能源论坛
www.21micro-grid.com
小编推荐值得一看的书单
#ifndef ZX_FFT_H_
#define ZX_FFT_H_
typedef float FFT_TYPE;
#ifndef PI
#define PI (3.14159265f)
#endif
typedef struct complex_st {
FFT_TYPE real;
FFT_TYPE img;
} complex;
int fft(complex *x, int N);
int ifft(complex *x, int N);
void zx_fft(void);
#endif /* ZX_FFT_H_ */
/*
* zx_fft.c
*
* Implementation of Fast Fourier Transform(FFT)
* and reversal Fast Fourier Transform(IFFT)
*
* Created on: 2013-8-5
* Author: monkeyzx
*/
#include "zx_fft.h"
#include
#include
/*
* Bit Reverse
* === Input ===
* x : complex numbers
* n : nodes of FFT. @N should be power of 2, that is 2^(*)
* l : count by bit of binary format, @l=CEIL{log2(n)}
* === Output ===
* r : results after reversed.
* Note: I use a local variable @temp that result @r can be set
* to @x and won't overlap.
*/
static void BitReverse(complex *x, complex *r, int n, int l)
{
int i = 0;
int j = 0;
short stk = 0;
static complex *temp = 0;
temp = (complex *)malloc(sizeof(complex) * n);
if (!temp) {
return;
}
for(i=0; i
stk = 0;
j = 0;
do {
stk |= (i>>(j++)) & 0x01;
if(j
{
stk <<= 1;
}
}while(j
if(stk < n) { /* 满足倒位序输出 */
temp[stk] = x[i];
}
}
/* copy @temp to @r */
for (i=0; i
r[i] = temp[i];
}
free(temp);
}
/*
* FFT Algorithm
* === Inputs ===
* x : complex numbers
* N : nodes of FFT. @N should be power of 2, that is 2^(*)
* === Output ===
* the @x contains the result of FFT algorithm, so the original data
* in @x is destroyed, please store them before using FFT.
*/
int fft(complex *x, int N)
{
int i,j,l,ip;
static int M = 0;
static int le,le2;
static FFT_TYPE sR,sI,tR,tI,uR,uI;
M = (int)(log(N) / log(2));
/*
* bit reversal sorting
*/
BitReverse(x,x,N,M);
/*
* For Loops
*/
for (l=1; l<=M; l++) { /* loop for ceil{log2(N)} */
le = (int)pow(2,l);
le2 = (int)(le / 2);
uR = 1;
uI = 0;
sR = cos(PI / le2);
sI = -sin(PI / le2);
for (j=1; j<=le2; j++) { /* loop for each sub DFT */
//jm1 = j - 1;
for (i=j-1; i<=N-1; i+=le) { /* loop for each butterfly */
ip = i + le2;
tR = x[ip].real * uR - x[ip].img * uI;
tI = x[ip].real * uI + x[ip].img * uR;
x[ip].real = x[i].real - tR;
x[ip].img = x[i].img - tI;
x[i].real += tR;
x[i].img += tI;
} /* Next i */
tR = uR;
uR = tR * sR - uI * sI;
uI = tR * sI + uI *sR;
} /* Next j */
} /* Next l */
return 0;
}
/*
* Inverse FFT Algorithm
* === Inputs ===
* x : complex numbers
* N : nodes of FFT. @N should be power of 2, that is 2^(*)
* === Output ===
* the @x contains the result of FFT algorithm, so the original data
* in @x is destroyed, please store them before using FFT.
*/
int ifft(complex *x, int N)
{
int k = 0;
for (k=0; k<=N-1; k++) {
x[k].img = -x[k].img;
}
fft(x, N); /* using FFT */
for (k=0; k<=N-1; k++) {
x[k].real = x[k].real / N;
x[k].img = -x[k].img / N;
}
return 0;
}
/*
* Code below is an example of using FFT and IFFT.
*/
#define SAMPLE_NODES (128)
complex x[SAMPLE_NODES];
int INPUT[SAMPLE_NODES];
int OUTPUT[SAMPLE_NODES];
static void MakeInput()
{
int i;
for ( i=0;i
{
x[i].real = sin(PI*2*i/SAMPLE_NODES);
x[i].img = 0.0f;
INPUT[i]=sin(PI*2*i/SAMPLE_NODES)*1024;
}
}
static void MakeOutput()
{
int i;
for ( i=0;i
{
OUTPUT[i] = sqrt(x[i].real*x[i].real + x[i].img*x[i].img)*1024;
}
}
void zx_fft(void)
{
MakeInput();
fft(x,128);
MakeOutput();
ifft(x,128);
MakeOutput();
}
程序在TMS320C6713上实验,主函数中调用zx_fft()函数即可。
FFT的采样点数为128,输入信号的实数域为正弦信号,虚数域为0,数据精度定义FFT_TYPE为float类型,MakeInput和MakeOutput函数分别用于产生输入数据INPUT和输出数据OUTPUT的函数,便于使用CCS 的Graph功能绘制波形图。这里调试时使用CCS v5中的Tools -> Graph功能得到下面的波形图(怎么用自己琢磨,不会的使用CCS 的Help)。
输入波形

输入信号的频域幅值表示

FFT运算结果

对FFT运算结果逆变换(IFFT)

如何检验运算结果是否正确呢?有几种方法:
(1)使用matlab验证,下面为相同情况的matlab图形验证代码
SAMPLE_NODES = 128;
i = 1:SAMPLE_NODES;
x = sin(pi*2*i / SAMPLE_NODES);
subplot(2,2,1); plot(x);title('Inputs');
axis([0 128 -1 1]);
y = fft(x, SAMPLE_NODES);
subplot(2,2,2); plot(abs(y));title('FFT');
axis([0 128 0 80]);
z = ifft(y, SAMPLE_NODES);
subplot(2,2,3); plot(abs(z));title('IFFT');
axis([0 128 0 1]);
说明:本文来源网络电力电子变流器;文中观点仅供分享交流,不代表本公众号立场,转载请注明出处,如涉及版权等问题,请您告知,我们将及时处理。
- END -
合作请联系
微信号(QQ号)1768359031
推荐阅读:点击标题阅读
太阳能微型逆变器
LLC的原理与应用
半桥LLC论述—0N
中兴电路基础培训
艾默生器件应力降额总规范
中兴设计规范与指南-PCB接地设计
原理图设计规范126条checklist
原理图设计规范checklist(2)
PCB设计Checklist
如何控制漏电流危害-光伏逆变器黑科技
多图拆机评测-打开机箱,看红色固德威“芯”
看完有收获?请分享给更多人
限于篇幅,已做删减,获取原文,加小编微信号(QQ号)1768359031,文章收集整理于网络,如有侵权,请联系小编删除
公告:
小编对电力电子技术与新能源及微电网的市场发展很看好,对其关键技术很感兴趣,如有技术问题,欢迎加小编微信号(QQ号)1768359031,共同讨论。另,本公众号也有微信群,需要邀请进群,如有需要,可加小编微信号,谢谢!
欢迎大家加入技术交流QQ群:电力电子技术与新能源 905724684
电力电子技术:光伏并网逆变器(PV建模,MPPT,并网控制,LCL滤波,孤岛效应),光伏离网,光伏储能,风电变流器(双馈、直驱),双向变流器PCS,新能源汽车,充电桩,车载电源,数字电源,双向DCDC(LLC,移相全桥,DAB),储能(锂电池、超级电容),低电压穿越(LVRT),高电压穿越,虚拟同步发电机,多智能体,电解水,燃料电池,能量管理系统(直流微网、交流微网)以及APF,SVG ,DVR,UPQC等谐波治理和无功补偿装置等。
PSCAD/MATLABsimulink/Saber/PSPICE/PSIM——软件仿真+DSP+(TI)TMS320F2812,F28335,F28377,(Microchip)dsPIC30F3011,FPGA,ARM,STM32F334——硬件实物。
欢迎技术人员加入,多多交流,共同进步!打广告可以,要么有创意,要么有红包,谢谢。。。。。
更多精彩点下方“阅读原文”!
快来“在看”一下吧!