0
$\begingroup$

I want to implement a high pass filter (order 4) in MATLAB using cascade form.

[b,a]=butter(4,0.0083,'high');% I am using butterworth filter
[sos,gain]=tf2sos(b,a);

Should I use [sos,gain] for implementing the same in cascade form or just [sos]. I read a post related to same and it says just [sos] should be used, however, I am not sure if that is the correct way. P.S. I want to create a MATLAB function for IIR filter(don't want to use the standard filter function in MATLAB) which would get the coefficients b,a & input.

$\endgroup$
  • $\begingroup$ Could you link to that post? $\endgroup$ – Matt L. Jan 7 '16 at 8:09
  • $\begingroup$ The highpass gain will be unity (for the normalized transfer function), so, in this case, it's safe to ignore the gain. $\endgroup$ – a concerned citizen Jan 2 '17 at 8:25
0
$\begingroup$

Both will work if used correctly

b,a]=butter(4,0.0083,'high');% I am using butterworth filter
% version 1
[sos,gain]=tf2sos(b,a);
y1 = gain*sosfilt(sos,x);
% version 2
[sos]=tf2sos(b,a);
y2 = sosfilt(sos,x);
% y1 will be equal to y2
$\endgroup$
0
$\begingroup$

EDIT: the answer below assumes that you called tf2sos with [sos,gain] as output arguments, and that your question is about the necessity of making use of the output variable gain. Thanks to Hilmar for pointing out this potential misunderstanding. His answer is about the equivalence of two different calls to tf2sos, one with two output arguments, and the other with just one. Note that when called with just one output argument, the resulting sos is different from the one obtained from a call with two output arguments.


If you want the correct scaling, in the sense that high frequency signals are passed through the filter with a gain of $1$, then you need to use the variable gain. If you don't use it you'll get the same high pass filter, but with some scaling. For fixed-point implementations, appropriate scaling is very important to minimize overflow and other quantization artefacts. For a Matlab implementation I wouldn't worry too much about scaling and just implement the filter with the correct gain.

$\endgroup$
  • $\begingroup$ Sorry, I think this answer is wrong. If you omit the second output argument the overall gain is integrated into the first second order section. If you use two arguments all section are scaled so that $b_1=1$. In either case you get the same result $\endgroup$ – Hilmar Jan 7 '16 at 13:43
  • $\begingroup$ @Hilmar: I understood the question differently. I thought the OP wanted to know if it's OK to just use sos (given that you have both, sos and gain). Re-reading the question, your interpretation probably makes more sense. However, in that case reading the Matlab documentation would have solved the problem for the OP ... $\endgroup$ – Matt L. Jan 7 '16 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.