Can zp2sos be used in an audio plugin?

조회 수: 1 (최근 30일)
Nathan Lively
Nathan Lively 2021년 5월 7일
답변: Nathan Lively 2021년 5월 11일
I'm getting this error:
Unable to perform assignment because dot indexing is not supported for
variables of this type.
Error in filterPlugin/reset (line 21)
p.sos = zp2sos(z,p,k);
Here's my plugin code. I'm trying to keep it super simple for testing.
classdef filterPlugin < audioPlugin
% Basic IIR Butterworth lowpass for testing
properties % Public interface
end
properties (Constant) % Define the plugin interface
PluginInterface = audioPluginInterface();
end
properties (Access = private) % Internal State
sos = zeros(1,6);
end
methods
function out = process(p, in)
[out] = sosfilt(p.sos,in);
end
function reset(p) % Initialize internal state
Fs = getSampleRate(p);
Fc = 1000; FcNormalized = Fc/(Fs/2);
[z,p,k] = butter(2,FcNormalized);
p.sos = zp2sos(z,p,k);
end
end
end
  댓글 수: 2
Nathan Lively
Nathan Lively 2021년 5월 7일
Here's the console.
Nathan Lively
Nathan Lively 2021년 5월 7일
And here's the original MATLAB code used to make the plugin.
Fs = 48000;
Fc = 1000;
FcNormalized = Fc/(Fs/2);
[z,p,k] = butter(2,FcNormalized);
sos = zp2sos(z,p,k);
% out = sosfilt(sos,y);
fvtool(sos)

댓글을 달려면 로그인하십시오.

채택된 답변

Nathan Lively
Nathan Lively 2021년 5월 11일
Go to Digital and Analog Filters — Functions section and filter it by C/C++ code generation and you will find that zp2sos is not supported.

추가 답변 (1개)

Asvin Kumar
Asvin Kumar 2021년 5월 10일
The reason this error occurs is because you're using p as the "this" input argument and then overwriting it by the output of the butter function which is a column vector of complex numbers. Hence why the assignment fails. Use a modified version of the reset function to workaround this error.
function reset(this) % Initialize internal state
Fs = getSampleRate(this);
Fc = 1000;
FcNormalized = Fc/(Fs/2);
[z,p,k] = butter(2,FcNormalized);
this.sos = zp2sos(z,p,k);
end
  댓글 수: 4
Asvin Kumar
Asvin Kumar 2021년 5월 11일
You can find details about functions that support code generation from the Signal Processing Toolbox here: Code Generation and GPU Support - MATLAB & Simulink (mathworks.com)
Nathan Lively
Nathan Lively 2021년 5월 11일
Thanks so much Asvin!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Audio Plugin Creation and Hosting에 대해 자세히 알아보기

태그

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by