PDA

View Full Version : "Filter" command with SOS and GAIN!!!


archie is embedded
02-05-2008, 11:02 AM
Greetings Folks,

Am working on a 4th order,low pass,elliptic filter
at the moment.The development work is with the help of C language and
using a VC++ compiler.I have made use of the cascaded
operation(cascading two second order filters), as direct
implementation was getting me into trouble with bit precision.The
DIRECT FORM 1 difference equation, I employed for each of the second
order sections.The filter coefficents and GAIN were obtained from the
fda tool of the matlab.I am faced with the following problems.

1.The formulae into which I pass the values read from .wav
file(SAMPLING RATE =8000Hz) seems to be giving the perfect expected
output for the cut off (0-150 Hz LPF).But for a cut off of (0-1000Hz)
and (0-2000Hz),the negative values seem to be missing.The values
obtained after calculation seem to have only a few negative values.Its
like the negative side of the plot has been totally masked which
should not happen.The plotting is also done in matlab with the help of
values obtained from my program.As said earlier the coefficents are
obtained from the FDA tool of the matlab.Could anyone know whats the
problem.Is it bugs in my C code??.

2. Also to check the above facts I would like to use the matlab.But
unfortunately I do not know how to use the """""filter """"" command
with the cascaded format.It only takes the one without the cascaded
format.I need to know how we can use a SOS matrix with a corresponding
GAIN in the filter function.I have used SOSFILT,but it does not take
the GAIN as one of its arguments.Only takes the SOS along with the
input signal.The reason I ask this is because with the values obtained
from this exercise,(if correct with proper negative values),I could
cross check these values with those obtained from my program.

I humbly request you smart folks to help me out with
this dilemma.

Murali.

mboigner
02-05-2008, 04:12 PM
1. I think there is a error in your C code, but I am no visionary so I hav
no clue where your problem is. Maybe you have some truncation, but as yo
are programming in C (with floating point I guess) that should not be th
problem.
An other idea: depending to your implementation of the BQ structure yo
have to negate teh MATLAB coefficients a_1 and a_2 for your own produce
filter.
That means have a look to a row of your SOS matrix:
[b0 b1 b2 1 a1 a2]
Try to use b0 to b2 with the sign which MATLAB gives you and a1 and a
with a negated sign.

2. Use
[b,a] = sos2tf(SOS, prod(G));
as MATLAB command. Then you can use the filter function with:
[y,zf] = filter(b,a,X,zi)
zi are start values of your filter, zf is the final state of your filter
but I think you should check the help.

Hope that helps,
Fine regards,
Markus

www.two-pi.com

bharat pathak
02-05-2008, 04:15 PM
1. Send the coefficients across. The ones which are generated by
matlab.

2. Since you are doing it in software, there is good enough chances
that sign inversion would have happened while implementation.

For example: matlab would give something like

h(z) = [b0 + b1z^-1 + b2z^-2]/[1 + a1z-1 + a2z-2];

so this is frequency domain representation.

but when you are actually implementing in s/w you will be using
difference equation

y(n) = b0x(n)+b1x(n-1)+b2x(n-2) -a1x(n-1) -a2x(n-2);

so as a quick chek try the sign inversion of both a1 and a2
coefficient in s/w and check.

3. The gain values obtained will be for individual stages. So
multiply the gain value with the b0, b1 and b2 of that stage.

y1 = filter([k*b0 k*b1 k*b2], [1 a1 a2], xin);

similarly obtain y2, y3 ...

Regards
Bharat Pathak

Arithos Designs
~dsp Simplified
www.arithos.com