83 lines
2.1 KiB
Markdown
83 lines
2.1 KiB
Markdown
|
---
|
|||
|
layout: post
|
|||
|
title: "使用 Octave 工具设计巴特沃斯滤波器"
|
|||
|
subtitle: ""
|
|||
|
description: "使用 Octave 工具设计巴特沃斯低通、高通和带阻滤波器。"
|
|||
|
excerpt: "使用 Octave 工具设计巴特沃斯低通、高通和带阻滤波器。"
|
|||
|
date: 2022-09-07 15:44:00
|
|||
|
author: "Rick Chan"
|
|||
|
tags: ["DSP", "Butterworth", "Lowpass", "Highpass", "Bandstop"]
|
|||
|
categories: ["Algorithm"]
|
|||
|
published: true
|
|||
|
---
|
|||
|
|
|||
|
- [1. 巴特沃斯低通滤波器](#1-巴特沃斯低通滤波器)
|
|||
|
- [2. 巴特沃斯带阻滤波器](#2-巴特沃斯带阻滤波器)
|
|||
|
- [3. 巴特沃斯高通滤波器](#3-巴特沃斯高通滤波器)
|
|||
|
- [4. 外部参考资料](#4-外部参考资料)
|
|||
|
|
|||
|
需要安装和加载 signal 包。
|
|||
|
|
|||
|
```m
|
|||
|
>> pkg install -forge signal
|
|||
|
>> pkg load signal
|
|||
|
```
|
|||
|
|
|||
|
## 1. 巴特沃斯低通滤波器
|
|||
|
|
|||
|
设计一个 6 阶低通滤波器,截至频率为 100Hz,采样频率为 1000Hz。
|
|||
|
|
|||
|
```m
|
|||
|
>> fc = 100;
|
|||
|
>> fs = 1000;
|
|||
|
>> [b,a] = butter(6,fc/(fs/2),'low');
|
|||
|
>> freqz(b,a,[],fs)
|
|||
|
|
|||
|
>> b
|
|||
|
b =
|
|||
|
0.070115 0.420692 1.051731 1.402308 1.051731 0.420692 0.070115
|
|||
|
|
|||
|
>> a
|
|||
|
a =
|
|||
|
1.0000e+00 1.1876e+00 1.3052e+00 6.7433e-01 2.6347e-01 5.1753e-02 5.0225e-03
|
|||
|
|
|||
|
dataIn = randn(1000,1);
|
|||
|
dataOut = filter(b,a,dataIn);
|
|||
|
figure(2)
|
|||
|
subplot(1, 2, 1);
|
|||
|
plot(dataIn);
|
|||
|
subplot(1, 2, 2);
|
|||
|
plot(dataOut);
|
|||
|
```
|
|||
|
|
|||
|
![幅频特性](img/使用_Octave_工具设计巴特沃斯滤波器/001.png)
|
|||
|
|
|||
|
![滤波结果](img/使用_Octave_工具设计巴特沃斯滤波器/002.png)
|
|||
|
|
|||
|
a、b 即为公式:
|
|||
|
|
|||
|
$$y(n)=\sum_{k=0}^{M}b(k)x(n-k)-\sum_{l=1}^{N}a(l)y(n-l)$$
|
|||
|
|
|||
|
中的系数。
|
|||
|
|
|||
|
a 只需要 6 个系数就可以,a(1) 是为了计算方便,其结果始终为 1.0,并表示为归一化的系数,在实际使用时不会用到 a(1)。
|
|||
|
|
|||
|
## 2. 巴特沃斯带阻滤波器
|
|||
|
|
|||
|
```m
|
|||
|
>> [b,a] = butter(3,[0.2 0.6],'stop');
|
|||
|
>> freqz(b,a)
|
|||
|
```
|
|||
|
|
|||
|
## 3. 巴特沃斯高通滤波器
|
|||
|
|
|||
|
```m
|
|||
|
>> [z,p,k] = butter(9,300/500,'high');
|
|||
|
>> sos = zp2sos(z,p,k);
|
|||
|
>> fvtool(sos,'Analysis','freq')
|
|||
|
```
|
|||
|
|
|||
|
## 4. 外部参考资料
|
|||
|
|
|||
|
1. [Butterworth filter design](https://ww2.mathworks.cn/help/signal/ref/butter.html#bucse3u-ftype)
|