# 使用 Goertzel 算法进行 DFT 估计

### 生成 DTMF 音调

```symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'}; [tones, Fs, f, lfg, hfg] = helperDTMFToneGenerator(symbol, false); helperDFTEstimationPlot1(tones, symbol, Fs, f);```

### 播放 DTMF 音调

```% To hear, uncomment these lines: % for i = [5 11 8 6 4 7 7 11 11 11] % p = audioplayer(tones(:,i),Fs,16); % play(p) % pause(0.5) % end```

### 用 Goertzel 算法估计 DTMF 音调

ITU 标准定义的 DTMF 信号的最短持续时间为 40 毫秒。因此，最多有 0.04×8000 = 320 个采样可供估计和检测。DTMF 解码器需要估计这些短信号中包含的频率。

```Nt = 205; original_f = [lfg(:);hfg(:)] % Original frequencies```
```original_f = 7×1 697 770 852 941 1209 1336 1477 ```
```k = round(original_f/Fs*Nt); % Indices of the DFT estim_f = round(k*Fs/Nt) % Frequencies at which the DFT is estimated```
```estim_f = 7×1 702 780 859 937 1210 1327 1483 ```

`tones = tones(1:205,:);`

```for toneChoice = 1:12 % Select tone tone = tones(:,toneChoice); % Estimate DFT using Goertzel ydft(:,toneChoice) = goertzel(tone,k+1); % Goertzel uses 1-based indexing end```

`helperDFTEstimationPlot2(ydft,symbol,f, estim_f);`