Hello!
I am trying to pick up narrowband 18kHz signals from an electret microphone from as far away as possible.
Plan is to use a filter design tool like this one:
http://www.changpuak.ch/electronics/Nar ... pass_2.php
to design a MFB narrow bandpass filter centered at 18kHz with gain 10 and Q 10 and cascade two stages.
My question is: how do I interface the electret mic into the filter stages? I am concerned that the bias resistor that i'll need to put on the electret will throw off the input resistance into the filter. Do I need to put a unity gain buffer between the electret and the filter input, or is there a clever way to adjust the input resistors on the filter to match up with the electret stage without changing the filter characteristics?
Thanks!
Matching electret into MFB bandpass filter?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
Putting a buffer between the electret and the filter would be easiest.
You could treat the output impedance of the electret and its bias network as R1 and connect the output point directly to the junction of R3 and C1, but there are a couple of problems. First, the impedance of the filter would load the electret, changing its output response. Second, the equivalent resistance of the electret changes as it responds to sound, so the frequency response of your filter would change slightly with the input.
You could treat the output impedance of the electret and its bias network as R1 and connect the output point directly to the junction of R3 and C1, but there are a couple of problems. First, the impedance of the filter would load the electret, changing its output response. Second, the equivalent resistance of the electret changes as it responds to sound, so the frequency response of your filter would change slightly with the input.
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
Cool, thanks! Sounds like the buffer is the way to go. Can I cascade these stages if I need more gain? if the signal is <10mV, then I'll need a lot of gain to get it into the full range of my ADC. Am thinking of doing two stages of 18x. Anything I should watch out for?
My 1% resistor kit is arriving tomorrow :-)
My 1% resistor kit is arriving tomorrow :-)
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
Yeah, you can cascade gain stages as far as you want.
The general rule is to get as much gain as you can from the first stage though. Each stage adds some noise to the signal, and each stage multiplies the noise from all the previous stages.
If you wanted a gain of 10,000 and did it with three stages with gains of 10, 33, and 33, the noise injected by the first stage would be amplified by a factor of 1000 by the last two stages.
The first stage is the only one that doesn't have a "noise from all the previous stages" term, so push that one near the limit of its gain-bandwidth product. If your amp's GBP is 1MHz and your signal of interest is 18kHz, the gain limit would be around 55 (55*18k=1M). Use additional stages to get any further gain you need, and filter just before going to the ADC.
You need to make sure the signal going into an ADC has no information above (or near) half the sampling frequency. The nature of sampling causes rounding errors at or above half the sampling frequency which leads to a problem called 'aliasing' (all those wheels that seem to spin backwards in old movies)so every ADC wants an anti-aliasing filter on its input.
Since you need one anyway, it makes sense to roll any other filtering you want to do in with it.
The general rule is to get as much gain as you can from the first stage though. Each stage adds some noise to the signal, and each stage multiplies the noise from all the previous stages.
If you wanted a gain of 10,000 and did it with three stages with gains of 10, 33, and 33, the noise injected by the first stage would be amplified by a factor of 1000 by the last two stages.
The first stage is the only one that doesn't have a "noise from all the previous stages" term, so push that one near the limit of its gain-bandwidth product. If your amp's GBP is 1MHz and your signal of interest is 18kHz, the gain limit would be around 55 (55*18k=1M). Use additional stages to get any further gain you need, and filter just before going to the ADC.
You need to make sure the signal going into an ADC has no information above (or near) half the sampling frequency. The nature of sampling causes rounding errors at or above half the sampling frequency which leads to a problem called 'aliasing' (all those wheels that seem to spin backwards in old movies)so every ADC wants an anti-aliasing filter on its input.
Since you need one anyway, it makes sense to roll any other filtering you want to do in with it.
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
Hmm, it doesn't look like my mic has enough oomph to get through the buffer. Tested it with my function generator at 5mV pp and nothing on the other side. Do I need better opamps?
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
Hm, figured this one out - was not DC offsetting the signal out of the function generator into my single-supply buffer so it was actually getting clipped to 2.5mV.
I've built one stage of the filter theoretically centered at 19kHz, using the design tool from my previous post. The filter was designed to have gain=10 and Q=10. I then adjusted the values that the tool gave me to the closest 1% resistors in my stock, and built/simulated in PartSim:
http://www.partsim.com/simulator/#26435
The simulation with my real resistor values shows around 10x gain. But, when I built the circuit, I am only getting around 4.5x gain maximum at around 18kHz. I've double checked that I am using the correct parts. Is there something that I am overlooking here, or is this just a parts tolerance issue? Should I re-design the filter with more gain if I want to get to 10x in practice?
Thanks agian for your help!
I've built one stage of the filter theoretically centered at 19kHz, using the design tool from my previous post. The filter was designed to have gain=10 and Q=10. I then adjusted the values that the tool gave me to the closest 1% resistors in my stock, and built/simulated in PartSim:
http://www.partsim.com/simulator/#26435
The simulation with my real resistor values shows around 10x gain. But, when I built the circuit, I am only getting around 4.5x gain maximum at around 18kHz. I've double checked that I am using the correct parts. Is there something that I am overlooking here, or is this just a parts tolerance issue? Should I re-design the filter with more gain if I want to get to 10x in practice?
Thanks agian for your help!
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
Let's see.. that's a multiple-feedback topology.
High-pass MFB filters have a known quirk of having their input impedance fall as the frequency rises.. a side effect of the input capacitance. If the frequency gets high enough, the impedance can fall low enough to overload the drive capacity of the op amp. Check the op amp's datasheet for information about driving capacitive loads.
Also, looking over your component values, the input voltage divider (R1-R3) seems a bit off.. the equations I have put the ratio at R2/R1=H/(2Q-H) where H is the desired gain. You want H=Q=10, so by my equations the ratio would be 1:1, and both values would be about 1.8k. The ratio on yours is 1:19, which makes me suspect the ratio was figured with Q=10 and H=1.
(Cheat sheet: http://www.analog.com/static/imported-f ... MT-220.pdf)
High-pass MFB filters have a known quirk of having their input impedance fall as the frequency rises.. a side effect of the input capacitance. If the frequency gets high enough, the impedance can fall low enough to overload the drive capacity of the op amp. Check the op amp's datasheet for information about driving capacitive loads.
Also, looking over your component values, the input voltage divider (R1-R3) seems a bit off.. the equations I have put the ratio at R2/R1=H/(2Q-H) where H is the desired gain. You want H=Q=10, so by my equations the ratio would be 1:1, and both values would be about 1.8k. The ratio on yours is 1:19, which makes me suspect the ratio was figured with Q=10 and H=1.
(Cheat sheet: http://www.analog.com/static/imported-f ... MT-220.pdf)
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
Ok.
I'm using the equations from that cheat sheet in the bandpass filter section and getting something different for R1 = R2 than that web calculator as well as what you got! Erm...
f0 = 19000
C1 = C2 = 0.47nF
H = Q = 10
k = 2*pi*f0*C1
k = 2*pi*19000*.47e-9
k = 1.19e-4
R1 = 1/(H*k)
R1 = 837.66(...?)
Also, if I want to increase the gain with the same rolloff, I also need to increase q, right?
I'm using the equations from that cheat sheet in the bandpass filter section and getting something different for R1 = R2 than that web calculator as well as what you got! Erm...
f0 = 19000
C1 = C2 = 0.47nF
H = Q = 10
k = 2*pi*f0*C1
k = 2*pi*19000*.47e-9
k = 1.19e-4
R1 = 1/(H*k)
R1 = 837.66(...?)
Also, if I want to increase the gain with the same rolloff, I also need to increase q, right?
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
I think you got a partial result for the value of k. I get about 56.1e-6:
https://www.google.com/#q=2+*+pi+*+19000+*+.47e-9
https://www.google.com/#q=1+%2F+(+10+*+ ... *+.47e-9+)
The value of 2*pi*f0 is 119380 though, which has all the same digits as your result.
WRT rolloff, you can leave Q the same.
In a bandpass filter, Q is the ratio of the center frequency and the distance between the -3db points on either side.
For Q=10 and a center frequency of 19kHz, the distance between the -3db points will be 1.9kHz, and the points themselves will be 18.07kHz and 19.97kHz (it's a geometric average, so sqrt(f1*f2)=f0).
If Q remains 10, the -3db points will stay at those two frequencies no matter what gain you use. The absolute amplitude at those points will rise and fall with the gain, but they'll always be 3db down from the amplitude at the center frequency.
https://www.google.com/#q=2+*+pi+*+19000+*+.47e-9
https://www.google.com/#q=1+%2F+(+10+*+ ... *+.47e-9+)
The value of 2*pi*f0 is 119380 though, which has all the same digits as your result.
WRT rolloff, you can leave Q the same.
In a bandpass filter, Q is the ratio of the center frequency and the distance between the -3db points on either side.
For Q=10 and a center frequency of 19kHz, the distance between the -3db points will be 1.9kHz, and the points themselves will be 18.07kHz and 19.97kHz (it's a geometric average, so sqrt(f1*f2)=f0).
If Q remains 10, the -3db points will stay at those two frequencies no matter what gain you use. The absolute amplitude at those points will rise and fall with the gain, but they'll always be 3db down from the amplitude at the center frequency.
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
Hm. Think I must have entered something in my spreadsheet wrong. Sorry...
Will try these values tomorrow. Question though....I used this calculator too (looks like the guy Knows What He's Doing, he finds the transfer function and everything):
http://sim.okawa-denshi.jp/en/OPtazyuBakeisan.htm
and got the same result as the other one (which is different than the equations you sent me). Why is this?
Thanks again for your help!
Will try these values tomorrow. Question though....I used this calculator too (looks like the guy Knows What He's Doing, he finds the transfer function and everything):
http://sim.okawa-denshi.jp/en/OPtazyuBakeisan.htm
and got the same result as the other one (which is different than the equations you sent me). Why is this?
Thanks again for your help!
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
Ah.. he's using a different solution pattern.
There's a note in the section where you set the capacitor values which says the ratio of C2/C1 has to be H/(Q^2-1). For the values you've chosen, that would be roughly 1/10. If C1 is 470pF, C2 would have to be 47pF.
That's part of the fun when it comes to designing filters: you have a second-order differential equation and 5 unknown component values. The filter's characteristic equation doesn't give you enough information to find a single, unique solution for all five values, so you have to impose additional rules.
The cheat sheet I posted makes a rule that the capacitor values will be equal, then solves for the resistances. The calculator you posted makes a rule that the ratio of C2/C1 will equal the ratio of R2/R1, then solves in terms of those.
The question of which approach is best is something for the filter hipsters to argue (endlessly, and to no visible effect).
The ratio approach shows a bias toward IC design, because the tolerances on IC component values absolutely suck.. +/-20% is normal. IC design makes it easy to get a precise ratio between component values though.. 10x to 1x, with a +/-20% tolerance on the exact value of x.. so ratio-based solutions are a hallmark of IC design.
For those of us who don't have a billion-dollar fab at our disposal, finding discrete components whose tolerances are within 1% of nominal is easy.. so value-based solutions are a hallmark of discrete design.
SMD components bring a little bit of the fab to the discrete designer's portfolio though, so it's easy to get component arrays with extremely good 1:1 ratios within a package, and 1% to 5% tolerances between packages. That means 1:1 ratios and low-integer ratios (2:3, 7:1) are also becoming popular in discrete design.
Bottom line, it's the analog EE version of po-tay-to/po-tah-to.
There's a note in the section where you set the capacitor values which says the ratio of C2/C1 has to be H/(Q^2-1). For the values you've chosen, that would be roughly 1/10. If C1 is 470pF, C2 would have to be 47pF.
That's part of the fun when it comes to designing filters: you have a second-order differential equation and 5 unknown component values. The filter's characteristic equation doesn't give you enough information to find a single, unique solution for all five values, so you have to impose additional rules.
The cheat sheet I posted makes a rule that the capacitor values will be equal, then solves for the resistances. The calculator you posted makes a rule that the ratio of C2/C1 will equal the ratio of R2/R1, then solves in terms of those.
The question of which approach is best is something for the filter hipsters to argue (endlessly, and to no visible effect).
The ratio approach shows a bias toward IC design, because the tolerances on IC component values absolutely suck.. +/-20% is normal. IC design makes it easy to get a precise ratio between component values though.. 10x to 1x, with a +/-20% tolerance on the exact value of x.. so ratio-based solutions are a hallmark of IC design.
For those of us who don't have a billion-dollar fab at our disposal, finding discrete components whose tolerances are within 1% of nominal is easy.. so value-based solutions are a hallmark of discrete design.
SMD components bring a little bit of the fab to the discrete designer's portfolio though, so it's easy to get component arrays with extremely good 1:1 ratios within a package, and 1% to 5% tolerances between packages. That means 1:1 ratios and low-integer ratios (2:3, 7:1) are also becoming popular in discrete design.
Bottom line, it's the analog EE version of po-tay-to/po-tah-to.
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
That's interesting....thanks!
So could this capacitor ratio thing I'm not taking into account be the reason that the gain is always off by around a factor of 2?
I built a few of them anyway and am piping it into a goertzel filter on my micro, and it seems to work ok! But now I am itching to go back and redesign the thing with the correct math :-)
So could this capacitor ratio thing I'm not taking into account be the reason that the gain is always off by around a factor of 2?
I built a few of them anyway and am piping it into a goertzel filter on my micro, and it seems to work ok! But now I am itching to go back and redesign the thing with the correct math :-)
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
Yep.. the idea is to keep the time constants of the R1-C2 and R2-C1 pairs equal and at the corner frequency of the filter.powerpants wrote:So could this capacitor ratio thing I'm not taking into account be the reason that the gain is always off by around a factor of 2?
Once you learn the territory, it's easiest to describe filter behavior by plotting the pairs on the complex-frequency plane. To simplify things enormously, resistance is plotted on the horizontal axis with larger values going left, capacitance and inductance are plotted on the vertical axis.
Using the equal-ratios rule and normalizing the values to make the math easier to visualize, R1-C2 would plot as the point (-10,1) and R2-C1 would plot as the point (-1,10). Those are both the same distance from the origin, so you could draw a circle centered at the origin that will touch both points, and for reasons I won't even begin to explain, that produces a Butterworth filter.. the best possible compromise between fast rolloff and smooth amplitude response in the passband.
If we made R1 larger, that point would move farther to the left, and you'd need to draw a wide ellipse to touch both points. That would give you a Bessel filter.. slower rolloff, but less phase-shift as the frequency increases, and thus less tendency for signals with lots of harmonics (square waves) to ring at the output.
If we made R1 smaller, the point would move to the right and we'd have to draw a tall ellipse to touch both points. That would give you a Chebyshev filter.. fastest possible rolloff, but at the cost of varying gain in the passband and more phase shift as the frequency increases (Chebyshev filters ring like a bell).
In the case of the filter you built, both C values are the same, but the R values are different. The two points would sit on a line parallel to the horizontal axis, and the point with the higher time constant would steal energy from the one with the lower time constant. The net result would be a Bessel-like loss of rolloff and Q.
- 405nm
- Posts: 64
- Joined: Tue Feb 26, 2008 8:55 pm
Re: Matching electret into MFB bandpass filter?
Ok, that connected a few dots (ha!) that I never quite understood from my controls class years ago, it's cool how actually trying to build stuff will do that ;-)
Some more questions:
-Why would my simulation (with the original C1=C2 values from my first webcalc that gave me the amps with 0.5x gain in real life) give me the output I was expecting (gain of 10/100, etc)? The visual math explanation you gave makes sense to me, but I hate it when I don't understand everything...
-How do I figure out the capacitive "loadiness" of my stages so I can see if my opamp is ok with it? (Datasheet says up to 500pF is ok)
-I got some fancy 38MHz opamps (OPA2350), but they don't like being driven as buffers directly off of my electret. What spec should I check on the datasheet to figure out why this is?
Thanks again for all of you help on this, am learning a lot!
Some more questions:
-Why would my simulation (with the original C1=C2 values from my first webcalc that gave me the amps with 0.5x gain in real life) give me the output I was expecting (gain of 10/100, etc)? The visual math explanation you gave makes sense to me, but I hate it when I don't understand everything...
-How do I figure out the capacitive "loadiness" of my stages so I can see if my opamp is ok with it? (Datasheet says up to 500pF is ok)
-I got some fancy 38MHz opamps (OPA2350), but they don't like being driven as buffers directly off of my electret. What spec should I check on the datasheet to figure out why this is?
Thanks again for all of you help on this, am learning a lot!
- adafruit_support_mike
- Posts: 67485
- Joined: Thu Feb 11, 2010 2:51 pm
Re: Matching electret into MFB bandpass filter?
Yeah.. a week of building actual filters gives you meaningful context for about three semesters of theory.powerpants wrote:Ok, that connected a few dots (ha!) that I never quite understood from my controls class years ago, it's cool how actually trying to build stuff will do that ;-)
The biggest factor is probably that you used an ideal op amp in the simulation and a real one on the breadboard.powerpants wrote:-Why would my simulation (with the original C1=C2 values from my first webcalc that gave me the amps with 0.5x gain in real life) give me the output I was expecting (gain of 10/100, etc)? The visual math explanation you gave makes sense to me, but I hate it when I don't understand everything...
The simplest Spice models for things like op amps are hugely deceptive.. infinite input impedance, zero output impedance, and worst of all, no frequency-dependent behavior. That's a huge problem when it comes to modeling filters, because most real op amps have what's called 'dominant pole compensation' to keep them stable, and that basically throws another low-pass filter into your circuit.
If you're using the OP2350 (lovely things), take a look at the gain/phase-vs-frequency graph in the Typical Characteristics section.. it's a low-pass filter with a corner frequency of 100Hz. That large filtering effect swamps out the little effects from all the parasitic capacitances in the chip, but it knocks the open-loop gain down to about 1000 in the 20kHz to 30kHz range.
Put it on the oscilloscope. Set the amp up as a simple buffer, connect the capacitors in parallel between the output and GND, and hook a pulse generator to the input. Use the shortest pulses you can get, spaced widely at first to see the amp's impulse response, the send the pulses in at 19kHz.powerpants wrote:-How do I figure out the capacitive "loadiness" of my stages so I can see if my opamp is ok with it?
What kind of problematic output are you getting? Those should be almost ideal electret preamps.powerpants wrote:-I got some fancy 38MHz opamps (OPA2350), but they don't like being driven as buffers directly off of my electret. What spec should I check on the datasheet to figure out why this is?
Please be positive and constructive with your questions and comments.