[英]How to create 1/3-Octave-Band Filters in MatLAB/Octave
I have to design 1/3-Octave-Band filters in MatLAB (or alternatively in Octave). 我必须在MatLAB(或八度音阶)中设计1/3八度频带滤波器。 I've read this doc article and I've tried using the
fdesign.octave
- design
duo, but this method allows creation of band filters for mid-band frequencies starting at around 25Hz. 我已经阅读了这篇文档文章,并尝试使用
fdesign.octave
- design
二重奏,但是这种方法允许为25Hz左右的中频带频率创建频带滤波器。 I need to create filters for frequency range from 0.5Hz to 100Hz. 我需要创建频率范围从0.5Hz到100Hz的滤波器。
I know how to calculate midband frequencies (fm) for those filters and corresponding upper and lower frequency bounds, so I've tried creating them myself using butter
or cheby1
functions or using the fdatool
. 我知道如何计算这些滤波器的中频带频率(fm)以及相应的上限和下限频率,因此我尝试使用
butter
或cheby1
函数或使用fdatool
自己创建它们。 While filters created/displayed in fdatool
look good, when I use them to filter chirp
signal using the filer
function, I can see something like in the image below: 虽然在
fdatool
创建/显示的过滤器看起来不错,但是当我使用它们使用filer
函数过滤chirp
信号时,可以在下图中看到类似的图像:
Top plot is chirp
filtered with my custom filter, bottom plot shows the same chirp
filtered with the filter of the same order, type and mid-band frequency, but created using fdesign.octave
- design
duo. 上图是
chirp
与我的自定义过滤器过滤,下图显示了相同的chirp
以相同的顺序,类型和中频段频率的过滤器过滤,但使用创建fdesign.octave
- design
二人。 I don't know how to get rid of that signal gain at the beginning and this one is actually one of the lowest signal gain, which shows for 100hZ mid-band frequency. 我不知道如何从一开始就消除信号增益,而这实际上是最低的信号增益之一,在100hZ中频带频率下显示。 The lower the mid-band frequency is, the worse my filter is (actually, below 2 or 3 Hz my filters filter out everything).
中频带频率越低,我的滤波器越差(实际上,在2或3 Hz以下,我的滤波器会滤除所有内容)。
Hers is the code, that I am using to build my filter: 她的代码是我用来构建过滤器的代码:
Wn = [Fl(i) Fh(i)] / (Fs/2);
[ z, p, k ] = butter( N, Wn, 'bandpass' );
% [z,p,k] = cheby1( N, Rp, Wn, 'bandpass' );
[ sos, g ]=zp2sos( z, p, k );
f = dfilt.df2sos( sos, g );
Can anyone help me with designing proper 1/3-Octave-Band filters for that frequency range (0.5÷100)Hz? 有人可以帮助我设计适合该频率范围(0.5÷100)Hz的1/3八度频带滤波器吗?
EDIT: I've found another way to do what I want using the standardized fdesign.octave
method. 编辑:我已经找到了另一种方法来使用标准化的
fdesign.octave
方法来做我想做的fdesign.octave
。 Read my answer below. 请在下面阅读我的答案。
Just do it manually by working out the centre frequencies you want and then calculating upper and lower bounds. 只需手动计算出所需的中心频率,然后计算上下限即可。 The following demo uses simple
butterworth
filters, but you can swap that out with any prototype you like. 以下演示使用简单的
butterworth
过滤器,但您可以将其替换为任何所需的原型。
fs = 250;
bw = 1/3;
fMin = 0.5;
fMax = 100;
octs = log2(fMax/fMin);
bmax = ceil(octs/bw);
fc = fMin*2.^( (0:bmax) * bw ); % centre frequencies
fl = fc*2^(-bw/2); % lower cutoffs
fu = fc*2^(+bw/2); % upper cutoffs
numBands = length(fc);
b = cell(numBands,1);
a = cell(numBands,1);
figure
for nn = 1:length(fc)
[b{nn},a{nn}] = butter(2, [fl(nn) fu(nn)]/(fs/2), 'bandpass');
[h,f]=freqz(b{nn},a{nn},1024,fs);
hold on;
plot(f, 20*log10(abs(h)) );
end
set(gca, 'XScale', 'log')
ylim([-50 0])
Which gives . 这使 。 .
。 .
。
You can then use tf2sos
if you want stability from higher order filters as a cascade of 2nd order sections. 然后,如果您希望将高阶滤波器作为第二阶节的级联,则可以使用
tf2sos
。
You can use the following code to test a chirp to see that nothing weird is going on . 您可以使用以下代码来测试线性调频脉冲,以查看没有奇怪的事情发生。 .
。
dt=1/fs;
t = 0:dt:2000; % 2 seconds
fo = 0.5; f1 = 120;
x = chirp(t,fo,numel(t)*dt,f1,'logarithmic')';
y = zeros(numel(x), length(fc));
for nn = 1:length(fc)
y(:,nn) = filter(b{nn},a{nn},x);
end
figure; plot(y)
Although I've accepted learnvst's answer (as it helped me a bit at the beginning), I've later found other way to create correct filters, that would comply with ANSI S1.11 / IEC 61260 and it's actually quite easy. 尽管我接受了learningvst的回答(起初对我有所帮助),但后来我发现了创建符合ANSI S1.11 / IEC 61260的正确过滤器的其他方法,并且实际上很容易。 My idea is based on a specific property of digital filters, ie they can be used for signals of different sampling rate than they were designed for, which will result in changing the actual passband range of a filter.
我的想法基于数字滤波器的特定属性,即它们可用于与设计时不同的采样率的信号,这将导致更改滤波器的实际通带范围。
I've used the standardized fdesign.octave
method but with different parameter values. 我使用了标准化的
fdesign.octave
方法,但参数值不同。 For mid-band frequencies of (25÷100)Hz range I did everything the normal way, but for the range starting around 2.5Hz (up to 24Hz) I have specified 10 times bigger sampling rate and 10 times bigger mid-band frequency. 对于(25÷100)Hz范围的中频带频率,我以正常方式进行了所有操作,但是对于从2.5Hz(最高24Hz)开始的范围,我指定了大10倍的采样率和10倍的中频带频率。 For frequencies of 0.5Hz and up (<2.5Hz) I've multiplied those values by 100. As a result, I've obtained valid filters for (0.5÷100)Hz range for actual sampling rate of my source signals.
对于0.5Hz及以上(<2.5Hz)的频率,我将这些值乘以100。结果,对于我的源信号的实际采样率,我获得了有效范围为(0.5÷100)Hz的滤波器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.