How do I only get vectors out of the butter function?

1 回表示 (過去 30 日間)
Grace Wagstaffe
Grace Wagstaffe 2019 年 5 月 23 日
編集済み: Jan 2019 年 5 月 23 日
I am using the function butter as follows.
freq = 125;
rate = 300;
t = [0:0.1:4*pi]
s = sin(t);
[b,a] = butter(2,freq/(rate*2),'low');
dataIn = s;
dataOut = filter(b,a,dataIn);
When I look at b it is a 2x2 matrix, however to use the filter function it must be a vector.
I am using the R2017a.
I have also tried modifying the matlab example in browser and I get a vector
Where am I going wrong?
  1 件のコメント
Alex Mcaulley
Alex Mcaulley 2019 年 5 月 23 日
Following butter documentation a and b are always row vectors (also running your code).

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

回答 (2 件)

Jan
Jan 2019 年 5 月 23 日
I cannot confirm this. With standard Matlab functions, butter replies vectors. So check, if you use the official function:
which butter -all
  2 件のコメント
Grace Wagstaffe
Grace Wagstaffe 2019 年 5 月 23 日
I am using the butter function from
C:\Program Files\MATLAB\R2017a\toolbox\shared\controllib\graphics\+ctrluis\+toolstrip\+dataprocessing
Jan
Jan 2019 年 5 月 23 日
編集済み: Jan 2019 年 5 月 23 日
I'd expect this one:
C:\Program Files\MATLAB\R2017a\toolbox\signal\signal\butter.m
What does this reply:
which butter -all
?

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


Star Strider
Star Strider 2019 年 5 月 23 日
Your filter design has other problems. Your actual sampling frequency is:
Fs = 1/mean(diff(t));
or 10, and the Nyquist frequency (that you use to normalise your desired frequency) is half of that.
Your butter call should be:
[b,a] = butter(2,freq/(Fs/2),'low');
Note also that ‘freq’ must be less than ‘Fs/2’, so a passband frequency of 300 will fail.
It is also better to use filtfilt than filter to do the actual filtering.

カテゴリ

Help Center および File ExchangeDigital and Analog Filters についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by