如何在Matlab中更改信号范围的值 [英] How to change value of a signal's range in Matlab

查看:264
本文介绍了如何在Matlab中更改信号范围的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我们在Matlab中有这样的信号

Let's say that I have a signal in Matlab like this

x = cos(2*pi*10*t) + cos(2*pi*20*t) + cos(2*pi*50*t);

我想将20到30 Hz之间的值更改为0.我该怎么做?我的意思是,从x公式生成的那些值,我想稍作更改.

And I want to change the values between 20 and 30 hz into 0. How can I do that? I mean, those values generated from the x formula, I want to change them a little bit.

推荐答案

您可以通过在x上执行FFT,并将介于20和30 Hz之间的那些值设置为零,然后对先前的值应用FFT逆,来做到这一点.应该获得没有那些频率的信号.但是,您可能会丢失有价值的信息,或者信号可能看起来并不像您期望的那样.因此,我建议您使用带阻滤波器".带阻滤波器将接收截止频率(您要使用的极限频率)和其他一些参数.带阻滤波器基本上从信号中删除您指定的频率.好处是,它可以像以下操作一样轻松完成:

You can do it by performing FFT over x and setting to zero those values that are between 20 and 30 Hz then applying the FFT inverse on the previous values and you should get the signal without those frequencies. However, you may lose valuable information or the signal might just not look as you wish. Therefore, I recommend you to use a "Bandstop filter". The band stop filter will receive the cutoff frequencies (the limit frequencies you want to work with) and some other parameters. The bandstop filter basically removes from the signal the frequencies that you specify. And the good part is that it can be done as easy as doing what follows:

  1. 首先,您必须构建过滤器.为此,您需要指出可以根据需要定义的过滤器顺序.通常,第二订单效果​​很好.另外,您还必须注意采样率Fs.

  1. First you have to build the filter. To do so, you need to indicate the filter order which can be defined as you wish. Usually a second order works good. Also, you have to be aware of your sampling rate Fs.

d = designfilt('bandstopiir','FilterOrder',2,... 'HalfPowerFrequency1',20,'HalfPowerFrequency2',30,... 'SampleRate',Fs);

d = designfilt('bandstopiir','FilterOrder',2, ... 'HalfPowerFrequency1',20,'HalfPowerFrequency2',30, ... 'SampleRate',Fs);

现在,您只需要将滤波器应用于所需的信号即可.

Now you only need to apply the filter to your desired signal.

filtered_signal_x = filtfilt(d,x)

filtered_signal_x = filtfilt(d, x)

现在,filtered_signal_x不应具有您要删除的频率.通过使用带阻,您不必弄乱FFT和类似的东西,而且速度更快,因此我认为它是最佳选择.

Now, filtered_signal_x should not have the frequencies you wanted to delete. By using the bandstop you don't have to mess with the FFT and that kind of stuff and is a way faster so I think its the best option.

这篇关于如何在Matlab中更改信号范围的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆