Libfilth使用说明
winshton
2009年2月
(*本文大部分翻译自libfilth,还有一部分是个人使用实践
*时间水平均有限,翻译的不完整,尤其第二章可以忽略)
版本历史修改记录
版本 |
作者 |
日期 |
备注 |
V1.0 |
winshton |
2009-2-1 |
创建 |
-
目 录
2.8.2. fd_minphaseminimax() 16
2.16.30. mat_clinspace_pol() 47
-
概述
Libfilth 是一套设计、分析和应用数字和模拟滤波器的程序库。它包含一些基本的滤波器功能。Libfilth为滤波器的设计、分析和变换提供以下类型:
- 带有线性相位和最小二乘法的FIR滤波器。
- 大有复杂规范和最小二乘法的FIR滤波器。
- 使用线性编程提供线性相位和上下限设计的FIR滤波器。
- 使用Remes算法提供线性相位和上下限设计的FIR滤波器。
- 提供最小相位和最佳幅值的FIR滤波器。
- 提供复杂规范和上下限设计的FIR滤波器。
- 提供组延迟限制的FIR滤波器。
- 二次编程实现最优窗的FIR滤波器。
- 提供最小相位谱的FIR滤波器。
- 使用倒谱设计的FIR滤波器。
- 使用模拟滤波器设计的贝塞尔-汤姆逊,巴特沃斯,切比雪夫I型, II和椭圆函数滤波器。
- 模拟-模拟与模拟-数字滤波器的转换。
- 实现全通IIR滤波器。
- FIR 半带滤波器
- DFT的滤波器组和平行的DFT滤波器组的设计和实施。
- FIR、IIR和模拟滤波器的性能计算分析。
- 窗函数功能。
带有fir和iir前缀的文件完成FIR和IIR滤波器的设计和转换功能。Filtannalysis.c完成所有滤波器的分析功能,window.c和window.h完成窗函数的计算功能。
AIP的函数前缀使用如下约定:
- fd_ FIR Design
- fe_ FIR Execute
- fa_ FIR Analysis
- ft_ FIR Transform
- ff_ FIR Free (memory)
- id_ IIR Design
- ia_ IIR Analysis
- it_ IIR Transform
- wd_ Calculate window function
-
库文件分析
-
filth.h/filth.c
定义库中使用的所有全局数据类型和错误管理函数。
两个类型定义:
typedef double _ftype_t
设计函数中使用的双精度浮点指针类型。
typedef float _fshort_t
执行函数中使用的单精度浮点指针类型。
有两个函数:
-
quantize()
将输入值转换为小数表示法。
参数:
x Floating point value
n Number of bits [1,64]
nx Numeartor
dx Eponent for denominator [-128,128]
返回:
On success 0 is returned, -1 is returned on error and errno is set appropriately.
-
filter_strerror()
返回字符串描述的错误代码,拓展strerror()。
参数:
errnum 错误号
返回:
字符串描述的错误代码。
-
filter.h/filter.c
设计,实施,转化和分析不同类型的模拟和数字滤波器。这两个文件是滤波器的总纲,滤波器需要的所有类型定义和宏定义等基本资源都从这两个文件获得,而且滤波器的库接口头文件就是filter.h,所有相关的函数声明都在这里了。
其中包括若干数据结构定义、宏定义和类型定义。
此外在filter.c中包含三个基本的处理函数:
-
fir()
被pfir调用,内联函数。
C implementation of FIR filter
, *表示卷积。
本函数似乎是卷积运算函数,输入数组进行一次求积并累加,但这种计算又不像是卷据运算。
参数:
n
过滤阀数,where mod
w
过滤阀
x
输入信号必须是一个顺序索引的环形缓冲区
返回:
卷积结果。
-
pfir()
C implementation of parallel FIR filter
, *表示卷积。
本函数似乎是采集信号值的卷积运算,但看不太懂。
参数:
n
过滤阀数 where mod
d
滤波器数
xi
唤醒缓冲区当前索引
w
过滤阀 [k,n]
x
输入信号必须是一个顺序索引的环形缓冲区
y
输出缓冲区
s
输出缓冲步幅
返回:
输出缓冲y的指针。
-
updatepq()
内联函数。
添加数据到循环队列,用与并行FIR滤波器设计。
Add new data to circular queue designed to be used with a parallel FIR filter.
参数:
n
过滤阀数 where mod
d
滤波器数
xi
唤醒缓冲区当前索引
xq
环形缓冲n*2,k]
in
输入新数据*s]
s
输入冲步幅
返回:
Xq的新索引。
-
window.h/window.c
该文件提供计算窗函数。窗函数包括:Boxcar, Triang, Hanning, Hamming, Blackman, Flattop 和Kaiser.
-
wd_boxcar()
截断窗,又叫Rectangular窗,效果如同没有加窗一样,它的作用只是将信号截短。其谱泄露最大。该窗可以用来分析持续时间比窗短的信号。
Boxcar
参数:
n
窗长
w
窗参数缓冲区 [n]
-
wd_triang()
Triang a.k.a Bartlett
参数:
n
Window length
w
Buffer for window parameters [n]
-
wd_hanning()
Hanning
参数:
n
Window length
w
Buffer for window parameters [n]
-
wd_hamming()
Hamming
参数:
n
Window length
w
Buffer for window parameters [n]
-
wd_blackman()
Blackman
参数:
n
Window length
w
Buffer for window parameters [n]
-
wd_flattop()
Flattop
参数:
n
Window length
w
Buffer for window parameters [n]
-
wd_kaiser()
Kaiser
The beta parameter trades the rejection of the low pass filter against the transition width from passband to stop band. Larger Beta means a slower transition and greater stop band rejection. See Rabiner and Gold (Theory and Application of DSP) under Kaiser windows for more about Beta. The following table from Rabiner and Gold gives some feel for the effect of Beta:
All the passband ripple
and the stop-band ripple
is in dB, width of transition band
.
参数:
n
Window length
w
Buffer for window parameters [n]
b
Beta parameter for Kaiser window, Beta >= 1
-
filtanalysis.c
该文件函数功能用于分析模拟和数值滤波器的特点。
-
fa_ampfunc()
为对称型和反对称型1-4FIR滤波器计算振幅,该函数的速度比fa_response()快。
参数:
n
过滤阀数
w
滤波器数
k
频率点数
f
频率点 [0,0.5] [k]
a
得出的振幅 [k]
flags
类型标志, see filter.h
返回:
成功返回0 , -1返回的错误,and errno is set appropriately.
-
fa_response()
为任何实型滤波器计算响应(量值,功率,相位,群延迟)。
Calculate filter responses (magnitude, power, phase, group delay) for any type of real fir filter.
参数:
n
过滤阀数
w
滤波器数
k
频率点数
f
频率点矢量 [0,0.5] [k]
r
返回结果 [k]
flags
类型标志, see filter.h
返回:
成功返回0 , -1返回的错误,and errno is set appropriately.
-
fa_cerror()
为所有实型FIR滤波器计算权重误差。
Calculate the weighted error function
for any type of real FIR filter.
参数:
n
过滤阀数
w
滤波器数
k
频率点数
f
频率点矢量 [0,0.5] [k]
hd
理想的频率响应 used during the design of w [k]
v
权重 vector (if no weighting desired set to NULL) [k]
r
返回结果 [k]
flags
类型标志, see filter.h
返回:
成功返回0 , -1返回的错误,and errno is set appropriately.
-
ia_response()
IIR滤波器分析函数,为由b/a给出的实型IIR滤波器计算频率响应、量值、功率、相位响应或群延迟。
Analysis function for IIR filters, calculates frequency response, magnitude, power, phase response or group delay for the real IIR filter given by b/a.
参数:
n
滤波器多项式分子数
b
滤波器多项式分子数组[n]
m
滤波器多项式分母数