Reply
 
Thread Tools Display Modes
  #1   Report Post  
Scott Soderlund
 
Posts: n/a
Default Understanding Implementation of High Pass Filter

Hi,
I wrote the other day asking about Noise Gates and got some really
good replies which greatly helped in my understanding of how they
work. Thanks Guys!!!

Today, I'm asking about a High Pass Filter. Again, I just started
working on a project where the computer captures samples of someone's
speech. Each of these samples is run through a 50 Hz High Pass Filter
to improve the quality of the sample. I've done a lot of reading
about High Pass filters and think I understand pretty well how they
work. What I don't understand though is a couple of the variables in
the program where the filter is actually implemented. I'm hoping
someone out there knows java and can help tell me what they mean.
Code follows and then my questions...

public class HighPass50
{
static int NZEROS = 5;
static int NPOLES = 5;
static double GAIN = 1.095980088e+00;

double xv[] = new double[NZEROS+1];
double yv[] = new double[NPOLES+1];

public HighPass50() {}

public void process(short data[])
{
for (int i=0; i data.length; ++i)
{
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = data[i] / GAIN;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (xv[0] + xv[2]) - 2 * xv[1] + ( -0.9479259375 *
yv[0]) + ( 1.9469976496 * yv[1]);
data[i] = (short)yv[2];
}
}
}


Looking at the method above, I don't understand the meaning of the
'GAIN' variable (and more specifically the number it is set to). Is
this likely the cutoff frequency? Also, in the next to the last line
of the method, where yv[2] = ..., there are two numbers in this line
that I have no idea what they mean. The number "-0.9479259375" and
the number "1.9469976496". My guess is that the number
"-0.9479259375" is the lowest frequency possible (zero Hz) and that
"1.9469976496" is the highest frequency possible. This would make
sense if the GAIN variable was the cutoff frequency. Again, that is
my best guess! Can someone help with my understanding???

Thanks in advance,

Scott
  #2   Report Post  
 
Posts: n/a
Default Understanding Implementation of High Pass Filter

Scott Soderlund wrote:

Snip

Looking at the method above, I don't understand the meaning of the
'GAIN' variable (and more specifically the number it is set to). Is
this likely the cutoff frequency? Also, in the next to the last line
of the method, where yv[2] = ..., there are two numbers in this line
that I have no idea what they mean. The number "-0.9479259375" and
the number "1.9469976496". My guess is that the number
"-0.9479259375" is the lowest frequency possible (zero Hz) and that
"1.9469976496" is the highest frequency possible. This would make
sense if the GAIN variable was the cutoff frequency. Again, that is
my best guess! Can someone help with my understanding???


No, the filter has some gain in the passband, which has been calculated
during the design, by dividing the input by this the code ensures that
the output level at high frequency is the same as the input.

The other numbers are the coefficents derived from the recurrence relation
which are derived from the Z plane poles & zeros.
The Z plane pole zero diagram is derived by warping the S plane pole & zero
positions to account for the discrete time nature of the filter.

Digital filters are a HUGE sunject and there is lots of literature out
there.

There is an interactive design program for some of the possibilities at:
http://www-users.cs.york.ac.uk/~fisher/mkfilter which is a very easy
way to design 1 off simple filters.

In fact I would not be surprised if this is the original source of
your code.

Regards, Dan.
--
** The email address *IS* valid, do NOT remove the spamblock
And on the evening of the first day the lord said...........
..... LX 1, GO!; and there was light.
  #3   Report Post  
Ben Bradley
 
Posts: n/a
Default Understanding Implementation of High Pass Filter

In rec.audio.pro, (Scott Soderlund) wrote:

Hi,
I wrote the other day asking about Noise Gates and got some really
good replies which greatly helped in my understanding of how they
work. Thanks Guys!!!

Today, I'm asking about a High Pass Filter. Again, I just started
working on a project where the computer captures samples of someone's
speech. Each of these samples is run through a 50 Hz High Pass Filter
to improve the quality of the sample. I've done a lot of reading
about High Pass filters and think I understand pretty well how they
work. What I don't understand though is a couple of the variables in
the program where the filter is actually implemented. I'm hoping
someone out there knows java


I wrote all the below and didn't even see that word. I don't know
Java, though I understand it's an interpreted language (as if that
made much difference at the source level), and it sure looks a helluva
lot like C (or maybe C++ with the class/OOP stuff). I presume what I
see does the same things as in C.
I remember when Microsoft had "Quick C" - a C interpreter, that
allegedly speeded up development. "But I digress..."

and can help tell me what they mean.
Code follows and then my questions...


This is really a question for comp.dsp, but I'll try to answer
anyway, I know at least enough to be dangerous on Usenet.
[i]
public class HighPass50
{
static int NZEROS = 5;
static int NPOLES = 5;
static double GAIN = 1.095980088e+00;

double xv[] = new double[NZEROS+1];
double yv[] = new double[NPOLES+1];

public HighPass50() {}

public void process(short data[])
{
for (int i=0; i data.length; ++i)
{
xv[0] = xv[1];
xv[1] = xv[2];
xv[2] = data[i] / GAIN;
yv[0] = yv[1];
yv[1] = yv[2];
yv[2] = (xv[0] + xv[2]) - 2 * xv[1] + ( -0.9479259375 *
yv[0]) + ( 1.9469976496 * yv[1]);
data = (short)yv[2];
}
}
}


This looks like an implementation of an IIR filter. Most of the
lines inside the for loop just move the data around, and the "yv[2] =
...." line that does the filtering. As far as I'm concerned, though, it
might as well be machine code. There's no documentation about the
derivation of the filter, or any of the little diagrams that show the
"data flow" of the samples. I hate looking at code to try to derive
this myself. Where did you get this code, and more importantly, why
isn't there a single comment in it, much less some REAL info on what
the code does?

Looking at the method above, I don't understand the meaning of the
'GAIN' variable (and more specifically the number it is set to). Is
this likely the cutoff frequency?


It's what it says it is. Apparently the output amplitude of in-band
signals through the filters is about 1.09 times the input amplitude.
The line xv[2] = data[i] / GAIN; takes the input sample (in data[i])
and divides it by that gain (putting the result into the first 'tap'
or whatever of the filter) so that the filter output is the same as
the input (I would have multiplied by the reciprocal, just on the
ornery principle that multiplication may be slightly faster than
division).
That's the easy part, it's human-readable (or, rather,
C-programmer-readable) even without documentation.

Also, in the next to the last line
of the method, where yv[2] = ..., there are two numbers in this line
that I have no idea what they mean. The number "-0.9479259375" and
the number "1.9469976496". My guess is that the number
"-0.9479259375" is the lowest frequency possible (zero Hz) and that
"1.9469976496" is the highest frequency possible. This would make
sense if the GAIN variable was the cutoff frequency. Again, that is
my best guess! Can someone help with my understanding???


These are constants in the IIR filter. They DO determine cutoff
frequency and such, but not in a direct way as you were guessing. The
correlation is far from obvious without studying IIR filters (or even
WITH studying the appropriate things). And these aren't the only
constants. xv [0], xv [1] and xv[2] have constants of 1, -2, and 1,
respectively.
Really, ask this second part (or the whole thing again) on
comp.dsp. Feel free to quote this response, FWIW.

Thanks in advance,


Should I say anything about the parenthesesitis (isn't there a
Jargon File word for extra parens in C code?) in the filter
statement... nah.

Scott



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
High Pass Filtering - How Audible? Arny Krueger Audio Opinions 36 April 22nd 04 08:10 PM
rec.audio.car FAQ (Part 4/5) Ian D. Bjorhovde Car Audio 0 March 6th 04 07:54 AM
Bose high pass filter Chris Audio Opinions 3 January 25th 04 06:19 PM
Crossover Point - Low & High Pass Filter Slope Al High End Audio 0 December 2nd 03 09:41 PM
Low pass filter question... GregS Car Audio 0 July 3rd 03 07:07 PM


All times are GMT +1. The time now is 11:29 AM.

Powered by: vBulletin
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 AudioBanter.com.
The comments are property of their posters.
 

About Us

"It's about Audio and hi-fi"