資源簡介
由于matlab程序將各信號處理函數封裝,無法看到原始代碼,這里是其中resample函數的C語言實現源碼,可實現任意整數倍上采及下采

代碼片段和文件信息
/*
FIR濾波器的I?和?II兩種類型
調用格式:Firls_LP(double?*?h_firls?int?Lendouble?Fint?M);
len表示濾波器的階數;
M?=?[1?1?0?0];
F給表示頻率范圍,格式為4*1的數組;
輸出一個len+1的數組,由h返回;
*/
#?include?“resample_definition.h“
#?include?
#?include?
#?include?
#?include?
//#?define?PI?3.1415926
//#?define?EPSILON?0.000001
//double?*?Firls_LP(int?double?*?int?*);???//計算FIR濾波器抽頭系數
//bool?Constant_Diff(double?*);?????????????//判斷頻率范圍是否合理
//double?Sinc(double);??????????????????????//辛格函數
//double?*?Divide_Matrix(double?**?double?*?int);??//矩陣左除
//void?Inverse_Matrix(double?**?int);??????//求逆矩陣
//int?main(void)
//{
// double?*?h;?????????????????????????//h數組存放firls輸出
// int?Len;????????????????????????????//根據調用函數設置,測試時給定,可變
// int?M[4]?=?{1?1?0?0};????????????//低通濾波器幅度范圍,恒定
// double?F[4]?=?{0?0.2?0.4?1}; ????//根據調用函數設置,測試時給定,可變
// printf(“請輸入濾波器階數:“);
// scanf(“%d“?&Len);
// h?=?(double?*)malloc(sizeof(double)?*?(Len?+?1));
// h?=?Firls_LP(Len?F?M); ???????????//len代表濾波器階數,F為頻率范圍,M為幅度范圍??????????
//
// return?0;
//}
void?Firls_LP(double?*h_firlsint?N?double?*?F?int?*?M)
{
int?i?j?fullband?constant_weight?Nodd?L?need_matrix?s;
constant_weight?=?1;???????????????//類型I和II濾波器,constant_weight值恒定,由w矩陣計算而來
int?W[2]?=?{1?1};????????????????//類型I和II濾波器,w矩陣值恒定
double?*?m?*?k_Odd?*k_Even?*?b_Even?*?b_Odd?*?bNew?*?a;
double?**?I1?**?I2?**G;?????????
double?b0?m0?b1;
N?=?N?+?1;????????????????????????//N階濾波器具有N+1個系數
Nodd?=?N%2;???????????????????????//判斷序列長度奇偶性
L?=?(N-1)/2;??????????????????????//中心對稱點
m?=?(double?*)malloc(sizeof(double)?*?(L+1));
for?(i=0;?i<4;?i++)
F[i]?/=?2; ??????????????//頻率歸一化
if?(Constant_Diff(F))?????????????//判斷頻率是否恒定
fullband?=?1;
else
fullband?=?0; ??????????????????????
if?(!Nodd)
{
//序列長為奇數
for?(i=0;?i<=L;?i++)
m[i]?=?i?+?0.5;
}
else???//序列長為偶數
{
for?(i=0;?i<=L;?i++)
m[i]?=?i;
}
need_matrix?=?(!fullband)||(!constant_weight);????//參數
if?(need_matrix)??
{
//定義(L+1)*(L+1)大小的方陣,其值等于m方陣+m方陣的轉置矩陣
I1?=?(double?**)malloc(sizeof(double*)?*?(L+1));
for?(i=0;?i<=L;?i++)
*(I1?+?i)?=?(double?*)malloc(sizeof(double)?*?(L+1));
for(i=0;?i<=L;?i++)
for?(j=0;?j<=L;?j++)
I1[i][j]?=?m[i]?+?m[j];
//定義(L+1)*(L+1)大小的方陣,其值等于m方陣-m方陣的轉置矩陣
I2?=?(double?**)malloc(sizeof(double*)?*?(L+1));
for?(i=0;?i<=L;?i++)
*(I2?+?i)?=?(double?*)malloc(sizeof(double)?*?(L+1));
for(i=0;?i<=L;?i++)
for?(j=0;?j<=L;?j++)
I2[i][j]?=?m[i]?-?m[j];
//定義(L+1)*(L+1)大小的零矩陣
G?=?(double?**)malloc(sizeof(double*)?*?(L+1));
for?(i=0;?i<=L;?i++)
*(G?+?i)?=?(double?*)malloc(sizeof(double)?*?(L+1));
for(i=0;?i<=L;?i++)
for?(j=0;?j<=L;?j++)
G[i][j]?=?0;
}
k_Even?=?(double?*)malloc(sizeof(double)?*?L);???????//偶階次的k序列
k_Odd?=?(double?*)malloc(sizeof(double)?*?(L+1));????//奇階次序列的k序列
bNew?=?(double?*)malloc(sizeof(double)?*?(L+1));
?屬性????????????大小?????日期????時間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2018-10-23?23:54??resample_1029\
?????目錄???????????0??2018-10-23?23:49??resample_1029\Debug\
?????文件???????47104??2018-10-23?23:49??resample_1029\Debug\resample_1029.exe
?????文件??????357500??2018-10-23?23:49??resample_1029\Debug\resample_1029.ilk
?????文件??????543744??2018-10-23?23:49??resample_1029\Debug\resample_1029.pdb
?????目錄???????????0??2018-10-23?23:50??resample_1029\resample_1029\
?????文件????24268800??2018-10-23?23:54??resample_1029\resample_1029.sdf
?????文件?????????906??2018-10-23?23:49??resample_1029\resample_1029.sln
?????文件?????1038774??2018-10-23?23:50??resample_1029\resample_1029\data_i.txt
?????文件?????1039121??2018-10-23?23:50??resample_1029\resample_1029\data_r.txt
?????目錄???????????0??2018-10-23?23:50??resample_1029\resample_1029\Debug\
?????文件????????2638??2018-10-23?23:50??resample_1029\resample_1029\Debug\cl.command.1.tlog
?????文件???????18648??2018-10-23?23:50??resample_1029\resample_1029\Debug\CL.read.1.tlog
?????文件????????2382??2018-10-23?23:50??resample_1029\resample_1029\Debug\CL.write.1.tlog
?????文件???????20694??2018-10-23?23:50??resample_1029\resample_1029\Debug\firls.obj
?????文件???????12095??2018-10-23?23:50??resample_1029\resample_1029\Debug\kaiser1.obj
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件???????????2??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件????????1986??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件????????3406??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件????????1132??2018-10-23?23:50??resample_1029\resample_1029\Debug\li
?????文件?????????420??2018-10-23?23:50??resample_1029\resample_1029\Debug\mt.command.1.tlog
?????文件?????????410??2018-10-23?23:50??resample_1029\resample_1029\Debug\mt.read.1.tlog
............此處省略22個文件信息
- 上一篇:地震數據SEGY格式的讀寫 C++
- 下一篇:用C++實現簡易的文本編輯器
評論
共有 條評論