
快速傅立叶变换
李喜付
(东北农业大学 工程学院)
班级 机化0802
姓名 李喜付
学号 A07070244
指导教师 范永存
快速傅立叶变换
摘要
实现二维快速傅立叶变换,这是第一次通过读程序流程图来设计程序,同时也将借此实例学习C语言实现矩阵的基本操作、复数的基本操作,复习前面所学过的动态内存分配、文件操作、结构指针的函数调用等内容。
关键词 C语言程序设计 傅立叶变换 C语言论文
程序流程图
本程序将对二维数组进行正、反快速快速傅立叶变换。
#include #include #include #define PI 3.1415926 Struct COMPLEX { Float re; Float im; } cplx , * hfield , * s , * r , * w ; Int n , m ; Int ln , lm ; Void initiate ( ) ; Void dfft () ; Void rdfft () ; Void showresult () ; Void fft( int l , int k ) ; Void reverse ( int t , int k ) ; Void w ( int l); Int loop ( int l ); Void conjugate ( ) ; Void add (struct complex * x , struct complex * y , struct complex * z ) ; Void sub (struct complex * x , struct complex * y , struct complex * z ) ; Void mul (struct complex * x , struct complex * y , struct complex * z ) ; Struct complex *hread (int j , int j ); Void hwrite ( int i ,int j ,struct complex x ) ; Void main ( ) ; { Initiate ( ) ; Printf ( "\\n 原始数据:\\n") ; Showresult ( ) ; Getchar ( ) ; Dfft ( ) ; Printf ("\\n快速傅立叶变换后的结果:\\n"); Showresult ( ) ; Getchar ( ); Rdfft ( ) ; Printf ( "\\n快速傅立叶你变换后的结果:\\n"); Showresult ( ); Getchar ( ) ; Free ( hfield ); } Void initiate ( ) File * df ; df = fopen ("data.txt" ,"r" ) ; Fscanf ( df , "%5d", & n ) ; Fscanf ( df ,"%5d", & m ) ; If ( ( ln = loop ( n ) )== -1 ) { Printf ( " 列数不是2的整数次幂 " ) ; Exit ( 1 ) ; } If ( ( lm = loop ( m ) ) == -1 ) { Printf ( " 行数不是2的整数次幂 " ) ; Exit ( 1 ) ; } Hfield = ( struct complex * ) malloc ( n * m sizeof ( cplx )) ; If ( fread ( hfield , sizeof ( cplx ) , m * n ,df ) != ( unsigned ) ( m * n ) ) { If ( feof ( df) ) printf (" premature end of file " ) ; Else printf ( " file read error " ) ; } Fclose ( df ) ; } Void dfft ( ) { Int i , j ; Int l , k ; l = n; k = ln ; w = ( struct complex * ) calloc ( l , sizeof ( cplx ) ) ; r = ( struct complex * ) calloc ( l , sizeof ( cplx ) ) ; s = ( struct complex * ) calloc ( l , sizeof ( cplx ) ) ; W ( l ) ; For ( i = 0 ; j < m ; j++ ) For ( j = 0 ; j < n ; j++ ) ; } Free ( R) ; Free ( S) ; Free ( W) ; L = m ; K = lm; w = ( struct complex * ) calloc ( l , sizeof ( cplx ) ) ; r = ( struct complex * ) calloc ( l , sizeof ( cplx ) ) ; s = ( struct complex * ) calloc ( l , sizeof ( cplx ) ) ; W ( 1 ) ; For ( i = 0 ; i < n ; i++ ) For ( j = 0 ; j < m ; j++ ) { S [ j ] .re = hread ( j . i ) re S [ j ] .re = hread ( j . i ) im } Fft ( l , k ) ; For ( j = 0; j < m ; j++ ) ; } Free ( R ) ; Free ( S ) ; Free ( W ) ; } Void rdft ( ) { Conjugate ( ) ; Dfft ( ) ; Conjugate () ; } Void showresult () { Int i , j ; For ( i = 0 ; i < n ; j++ ) { Printf ( "\\n第%d行\\n ", i ) For ( j = 0 ; j < n ; j++ ) { If ( j % 4 == 0 ) print (" \\n") ; Printf ( " ( %5.2f ,%5.2fi )" , hread ( i , j ) , hread ( i , j ) ; } } 本实例实现了矩阵、复数及复数矩阵的基本操作,并复习了前面所学过的文件操作、动态内存分配操作等知识点。 参考文献 [1]C语言精彩编程 温海 张友 中国水利水电出版社 [2]贾宇然,应建华,倪春波,等.一种低功耗时钟芯片的设计[J].华中科技大学学报:自然科学版,2003,31(7):25-27 任务要求: 1.C语言程序要求结合本专业应用 2.要有完整的设计任务过程和分析 3.必要的图标说明 4.参考文献 格式:1.题目居中三号宋体 其余五号宋体. 全文3000字左右 单倍行距
