> >Yup, this is a low pass filter, intended for anti-aliasing. > > Anti-aliasing is normally done before sampling. The only reason that I'm > aware of for anti-aliasing after sampling is prior to decimation.Glad to hear it! There is an analog anti-aliasing LPF prior to the analog-to-digital conversion. Once sampled, I apply the digital LPF to attenuate any higher frequencies. I then decimate to reduce the amount of subsequent processing required. Cheers, Dave
FIR: Dealing with negative values and scaling
Started by ●September 11, 2006
Reply by ●September 12, 20062006-09-12
Reply by ●September 12, 20062006-09-12
> (snip) > > > I'm lost here. All signals that can be capacitor- or transformer coupled > > -- that is, almost all audio and RF -- are bipolar. How can you not have > > negative values? > > I agree. > > There are different ways to look at the output of an A/D converter. > One is a signed value, say between -32768 and 32767, the other is > an unsigned value between 0 and 65535. >The signal I'm measuring will be of the usual +/- variety (and ADC output is on the [-32768, 32767] range). The phenomena that the signal represents is conceptually positive, so the zero-reference should be at the low-end of the ADC range. Process the data in the native +/- range, I was concerned that I would lose information. With a 40-bit accumulator and desired 16-bit output, I am confused about which 16 bits to use. For example, if the filter has a DC gain of 32768, I can right-shift the accumulator by 16 bits (equivalent to a divide by 32768). But now I'm left with 16 + 8 bits. What happens if some of the most significant 8 bits contain information? Like I said, I'm still a little confused. I'll put a little more thought into it...maybe I'll have an epiphany :)> One system I worked with would average some number of A/D outputs > before the signal arrived, and then subtract that from the actual > signal. (With FPGA hardware to do the calculation.) >I actually do need to perform some AC coupling on the signal (after the LPF I mentioned). I plan on taking a similar approach...average the signal and subtract the average. I haven't decided if I should use another LPF or if I should adopt a boxcar sliding average. I'm leaning towards LPF.
Reply by ●September 12, 20062006-09-12
glen herrmannsfeldt wrote:> Jerry Avins wrote: > > (snip) > >> I'm lost here. All signals that can be capacitor- or transformer >> coupled -- that is, almost all audio and RF -- are bipolar. How can >> you not have negative values? > > I agree. > > There are different ways to look at the output of an A/D converter. > One is a signed value, say between -32768 and 32767, the other is > an unsigned value between 0 and 65535. > > With an AC coupled input, one would bias the input somewhere in > the middle, but it might not be exactly in the middle. Zero volts > might not be 0 or 32768 as signed or unsigned values. > > One system I worked with would average some number of A/D outputs > before the signal arrived, and then subtract that from the actual > signal. (With FPGA hardware to do the calculation.)Sure. The output of a an A/D converter can be expressed in unsigned, offset, or two's-complement (among others) binary, but that has no impact on filter algorithms' "expectation" that a pure sines lie between symmetric positive and negative limits. Since almost all filter computations use two's-complement arithmetic, the sample values need to be converted to that form in order to be valid filter inputs. Perhaps Mr. Bonnell mistakenly thinks that filters deal with amplitudes instead of instantaneous values. That might explain why he sees negative numbers as wrong results. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●September 12, 20062006-09-12
dave_bonnell@hotmail.com wrote:>>(snip) >> >> >>>I'm lost here. All signals that can be capacitor- or transformer coupled >>>-- that is, almost all audio and RF -- are bipolar. How can you not have >>>negative values? >> >>I agree. >> >>There are different ways to look at the output of an A/D converter. >>One is a signed value, say between -32768 and 32767, the other is >>an unsigned value between 0 and 65535. >> > > > The signal I'm measuring will be of the usual +/- variety (and ADC > output is on the [-32768, 32767] range). The phenomena that the signal > represents is conceptually positive, so the zero-reference should be at > the low-end of the ADC range.Assuming that I could find the appropriate MAC instruction I would offset the thing to the [0, 65535] range, then. This tends to self-document the process, so that you have an easy 'numbers to volts' conversion (or 'numbers to inches') when you're debugging. It depends on your processor being able to do a signed-unsigned multiply, though.> > Process the data in the native +/- range, I was concerned that I would > lose information.You shouldn't, but it may be obscure. Obscurity is to be avoided if you can, but you'll often find that it must be embraced if you're squeezing that last penny out of the product cost or the last clock tick out of the processor.> With a 40-bit accumulator and desired 16-bit output, > I am confused about which 16 bits to use. For example, if the filter > has a DC gain of 32768, I can right-shift the accumulator by 16 bits > (equivalent to a divide by 32768). But now I'm left with 16 + 8 bits. > What happens if some of the most significant 8 bits contain > information?You probably want to arrange for a filter with a DC gain of 65536, and take the upper 16 bits of the accumulator (sans the overflow byte). If your filter is as described it should just never saturate -- but make sure.> > Like I said, I'm still a little confused. I'll put a little more > thought into it...maybe I'll have an epiphany :) >Just keep grinding through the numbers. It'll come to you. -- snip -- -- Tim Wescott Wescott Design Services http://www.wescottdesign.com Posting from Google? See http://cfaj.freeshell.org/google/ "Applied Control Theory for Embedded Systems" came out in April. See details at http://www.wescottdesign.com/actfes/actfes.html
Reply by ●September 12, 20062006-09-12
<dave_bonnell@hotmail.com> wrote in message news:1158069436.140080.26470@i42g2000cwa.googlegroups.com...>> (snip) >> >> > I'm lost here. All signals that can be capacitor- or transformer >> > coupled >> > -- that is, almost all audio and RF -- are bipolar. How can you not >> > have >> > negative values? >> >> I agree. >> >> There are different ways to look at the output of an A/D converter. >> One is a signed value, say between -32768 and 32767, the other is >> an unsigned value between 0 and 65535. >> > > The signal I'm measuring will be of the usual +/- variety (and ADC > output is on the [-32768, 32767] range). The phenomena that the signal > represents is conceptually positive, so the zero-reference should be at > the low-end of the ADC range.***Why is that necessarily so? Why worry about "conceptually positive" as compared to simply dealing with the signal as it occurs? ***If you really mean that *any* negative input is an error or noise then maybe you should limit the result to purely positive numbers. That would be a nonlinear filter but maybe appropriate for your physical situation. Either way, I'm not sure what you do with the numeric range but I suspect it's easier to keep the negative range in your number system. You should not expect the FIR filter to *not* have negative coefficients and negative interim results, etc. so keeping the negative range may be important.> > Process the data in the native +/- range, I was concerned that I would > lose information. With a 40-bit accumulator and desired 16-bit output, > I am confused about which 16 bits to use. For example, if the filter > has a DC gain of 32768, I can right-shift the accumulator by 16 bits > (equivalent to a divide by 32768). But now I'm left with 16 + 8 bits. > What happens if some of the most significant 8 bits contain > information????? I think a right shift is a multiply and then, yes, you'd lose the most significant bits and would lost the most significant information. I think a left shift is a divide and you lose the least significant bits which have the least significant information - so to speak.> > Like I said, I'm still a little confused. I'll put a little more > thought into it...maybe I'll have an epiphany :) > >> One system I worked with would average some number of A/D outputs >> before the signal arrived, and then subtract that from the actual >> signal. (With FPGA hardware to do the calculation.)*** "before the signal arrived" implies knowledge of when the signal is present and when it is not present. It also implies temporal logic of some sort. Is that really, really what you want to do? I'd avoid it if possible unless you're only talking about a calibration phase of operation.>> > > I actually do need to perform some AC coupling on the signal (after the > LPF I mentioned). I plan on taking a similar approach...average the > signal and subtract the average. I haven't decided if I should use > another LPF or if I should adopt a boxcar sliding average. I'm leaning > towards LPF. >*** AC coupling >> high pass filter. Why do you need to do this? A boxcar sliding average is just one type of LPF that could be used for the purpose of creating a signal called "the average" in order to subtract it out. Fred
Reply by ●September 13, 20062006-09-13
Jerry Avins wrote: (snip about A/D converter outputs)> Sure. The output of a an A/D converter can be expressed in unsigned, > offset, or two's-complement (among others) binary, but that has no > impact on filter algorithms' "expectation" that a pure sines lie between > symmetric positive and negative limits. Since almost all filter > computations use two's-complement arithmetic, the sample values need to > be converted to that form in order to be valid filter inputs.That isn't quite what I was trying to say. One that I was is that one can call the output either unsigned or twos complement, for example, somewhat independent of the actual voltage input. The A/D converters I know have inputs for the low and high voltage, which can be zero and some positive value, negative and positive values, both positive, both negative, etc. Some allow one to invert the MSB to form a twos complement value, others don't, but it is easy to do, anyway. In the case of supplying a negative and positive reference voltage, it is unlikely that zero voltage will be exactly at the 000000 point of the A/D converter.> Perhaps Mr. Bonnell mistakenly thinks that filters deal with amplitudes > instead of instantaneous values. That might explain why he sees negative > numbers as wrong results.If you do baseline correction, subtracting an average value with no signal it is pretty easy to go negative even when the output is supposed to be always positive. -- glen
Reply by ●September 13, 20062006-09-13
glen herrmannsfeldt wrote:> Jerry Avins wrote: > > (snip about A/D converter outputs) > >> Sure. The output of a an A/D converter can be expressed in unsigned, >> offset, or two's-complement (among others) binary, but that has no >> impact on filter algorithms' "expectation" that a pure sines lie >> between symmetric positive and negative limits. Since almost all >> filter computations use two's-complement arithmetic, the sample values >> need to be converted to that form in order to be valid filter inputs. > > That isn't quite what I was trying to say. > > One that I was is that one can call the output either unsigned > or twos complement, for example, somewhat independent of the actual > voltage input. The A/D converters I know have inputs for the low and > high voltage, which can be zero and some positive value, negative and > positive values, both positive, both negative, etc. Some allow one to > invert the MSB to form a twos complement value, others don't, but it > is easy to do, anyway.I think you're saying here that the samples can have any range of values, not necessarily encompassing zero, especially if there is a DC offset. Of course you're right.> In the case of supplying a negative and positive reference voltage, > it is unlikely that zero voltage will be exactly at the 000000 point > of the A/D converter.There's always some hardware offset if nothing else.>> Perhaps Mr. Bonnell mistakenly thinks that filters deal with >> amplitudes instead of instantaneous values. That might explain why he >> sees negative numbers as wrong results.Other posts I read after after I wrote that made it clear that this conjecture was off the mark. I wish I hadn't expressed it.> If you do baseline correction, subtracting an average value with no > signal it is pretty easy to go negative even when the output is > supposed to be always positive.Subtracting a running average from a signal in order to remove offset is a form of high-pass filtering, but not usually the best digital kind for the job. (It's great for analog when done right: capacitor coupling.) Digital or analog, the filter's settling time at startup can be a problem. Is there a URL for R.B-J.'s DC blocker? Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●September 14, 20062006-09-14
Jerry Avins wrote: (snip)> Subtracting a running average from a signal in order to remove offset is > a form of high-pass filtering, but not usually the best digital kind for > the job. (It's great for analog when done right: capacitor coupling.) > Digital or analog, the filter's settling time at startup can be a > problem. Is there a URL for R.B-J.'s DC blocker?The system I was working on not so long ago took some samples before the pulse being measured arrived, when it really was supposed to be zero, to use as a baseline. Then summed the samples where the pulse is to integrate over the pulse. -- glen
Reply by ●September 14, 20062006-09-14
glen herrmannsfeldt wrote:> Jerry Avins wrote: > > (snip) > >> Subtracting a running average from a signal in order to remove offset >> is a form of high-pass filtering, but not usually the best digital >> kind for the job. (It's great for analog when done right: capacitor >> coupling.) Digital or analog, the filter's settling time at startup >> can be a problem. Is there a URL for R.B-J.'s DC blocker? > > The system I was working on not so long ago took some samples before > the pulse being measured arrived, when it really was supposed to be > zero, to use as a baseline. Then summed the samples where the pulse > is to integrate over the pulse.Establishing a base reference is a Good Thing. In hardware, the technique is called auto-zero. Subtracting what measurement indicates ought to be zero is not the same as subtracting an average of the previous signal. Jerry -- Engineering is the art of making what you want from things you can get. �����������������������������������������������������������������������
Reply by ●September 14, 20062006-09-14
"Jerry Avins" <jya@ieee.org> wrote in message news:-rqdnZa_d6yc95TYnZ2dnUVZ_tOdnZ2d@rcn.net...> glen herrmannsfeldt wrote: >> Jerry Avins wrote: >> >> (snip) >> >>> Subtracting a running average from a signal in order to remove offset is >>> a form of high-pass filtering, but not usually the best digital kind for >>> the job. (It's great for analog when done right: capacitor coupling.) >>> Digital or analog, the filter's settling time at startup can be a >>> problem. Is there a URL for R.B-J.'s DC blocker? >> >> The system I was working on not so long ago took some samples before >> the pulse being measured arrived, when it really was supposed to be >> zero, to use as a baseline. Then summed the samples where the pulse >> is to integrate over the pulse. > > Establishing a base reference is a Good Thing. In hardware, the technique > is called auto-zero. Subtracting what measurement indicates ought to be > zero is not the same as subtracting an average of the previous signal. >Jerry, Yes, but subtracting the average of a precursor where "signal is not present" epoch could be the former and not the latter. My question to the OP was: "how do you know?" Fred






