Need help with butterworth function

I am trying to use the butterworth function and I can't seem to get it working. Here is my code:
clear,clc
load('DATA_01_TYPE01.mat')
A = sig;
x = A(2,1:1000)
t=1:1:1000;
subplot(3,1,1)
plot(t,x)
N=size(x,2);
noise=0.5*randn(1,N); %noise
[b a]=butter(2, [0.6 0.7]);
noise=filter(b,a,noise);
x_n=x+noise;
subplot(3,1,2)
plot(t,x_n)

回答 (1 件)

Star Strider
Star Strider 2018 年 10 月 26 日
編集済み: Star Strider 2018 年 10 月 26 日

0 投票

I assume ‘A’ or ‘x’ is the signal you want to filter. If so, you are not giving it to the filter function to use. You are only giving it your ‘noise’ vector, so that it what it is filtering.
Also the filtfilt (link) function is preferable to filter.

4 件のコメント

G
G 2018 年 10 月 26 日
yes I want filter x. So how would I do that?
Star Strider
Star Strider 2018 年 10 月 26 日
I would do it this way:
x_filt = filtfilt(b, a, x);
or:
x_filt = filtfilt(b, a, x+noise);
depending on what you want to do. Note that it is not possible to remove all broadband noise with a frequency-selective filter.
(This is not the best way to design or implement your filter. However, it will likely give you acceptable results.)
G
G 2018 年 10 月 26 日
Is this using the butterworth function though? That is what I am trying to do
Star Strider
Star Strider 2018 年 10 月 26 日
Yes.
It is using the coefficients for the filter you designed.

サインインしてコメントする。

タグ

質問済み:

G
G
2018 年 10 月 26 日

コメント済み:

2018 年 10 月 26 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by