且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在Matlab中更改信号范围的值

更新时间:2023-02-27 09:10:53

您可以通过在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.