Previous in Forum: CD Player Won't Play CDs   Next in Forum: copper cable current?
Close
Close
Close
22 comments
Rate Comments: Nested
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65

Undersampling average

10/26/2009 6:37 PM

OK, so here's my problem. Let's say I have a motor running on a fixed frequency PWM of 30KHz. I use a current sense resistor to sense the motor current, and I get a voltage that looks more or less like my PWM waveform. I want to know the average value of my current. (Let's assume I forgot to do the obvious thing and put an analog filter on this signal before I ran it through a mux to an A/D.)

I'm taking an 10uS averaged sample once every millisecond.

I'm horribly undersampling the current sense voltage, but I'm not concerned with the frequency content of the signal, only the average (DC) component.

We know from Fourier analysis that the DC coefficient is independent of frequency. I know that if I take enough samples and average them I'll have the DC component of my current. The question is, how many samples is "enough"? How do I determine the amount of ripple I'll have in my average values, and how does that relate to the number of samples I average?

(Assume my sampling rate is not synchronous to the PWM frequency - a requirement for this sort of undersampling.)

Also assume that I already googled "undersampling average" and went through the first several pages of hits.

Any help?

Register to Reply
Pathfinder Tags: digital filters undersampling
Interested in this topic? By joining CR4 you can "subscribe" to
this discussion and receive notification when new comments are added.
Anonymous Poster
#1

Re: Undersampling average

10/26/2009 7:49 PM

If it were me, I would use the basic PWM clock signal as a trigger, and make sure my 10 us samples were on the peaks. You can do this using a 74123 dual one-shot. Then, knowing the duty cycle, (from the trigger signal), you could calculate the average, or direct current.

emc_c

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#2
In reply to #1

Re: Undersampling average

10/26/2009 7:55 PM

That actually would work, but I'm looking for a more general purpose solution. I have 12 motors, each operates at a different PWM frequency (I do this to reduce EMI).

Register to Reply
Guru
United Kingdom - Member - Not a New Member Hobbies - Musician - New Member Hobbies - Fishing - New Member

Join Date: May 2006
Location: Reading, Berkshire, UK. Going under cover.
Posts: 9684
Good Answers: 468
#3
In reply to #2

Re: Undersampling average

10/26/2009 8:42 PM

"(I do this to reduce EMI)"

Does that really work? I haven't looked into it myself, but for example the L297 step motor controller datasheet states "To avoid switching noise on the ground plane all drivers should be synchronized and the chopper rate is therefore determined by the largest motor in the system" - so the chip has a SYNC I/O pin.

I assumed it was to stop sum & difference frequencies getting all over the place.

Sorry this isn't much help with your question. Bit late tonight for my little brain to work that hard.

__________________
"Love justice, you who rule the world" - Dante Alighieri
Register to Reply Off Topic (Score 5)
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#4
In reply to #3

Re: Undersampling average

10/27/2009 9:15 AM

It depends what you're trying to do. In our case, we're driving a number of motors outside of our EMI enclosure, on the ends of cables several feet long. These cables will tend to radiate EMI at the switching frequency and harmonics. If all the motors were locked together and switching on the same clock edge, there would be a huge energy spike right at the switching frequency - say 30KHz. If I run each motor at a slightly different frequency, say 28 KHz, 29KHz, etc., then I'll still generate the same amount of EMI, but I'll have a number of smaller spikes at each frequency, instead of one big one. To meet our EMI spec we have to have all energy below a certain line across all frequencies, so the one large spike would kill us, but several smaller spikes might be OK.

We power the motors with 4 dc/dc converters connected in parallel - in this case we do sync the converters. We do this not for ground noise, but so the 4 converters will current share on a pulse by pulse basis.

I'm not sure what your data sheet is getting at.

Register to Reply Off Topic (Score 5)
Commentator

Join Date: Mar 2009
Location: Southern California
Posts: 97
Good Answers: 15
#5

Re: Undersampling average

10/28/2009 1:25 AM

If your signal is 30kHZ and you are taking a 10uS sample every millisecond, you don't really have a way of knowing whether you are sampling during the "on" or "off" phase of the pulse. Whichever it is, since your signal frequency is an integer multiple of your sample frequency, the sample will continue to occur at the same part of the signal wave: in this case, for every 30 signal pulses you are taking one sample. If the very first sample occurs while the pulse is "on" then every subsequent pulse will also occur when the pulse is "on" and you won't have an average.

If you want to be more accurate with no ripple, then you need to sample at a rate greater than 60kHZ. Google "Nyquist rate" for more info.

If a sample rate that high is not an option, then at least change your sample frequency to a rate--say, 0.91ms--for which the signal is not an integer multiple. That way you would be sampling at different parts of the waveform. Then you simply need to calculate how many samples you could take to get an even distribution across the waveform. If you used a 0.91ms sample rate, then each sample would be shifted by 3/10 of a wavelength; so after 30 samples you would have cycled through (so of course your ripple frequency would be 1/(.00091*30)=36.6Hz. If you want more accuracy, use a 0.909ms sample rate (100 samples to cycle through). That gives you a ripple frequency of 11Hz. The more irrational your sample rate is, the lower your ripple frequency, but you really want a ripple of zero, which can only be achieved by using a frequency more than twice the signal frequency.

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#7
In reply to #5

Re: Undersampling average

10/28/2009 9:53 AM

I'm sorry you didn't read my original post better. The assumption is that the sampling frequency is not synchronous with the switching frequency, and of course, 30KHz and 10uS are not integrally related, and the idea is to employ undersampling, not Nyquist or Shannon sampling.

But thanks for taking the time to respond.

Register to Reply
Anonymous Poster
#6

Re: Undersampling average

10/28/2009 2:18 AM

Here's a simplistic thought--if your samples are asynchronous to the PWM output, run samples through a FIFO pipeline (dynamically configurable?) of length greater than a number of PWM cycle times.

Then calculate running averages based on strings of samples that overlap in the pipeline (maybe 10-25% overlap?). These will be out of phase with the motors' current.

Compare the n-th average with previous averages and call it valid when the rate of change of averages slows down "sufficiently".

Like ending a software iteration when the successive results differ by a sufficiently small amount from the previous value.

Long term the DC average, as you said, should be stable. So the average of samples should stabilize too shouldn't it?

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#8
In reply to #6

Re: Undersampling average

10/28/2009 9:56 AM

Yes - this approach would work, as would just averaging the samples. The question I'm asking is, how to relate the number of samples to when the rate of change of averages slows down "sufficiently". After studying the problem for an evening, I've about decided that whatever the answer is, it's many more samples than I'm prepared to take.

Thanks.

Register to Reply
Anonymous Poster
#9

Re: Undersampling average

10/28/2009 11:16 AM

What kind of motors are they? steppers, sych, induction motors?

If they were for example squirrel cage running on VFDs, you could add a capacitor to your shunt resistor's output and measure a simple sine wave, thus being able to calculate RMS or whatever current values you need? Maybe?

Yahlasit

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#10
In reply to #9

Re: Undersampling average

10/28/2009 11:46 AM

They are brush DC motors.

Register to Reply
Power-User

Join Date: Dec 2008
Location: Anthem, AZ
Posts: 392
Good Answers: 8
#11

Re: Undersampling average

10/28/2009 12:08 PM

Guest #1 has a good plan. Since you said the V signal (proportional to current) looks like the PWM waveform, you must be using a scope. Trigger the scope on the PWM clock as Guest #1 suggested, and use the scope's delay control to assure you are sampling on the peaks of each pulse. You can use the scope's AVERAGE measurement for the final result. Many scopes have a statistical distribution routine so that you can see the mean and standard deviation to help decide when to take the average reading.

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#12
In reply to #11

Re: Undersampling average

10/28/2009 12:11 PM

ummm - thanks.

Register to Reply
Guru
Engineering Fields - Electrical Engineering - Analog and Digital Circuit Design Engineering Fields - Electromechanical Engineering - Transformers, Motors & Drives, EM Launchers Engineering Fields - Engineering Physics - Applied Electrical, Optical, and Mechanical

Join Date: Jan 2008
Location: NY
Posts: 1207
Good Answers: 119
#13

Re: Undersampling average

10/28/2009 1:17 PM

Do you know the mux switch resistance (when ON) and the sample and hold capacitance of the A/D?

Are you using a PIC micro A/D for this application?

We ran into several interesting problems with multiplexed A/D conversions that were all easily solved by the addition of simple, and properly scaled, RC filters. That is NOT the answer to your question, but it may be the answer you need to get accurate measurements.

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#14
In reply to #13

Re: Undersampling average

10/28/2009 1:38 PM

Oh sure - and that's what we'll end up doing. The signals will be passed through active lowpass filters and what we'll end up sampling is very close to DC. This was just an interesting (to me) question that came up, and I was curious if anyone had any insight into this kind of undersampling technique, since I've only ever been able to find one other instance of it being used.

Register to Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#15
In reply to #14

Re: Undersampling average

10/30/2009 4:46 AM

OK... First thought was to use a resistor/capacitor low pass filter to do the averaging. BUT since you are going to run it directly to an A/D, I would run the digital words through a FIR (Finite Impulse Response) averaging filter. This is like a shift register say N samples long. Ignoring word size for the moment, each section of shift register is multiplied by 1/N and the output of the multiplications are all summed (accumulated). If you get tricky and use binary N, 1,2,4,8... the multiplys can be done by shifting only.

Bill

Register to Reply
Guru
Hobbies - HAM Radio - New Member

Join Date: Oct 2006
Location: Vancouver (not BC) Washington (not DC) US of A
Posts: 1261
Good Answers: 12
#16
In reply to #15

Re: Undersampling average

10/30/2009 5:22 AM

.5, .25, .125, .0625... etc.

I don't know your experience with DSP, but a book on the subject might make my comments more meaningful.

This gives what is known as a running average which means that samples which run off the end of the shift register are no longer part of the average.

Have fun...

Bill

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#17
In reply to #15

Re: Undersampling average

10/30/2009 9:46 AM

An FIR, or more likely a simple averager is what we would run the samples to. My question is, how many samples are required to reduce the ripple in such a measurement to an acceptable level, based on the undersampling conditions listed in my original post. Undersampling is not something that's described much in the literature, as least not in this context of recovering DC information, hence my question.

Register to Reply
Guru
Panama - Member - New Member Hobbies - CNC - New Member Engineering Fields - Marine Engineering - New Member Engineering Fields - Retired Engineers / Mentors - New Member

Join Date: Dec 2006
Location: Panama
Posts: 4273
Good Answers: 213
#18

Re: Undersampling average

10/30/2009 9:50 PM

I have faced a similar problem with trying to remove noise from an undersampled data stream- although the data was probably far noisier than what you are dealing with. I went through a period where I would strip spikes from the data, then pass it through an FFT and strip whatever frequency spikes I could find, then repeat the process until I got close to what I was looking for- which was the underlying signal that I wanted to strip from the noise until I had nothing but gaussian noise left. Ultimately, I found that, for my case, I needed about 38 time-synchronized samples to generate the same underlying signal from the data. Any more had no detectable effect on the finesse of the final results, and 35 averages still left recognizable ripple in the data (note that the underlying signal was repeating, but not DC, not sinusoidal and drifted somewhat over time). The rule held for data extracted from two totally different systems with the same measurement equipment.

Unfortunately, I have not been able to discover anything in the literature that will give me a relationship that would help me predict how many sample streams need to be averaged as a function of undersampling frequency, noise level (in my case, on the order of 5% of signal magnitude), or any other deterministic measure. There must be some ideas out there, but I haven't found them. I have encountered quite a bit on aliasing, and there should be some way to account for this, or extract higher-frequency information from the "folding" nature of the spectrum, but I haven't discovered anything yet.

But I ramble. The number you are looking for is 38. Or, that was the number that worked in my case. I suspect each system will have it's own number...

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#20
In reply to #18

Re: Undersampling average

11/02/2009 9:41 AM

Thanks.

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Oct 2007
Location: Sour Lake, TX 30°08'59.68"N 94°19'42.81"W
Posts: 675
Good Answers: 13
#19

Re: Undersampling average

10/31/2009 9:02 AM

Did you think about using analog approach? At 33 usec rate you can get a very smooth variable (and pretty fast proportional with your dc) voltage which, sampled at 1 msec rate give you the necessary data.

__________________
Bridge rule #1: Nobody is as good as he thinks about himself nor as dumb, as his partner thinks...
Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Sep 2006
Location: El Lago, Texas, USA
Posts: 2639
Good Answers: 65
#21
In reply to #19

Re: Undersampling average

11/02/2009 9:42 AM

Yeah - analog works great. I was looking for a digital approach. BTW, where is Sour Lake?

Register to Reply
Guru
Engineering Fields - Electrical Engineering - New Member

Join Date: Oct 2007
Location: Sour Lake, TX 30°08'59.68"N 94°19'42.81"W
Posts: 675
Good Answers: 13
#22
In reply to #21

Re: Undersampling average

11/02/2009 10:22 AM

I escaped from Houston, two years ago. Sour Lake is 10 miles west of Beaumont, on hwy 105. Some 2000 souls, a golf course (I've never been on it), in a part of the Big Thicket Forest. If you want to receive radio waves, you need to rise an antenna over the trees (100 ft or so).

About the digital approach, I would need more than one sample each 1 msec, unless the values fluctuate with a frequency less than 500 Hz. And I would do (digitally) a moving average (ten samples, averaged than discard the oldest of ten and add a new sample and average them then discard again the oldest and add a new one and so on). But I am sure that you have already thought of that.

__________________
Bridge rule #1: Nobody is as good as he thinks about himself nor as dumb, as his partner thinks...
Register to Reply
Register to Reply 22 comments
Copy to Clipboard

Users who posted comments:

Anonymous Poster (3); bhankiii (10); cwarner7_11 (1); indel (2); JohnDG (1); Mitsurati (1); mjb1962853 (1); Sciesis2 (2); WoodwardDL (1)

Previous in Forum: CD Player Won't Play CDs   Next in Forum: copper cable current?

Advertisement