How can I use a filter in a parfor with the more numerically stable z,p,k?

1 回表示 (過去 30 日間)
Gordon
Gordon 2017 年 4 月 26 日
コメント済み: Gordon 2017 年 4 月 28 日
Hello,
I would like to use a filter in a parfor loop. Using [b,a] coefficients there is no problem. Because of a better stability I have to use the [z,p,k] coefficients. It perfectly works in a for loop. However, in a parfor loop the error massage "Not enough input arguments." appears. Does anyone know a workaround?
Here is a little example: Anything works but the last loop!
% Signal
x = sin(0:pi/1000:10*pi);
% Filter properties
N = 1;
fc = 1/(2*pi);
fs = 1000/pi;
Wn = fc/(fs/2);
ftype = 'low';
% Transfer Function design
[b,a] = butter(N,Wn,ftype);
% Zero-Pole-Gain design
[z,p,k] = butter(N,Wn,ftype);
[sos,g] = zp2sos(z,p,k);
hd = dfilt.df2tsos(sos, g);
%%Loops
for n=1:2
y = filter(b,a,x);
end
parfor n=1:2
y = filter(b,a,x);
end
for n=1:2
y = filter(hd, x);
end
parfor n=1:2
y = filter(hd, x);
end
  2 件のコメント
Jan
Jan 2017 年 4 月 26 日
Please post the complete error message.
Gordon
Gordon 2017 年 4 月 28 日
This is the complete error message ;)

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

採用された回答

Aniruddha Katre
Aniruddha Katre 2017 年 4 月 26 日
Modifying the parfor loop as follows seems to resolve the error. The filter object was causing the error to occur for some reason, but creating the filter object on each worker separately fixes it.
parfor n=1:2
hd = dfilt.df2tsos(sos, g);
y(n,:) = filter(hd, x);
end
  2 件のコメント
Edric Ellis
Edric Ellis 2017 年 4 月 27 日
There's an underlying problem sending objects of type dfilt.df2tsos into parfor loops. An additional workaround you can use to avoid re-creating the object on each iteration is:
hdc = parallel.pool.Constant(hd);
parfor ...
... = filter(hdc.Value, ...);
end
Gordon
Gordon 2017 年 4 月 28 日
Both perfectly works! Thank you very much for the very quick reply!

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

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by