## Direction on Signal Processing

18 posts / 0 new
Author
Message

Hi Freaks,

I've been immersing myself into learning FFT and, since finding it a little tedious, I thought I might seek some guidance from the brains-trust on whether its likely to be the right way to go before investing too much time on something that isn't. (Ain't commercial life fun!)

Essentially I'm measuring impedance (or least the real part of it) of a battery insitu.  So far I'm doing this by injecting a 1kHz stimulus current (measured across sense resistor) and measuring the resultant voltage across the battery.  This involves talking an RMS calculation of both V & I wave forms, a bit of ohms law, and job done.

Problem is this only works properly when there is no charger ripple present across the battery.

At this point I have achieved some reasonable results (within a few mohm) by taking 2 sets of measurements, 1 with and 1 without the stimulus current applied, taking the difference, after correcting for phase shift, and then performing the RMS calc.  This has been optimised for a narrow range of freq say ±15Hz.

Unfortunately, the charger ripple frequency can vary between charger models.  So far I have measured ~150Hz but have others expected to be anything up to 300Hz.

Also, the sampling freq and window length make the RMS calculation frequency dependent so I'm considering alternative methods such as Standard Deviation, FFT, Goertzel which I believe should also eliminate need for the phase-shift/subtraction.

Ultimately I would like readings for both the rms charger ripple and the rms stimulus current.  Are the amplitudes or magnitudes output by an FFT likely to be usable for absolute level measurement? Would the Goertzel algorithm be the go given the known 1kHz stimulus or would that fall out of the FFT while looking for the unknown frequency ripple.

Is it perhaps better/easier to just measure the frequency, say zero crossings and then adjust the sample rate and window length to suit? Sort of auto-tuned to the particular installation if you like?

I will be most grateful for any thoughts, ideas, suggestions or other.

Cheers,

Steve

Free DSP textbook: http://www.dspguide.com/

schtevo wrote:
Essentially I'm measuring impedance (or least the real part of it) of a battery insitu.

To what end?

Have you done a literature search on that?

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

By "battery impedance", are you trying to model a: a) series resistance, b)frequency response c)dynamic response...What model are you attempting to fill in the blanks for?

If just a series resistance, instead of a 1 KHz load, perhaps you could just slowly switch on, then off, say a 100ma constant current load.  Measure the avg batt voltage in both cases to find the battery "droop" & hence the avg impedance.  By averaging, the charger ripple completely disappears. This assumes the charger current doesn't change with the extra load, or that avg total battery current could always be measured.  So if you measure:

avg batt current is 1.0A & the avg batt voltage is 3.0V

avg batt current is 1.1A & the avg batt voltage is 2.98V

(3.0-2.98)/(1.1-1.0) gives 200milliohms    Of course, this may be too simplistic compared to your reality

At this point I have achieved some reasonable results (within a few mohm)

How do you know what your batt really is to say the results were good?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

"Perturb and Observe" could be a good search term ...

Top Tips:

1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...

awneil wrote:
Free DSP textbook: http://www.dspguide.com/

Yep. Currently reading that one. Bookmarked years ago. Now putting it to use.

avrcandies wrote:
How do you know what your batt really is to say the results were good?

It has been compared to another commercial impedance meter.

avrcandies wrote:
By "battery impedance", are you trying to model a: a) series resistance, b)frequency response c)dynamic response...What model are you attempting to fill in the blanks for?

Nothing so elaborate as the Randles Model or the like. No EIS.  The people looking at the data are unlikely to know how to analyse that. Just the real component (resistance) measured at 1kHz.  Though now that I think about, maybe I should consider taking the magnitude of the complex impedance at 1kHz instead. The difference might account for my discrepancies.

Last Edited: Wed. Jun 27, 2018 - 10:36 PM

Perhaps you can simply use a very narrow filter to detect only your 1KHz measurement signal (and response)...you mention the charger freqs (150-300Hz), as though you were trying to pass them.  Of course those can have harmonics that might appear at 1KHz & other freqs can be generated, since the battery is likely a nonlinear load.  That also means your 1KHz signal may spread somewhat into other freqs.     Do you hope to finish with an impedance vs freq result (ideal), or more of an overall single number?

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

The ‘usual’ solution is to use a lock-in amplifier.

avrcandies wrote:
you mention the charger freqs (150-300Hz), as though you were trying to pass them.

I wasn't originally interested in this but the client has subsequently asked for it.  My initial method was to measure it so I could subtract it from the charger + stimulus signal.  Which I would hope also takes care of any harmonic contributions at the frequency of interest (1kHz).  Since I measure it anyway, I figure I can provide the reading.  But alas the reading is dependent on the sampling window. (i.e. n full cycles)  My immediately obvious idea would be to take a frequency measurement with say input capture, then tailor the sampling window/rate to suit but that seems more like a brute force attack.  I was hoping a DFT/FFT could be used to provide an RMS charger ripple as well as discriminating the stimulus component (still by subtraction but now in the frequency domain) without the critical dependence on window length.  Is this possible?  Am I off on a completely wrong tangent?

Oh an overall single value output. Just the Re{Z} at this stage but yes a charger ripple voltage also per customer request.

Kartman wrote:
The ‘usual’ solution is to use a lock-in amplifier.

"Lock-in" conjured up all thoughts of RF, PLLs, FM quieting, etc, and whatdiya know; quadrature mixing fun!  That does looks pretty close to what I need, indeed probably will do the job. Maybe a little overkill.  I do not have a problem with signal-to-noise ratio.  At least not yet.  Initially, I was not all that interested in phase response either though that is looking somewhat misplaced the digger I deep.  Looks like another good avenue to consider.

Thanks

Steve,

Maybe my old brain is getting tired, but...

Are you injecting a sine wave?

If not, why not?

If you inject a sine wave, why can you not measure the Peak of the voltage signal across the battery to then simply calculate the RMS value, but why do you even need to calculate the RMS value if you measure the peak across the sense resistor, also?  (measuring real part of Z only)

If the injected sine wave is generated independently of the charger circuitry, (a valid assumption, likely), then one can measure 1000 peaks, (or whatever large number you like), on each signal, (pseudo-simultaneously, to account for phase shifts and other drifts in the signals), and the average energy of the charger ripple will tend towards 0, (sometimes adding to the voltage across the battery signal, sometimes subtracting from it...).

I'd definitely be feeding the two signals through a narrow band pass filter to then feed the ADC (s).  You likely have an op-amp driving the ADC anyway, so put it to good use.

Edit: Plus for this technique, you want to look at, and measure, only the 1 KHz sine wave, and not any DC and ripple component the signal is riding on.

You can, perhaps, also include an additional 10 mOhm resistor in series with the battery, which with a relay you can switch in or out of the circuit, (i.e. short circuit the additional resistor, or have it in the circuit).  This gives you an easy, built-in 10 mOhm calibration signal on top of your real signal.  (I'd not switch it with an analog switch, or a transistor switch to ground, etc., sometimes old school is best.)

Regarding the FFT question.  I think you would actually be implementing a DFT, (splitting hairs on this one...), but since you are only interested in one, known frequency, the Goertzel algo should be fine.  The advantage of the DFT is that it generates a spectrum of signal energies vs frequency, at the expense of computational complexity (and time).  You only need the 1 KHz signal energy, so Goertzel is perfect, and then also measure the total BW signal energy, using simple analog signal processing into the ADC.  But, I'd likely use the approach above, and not go this route.  Carefully calibrated spectrum analyzers from HP, , Techtronix, Fluke, Keithley, etc., are mega-expensive for a reason, although admittedly you are doing fixed, low frequency analysis, not wide bandwidth work.

JC

Last Edited: Fri. Jun 29, 2018 - 01:24 AM

Wouldn't you want the DC resistance as well? It seems like it would be an easy first step.

A) Average the battery current & voltage over several seconds, feeding each into a 10ms RC,...avg 100000 samples to smooth out any charger ripple (essentially remove it).

B) Apply 100ma signal to nudge battery current. Average the battery current & voltage over several seconds, feeding each into a 10ms RC,...avg 100000 samples to smooth out any charger ripple (essentially remove it).

C) Now calculate (change in volts)/(change in current) gives resistance at DC freq.

As an aside, would it be easier (or possible) to reduce the actual charging ripple, with some power LC filtering so that it becomes negligible?  Then any higher freq measurement would be easier.

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

schtevo wrote:
I thought I might seek some guidance from the brains-trust on whether its likely to be the right way to go

Direction?

..."Go West, young man" is a phrase, the origin of which is often credited to the American author and newspaper editor Horace Greeley ...

Isn't there only "One Direction"?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

Last Edited: Fri. Jun 29, 2018 - 07:25 PM

Free DSP textbook: http://www.dspguide.com/

Thanks for the link, but it doesn't work for me

Not Acceptable

An appropriate representation of the requested resource / could not be found on this server.

Maybe it got moved,

Edit -- you can't access the home page, but you can save the book by chapters (or buy on Amazon) --http://www.dspguide.com/pdfbook.htm

(sorry, didn't do an actual link)

hj

Last Edited: Sun. Jul 1, 2018 - 04:56 AM

And here I was thinking "No Direction"...

https://www.avrfreaks.net/comment/1389186#comment-1389186

Maybe we should pose differently next time fellas.

Last Edited: Mon. Jul 2, 2018 - 12:58 AM

Kartman wrote:
Some food for thought: http://www.cappels.org/dproj/dlm...

That's very clever! Thanks Russell.

It's something I've been meaning to try for some time. The lock in amp technique is applicable to quite a few things. I first stumbled across it when using strain gauges in order to get high gain and low noise and drift.

Apologies for the hiatus.

DocJC wrote:
Are you injecting a sine wave? If not, why not? If you inject a sine wave, why can you not measure the Peak of the voltage signal across the battery to then simply calculate the RMS value, but why do you even need to calculate the RMS value if you measure the peak across the sense resistor, also? (measuring real part of Z only)

I am indeed injecting a sine wave. And by injection I mean I am modulating an electronic load across the battery.  This device is powered from the batteries under test so an electronic dummy load allows me to separate (and measure) stimulus current from supply current.

I suppose it may been possible to calculate RMS by Vp/SQRT(2) but wouldn’t this be only if just the stimulus signal was applied.  There is the charger current present as well. This may or may not be a nice pure sine wave.

Additionally, I already had a “proper” RMS process going on so why not? (Well, clearly its dependence on frequency!)

DocJC wrote:
If the injected sine wave is generated independently of the charger circuitry, (a valid assumption, likely), then one can measure 1000 peaks, (or whatever large number you like), on each signal, (pseudo-simultaneously, to account for phase shifts and other drifts in the signals), and the average energy of the charger ripple will tend towards 0, (sometimes adding to the voltage across the battery signal, sometimes subtracting from it...).

Ok I’m trying to visualise this…

The signal is biased. (unipolar ADC) So I take a bunch of samples and I expect, due to the bias level, I’d probably have to search for peaks and troughs to get a Vp-p then what, a simple matter of /2 and /SQRT(2)?

I guess that would work with enough averaging. Alternatively, I suppose I could run the samples through an AC coupling filter first then just look for the peaks only? And yes, I see this method would be independent of frequency.  But how accurate with a nonsinusoid?

DocJC wrote:
I'd definitely be feeding the two signals through a narrow band pass filter to then feed the ADC (s). You likely have an op-amp driving the ADC anyway, so put it to good use.

The current signal processing does indeed comprise a band-pass filter. The front end is differential, AC coupled with high-pass cut-off around 482Hz, as well as low-pass cut-off at 7.5kHz(Diff) & 160kHz(CM) for RFI. All passive and both 1st order.  This is routed via a differential mux to an instrumentation amp, with digitally selectable gain, and then to the ADC by way of a 4th order Chebyshev active low-pass filter with fc bit over 1kHz. (Sallen-Key)

DocJC wrote:
Edit: Plus for this technique, you want to look at, and measure, only the 1 KHz sine wave, and not any DC and ripple component the signal is riding on.

This is essentially the point.  The filter was originally designed to remove a reasonable amount of 50Hz mains (before the goal posts were shifted to include measuring charger ripple). It certainly doesn’t remove the 150Hz I’ve encountered insitu so far, though I believe it does attenuate so I may need to equalise for that.  So, the desire is to filter? out the charger ripple by software as well as measure the charger ripple.

DocJC wrote:
Regarding the FFT question. I think you would actually be implementing a DFT, (splitting hairs on this one...), but since you are only interested in one, known frequency, the Goertzel algo should be fine. The advantage of the DFT is that it generates a spectrum of signal energies vs frequency, at the expense of computational complexity (and time). You only need the 1 KHz signal energy, so Goertzel is perfect, and then also measure the total BW signal energy, using simple analog signal processing into the ADC.

DFT is what I’m thinking; I have no real need for speed but I presume I could switch to FFT if I find I do.  I actually am interested in 2 signals. The 1kHz stimulus signal and the charger ripple of unknown frequency.  What is this you say about measuring the total BW energy? Is this a requirement of using Goertzel?

Here is a sample of the signals I'm getting:

y is ADC count, x is sample #

So out of a DFT I’m expecting to get something like this:

Where f is the charger ripple frequency (with some harmonics). The 1kHz bin only present when the stimulus is enabled.

How would I go about translating that to an rms charge and an rms stimulus?

Perhaps that’s yet to be revealed in “The Scientist and Engineer's Guide to DSP”.

It sure appears much easier to separate the components in the frequency domain.

Ok, back to the books!