在 Matlab 中设计简单的带通/带阻滤波器

发布于 2024-12-08 21:24:47 字数 224 浏览 1 评论 0原文

对于家庭作业,我必须在 Matlab 中设计一个简单的带通滤波器,滤除 250Hz 到 1000 Hz 之间的所有频率。到目前为止我做了什么: - 使用“enframe”函数创建半重叠窗口,每个窗口有 512 个样本。在 Windows 上我应用了 hann 窗函数。 - 在每个窗口上我应用一个 fft。之后,我用函数 ifft 重建原始信号,一切顺利。

但问题是我必须如何解释 fft 函数的结果以及如何滤除频带。

For a homework assignment I have to design a simple bandpass filter in Matlab that filters out everything between 250Hz and 1000 Hz. What I did so far:
- using the 'enframe' function to create half overlapping windows with 512 samples each. On the windows I apply the hann window function.
- On each window I apply an fft. After this I reconstruct the original signal with the function ifft, that all goes well.

But the problem is how I have to interpret the result of the fft function and how to filter out a frequency band.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

摇划花蜜的午后 2024-12-15 21:24:47

除非我弄错了,否则听起来您对此采取了错误的方法。

如果您的任务是通过操纵信号的 FFT 来专门操纵信号,那么请忽略我。否则..继续阅读。

FFT 通常用于分析频域中的信号。如果您开始摆弄 FFT 返回的复杂系数,那么您就会陷入复杂的数学情况。尤其是这种情况,因为您的截止频率不会很好地位于 FFT bin 频率上。另外,请记住,FFT 并不是您正在分析的信号的完美变换。由于扇形错误,并与您的 hann 窗口卷积。

所以..让我们将 FFT 留给分析,并构建一个滤波器。

如果您在课堂上进行带通设计,我会假设您了解他们的作用。 Matlab 中有许多函数可以为不同类型的滤波器生成系数,例如 butterkaiser cheby1。在 Matlab 中查找他们的帮助页面以加载更多信息。您插入到这些函数中的值将取决于您的滤波器规格,即您需要“X”dB 滚降和“Y”dB 通带纹波。您需要了解这些滤波器的工作原理,并了解其传递函数,以了解它们的滤波器顺序与您的规格有何关系。

获得系数后,只需通过 filter 函数运行它们即可(如果您不确定其工作原理,请再次检查帮助页面)。

强大的 JOS 在此处提供了有关带通滤波器设计的精彩演练。

另一个小问题..在你的问题中你提到你希望你的滤波器“过滤掉”250Hz 到 1000Hz 之间的所有内容。这有点模棱两可。如果您正在设计带通滤波器,您可能希望“通过”250Hz 到 1000Hz 之间的所有信号。如果您实际上想要“过滤掉”此范围内的所有内容,那么您需要一个带阻滤波器。

Unless I'm mistaken, it sounds like you're taking the wrong approach to this.

If your assignment is to manipulate a signal specifically by manipulating its FFT then ignore me. Otherwise.. read on.

The FFT is normally used to analyse a signal in the frequency domain. If you start fiddling with the complex coefficients that an FFT returns then you're getting into a complicated mathematical situation. This is particularly the case since your cut-off frequencies aren't going to lie nicely on FFT bin frequencies. Also, remember that the FFT is not a perfect transform of the signal you're analysing. It will always introduce artefacts of its own due to scalloping error, and convolution with your hann window.

So.. let's leave the FFT for analysis, and build a filter.

If you're doing band-pass design in your class I'm going to assume you understand what they do. There's a number of functions in Matlab to generate the coefficients for different types of filter i.e. butter, kaiser cheby1. Look up their help pages in Matlab for loads more info. The values you plug in to these functions will be dependent on your filter specification, i.e. you want "X"dB rolloff and "Y"dB passband ripple. You'll need some idea of the how these filters work, and knowledge of their transfer functions to understand how their filter order relates to your specification.

Once you have your coefficients, it's just a case of running them through the filter function (again.. check the help page if you're not sure how this works).

The mighty JOS has a great walkthrough of bandpass filter design here.

One other little niggle.. in your question you mentioned that you want your filter to "filter out" everything between 250Hz and 1000Hz. This is a bit ambiguous. If you're designing a bandpass filter you would want to "pass" everything between 250Hz and 1000Hz. If you do in fact want to "filter out" everything in this range you want a band-stop filter instead.

盛夏已如深秋| 2024-12-15 21:24:47

这完全取决于您使用的采样率。
如果您根据奈奎斯特-香农采样定理正确采样,那么您可以尝试使用 DFT

为了了解哪些频率与 dft 结果中的哪些样本相对应,我认为最好查看 逆变换。您可以将系数 k 与

 exp(i*2*pi*k/N*n)

欧拉公式 解释为余弦。因此每个系数都乘以特定频率的正弦。

祝你好运 ;)

It all depends on the sampling rate you use.
If you sample right according to the Nyquist-Shannon sampling theorem then you can try and interpret the samples of your fft using the definition of the DFT.

For understanding which frequencies correspond with which samples in the dft results, I think it's best to look at the inverse transformation. You multiply coefficient k with

 exp(i*2*pi*k/N*n)

which can be interpreted to be a cosine with Euler's Formula. So each coefficient gets multiplied by a sine of a certain frequency.

Good luck ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文