Help with matlab Butterworth filter with signal processing
Hello everyone,
I am currently using Matlab 2020 to run semg signals the matlab’s simulink to process the signal. I am on the last step and need to add a Butterworth filter I am running into error messages that I do not know how to fix. This is for live signal processing aswell. I will attach the code below and the error messages that I am recieving I would highly apperciate it if someone could fix the code and explain what they did. I am still learning how to code in Matlab. Thank you in advance
function y = fcn(u, fs)
persistent Hd;
persistent filter_initialized;
if isempty(filter_initialized)
filter_order = 5;
low_cutoff = 20;
high_cutoff = 500;
Wn = [low_cutoff high_cutoff] / (fs / 2);
[b, a] = butter(filter_order, Wn, ‘bandpass’);
[sos,g] = butter2sos(b,a);
g = sqrt(prod(Wn));
Hd = dsp.BiquadFilter(‘SOSMatrix’, sos, ‘ScaleValues’, g);
filter_initalized = true;
end
y = step(Hd, u);
end
function [sos, g] = butter2sos(b,a)
end
errors that I am getting below:
Output argument ‘sos’ is not assigned on some execution paths. Function ‘MATLAB Function1’ (#36.473.476), line 25, column 11: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function ‘MATLAB Function1’ (#36.284.309), line 17, column 1: "[sos,g] = butter2sos(b,a)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘sos’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.285.288), line 17, column 2: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘g’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.289.290), line 17, column 6: "g" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘sos’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.372.375), line 20, column 36: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Persistent variable ‘Hd’ must be assigned before it is used. The only exception is a check using ‘isempty(Hd)’ that can be performed prior to assignment. Function ‘MATLAB Function1’ (#36.450.452), line 23, column 12: "Hd" Launch diagnostic report.Hello everyone,
I am currently using Matlab 2020 to run semg signals the matlab’s simulink to process the signal. I am on the last step and need to add a Butterworth filter I am running into error messages that I do not know how to fix. This is for live signal processing aswell. I will attach the code below and the error messages that I am recieving I would highly apperciate it if someone could fix the code and explain what they did. I am still learning how to code in Matlab. Thank you in advance
function y = fcn(u, fs)
persistent Hd;
persistent filter_initialized;
if isempty(filter_initialized)
filter_order = 5;
low_cutoff = 20;
high_cutoff = 500;
Wn = [low_cutoff high_cutoff] / (fs / 2);
[b, a] = butter(filter_order, Wn, ‘bandpass’);
[sos,g] = butter2sos(b,a);
g = sqrt(prod(Wn));
Hd = dsp.BiquadFilter(‘SOSMatrix’, sos, ‘ScaleValues’, g);
filter_initalized = true;
end
y = step(Hd, u);
end
function [sos, g] = butter2sos(b,a)
end
errors that I am getting below:
Output argument ‘sos’ is not assigned on some execution paths. Function ‘MATLAB Function1’ (#36.473.476), line 25, column 11: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function ‘MATLAB Function1’ (#36.284.309), line 17, column 1: "[sos,g] = butter2sos(b,a)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘sos’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.285.288), line 17, column 2: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘g’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.289.290), line 17, column 6: "g" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘sos’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.372.375), line 20, column 36: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Persistent variable ‘Hd’ must be assigned before it is used. The only exception is a check using ‘isempty(Hd)’ that can be performed prior to assignment. Function ‘MATLAB Function1’ (#36.450.452), line 23, column 12: "Hd" Launch diagnostic report. Hello everyone,
I am currently using Matlab 2020 to run semg signals the matlab’s simulink to process the signal. I am on the last step and need to add a Butterworth filter I am running into error messages that I do not know how to fix. This is for live signal processing aswell. I will attach the code below and the error messages that I am recieving I would highly apperciate it if someone could fix the code and explain what they did. I am still learning how to code in Matlab. Thank you in advance
function y = fcn(u, fs)
persistent Hd;
persistent filter_initialized;
if isempty(filter_initialized)
filter_order = 5;
low_cutoff = 20;
high_cutoff = 500;
Wn = [low_cutoff high_cutoff] / (fs / 2);
[b, a] = butter(filter_order, Wn, ‘bandpass’);
[sos,g] = butter2sos(b,a);
g = sqrt(prod(Wn));
Hd = dsp.BiquadFilter(‘SOSMatrix’, sos, ‘ScaleValues’, g);
filter_initalized = true;
end
y = step(Hd, u);
end
function [sos, g] = butter2sos(b,a)
end
errors that I am getting below:
Output argument ‘sos’ is not assigned on some execution paths. Function ‘MATLAB Function1’ (#36.473.476), line 25, column 11: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Function call failed. Function ‘MATLAB Function1’ (#36.284.309), line 17, column 1: "[sos,g] = butter2sos(b,a)" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘sos’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.285.288), line 17, column 2: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘g’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.289.290), line 17, column 6: "g" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Undefined function or variable ‘sos’. The first assignment to a local variable determines its class. Function ‘MATLAB Function1’ (#36.372.375), line 20, column 36: "sos" Launch diagnostic report.
Component:MATLAB Function | Category:Coder error
Persistent variable ‘Hd’ must be assigned before it is used. The only exception is a check using ‘isempty(Hd)’ that can be performed prior to assignment. Function ‘MATLAB Function1’ (#36.450.452), line 23, column 12: "Hd" Launch diagnostic report. butterworth filter, matlab, simulink MATLAB Answers — New Questions