# IIR 濾波器(二階節串接) (`iir`)

> 用一串二階節對取樣訊號濾波。

![iir](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/img/iir.svg)

[元件參考](https://voltecx-web.nguyenvanqui291.workers.dev/zh/docs/reference/) · [English](https://voltecx-web.nguyenvanqui291.workers.dev/docs/reference/control/iir/)

**分類:** 控制 · **種類:** `{"block":"iir","kind":"control"}`

## 何時使用

用於由濾波器設計工具匯出的巴特沃斯、柴比雪夫或橢圓濾波器。需要線性相位時改用 FIR 濾波器。

## 接腳

| 接腳 | 訊號域 | 意義 |
|---|---|---|
| `in` | 訊號 | 要濾波的訊號，每隔 ts 取樣 |
| `out` | 訊號 | 濾波後的輸出，在兩次取樣之間保持 |

## 常用參數

- `ts`: Time between samples (預設值: 必填)
- `sections`: Filter sections, six numbers each (預設值: 必填)
- `gain`: Overall gain applied to the input (預設值: 1)

## 參數

| 鍵 | 單位 | 預設值 | 典型範圍 | 說明 |
|---|---|---|---|---|
| `ts` | s | 必填 |  | Time between samples |
| `offset` | s | 0 |  | Time of the first sample |
| `sections` | — | 必填 |  | Filter sections, six numbers each |
| `gain` | — | 1 |  | Overall gain applied to the input |
| `lo` | — | -1e30 |  | Lowest value the output can reach; the limited output is what the filter remembers |
| `hi` | — | 1e30 |  | Highest value the output can reach; the limited output is what the filter remembers |
| `y0` | — | 0 |  | Output at the start while the input is zero (needs a pole at z = 1) |

_參數說明在兩種語言中都是英文。_

## 模型

sections 每節放六個數 b0、b1、b2、a0、a1、a2，一節接一節，最多 64 節。每節是 (b0 + b1·z^-1 + b2·z^-2) / (a0 + a1·z^-1 + a2·z^-2)，a0 不可為 0。輸入先乘以 gain，再依序通過各節。只有 gain 與每個 b0 都不為 0 時才有直通項。

## 常見錯誤

- 每節的順序是分子在前、分母在後：b0、b1、b2、a0、a1、a2。兩半對調會得到不同的濾波器，而且不會有任何警告；清單長度不是 6 的倍數則會被拒絕。
- 各節必須針對方塊實際使用的 ts 設計。設計工具若把總增益另外給一個數，請填入 gain；增益若已包含在 b 係數內，請讓 gain 保持 1。

Problems 規則: `compile.error`

## 規格書與來源

ts 是資料的取樣時間 1/fs。各節與增益來自濾波器設計工具，依該取樣率下你的截止頻率、階數與濾波器類型，以二階節形式匯出。

## 範例

以指令 `file.openExample` 開啟範例，名稱為 `demo:iir`.

---
由 `cargo xtask reference` 依使用說明文字與參數規格產生，請勿手動編輯。
