CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Off Topic - Algorithm for noise

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Doug99



Joined: 13 May 2004
Posts: 6

View user's profile Send private message

Off Topic - Algorithm for noise
PostPosted: Thu May 13, 2004 10:13 am     Reply with quote

Hello ladies and gentlemen... Very Happy I have a problem figuring out how to go about this.

I am measuring a PWM signal from an radio controlled receiver (variable from 1ms - 2ms) and I would like to create an algorithm to detect an erratic signal from a stable one.

I am measuring the pulses and storing each one as an 8bit value. I can hold about twenty values in a buffer and analyze them in between pulses. I thought I could use statistical calculations like mean, mode, variance, etc. but I am not a math wizard. Is there a better way to sniff out an erratic signal from a stable (but variable) one?

If anyone can help, I'd really appreciate it. If it works, I'll post the code in the code form.

Thank you,

Doug
valemike
Guest







PostPosted: Thu May 13, 2004 10:18 am     Reply with quote

In the past, i've sampled 5 times, put the values in ascending order, then take the average of the 3 middle ones.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu May 13, 2004 10:45 am     Reply with quote

From the net:
"The median filter is able to remove impulsive noise without smoothing
edges, as a linear filter would do."

Note that MS Excel has a median filter. You can load your data into
Excel and model it. Then write a C function that will do the same thing.
Compare the output of your function to the results from Excel to make
sure you're doing it the same way.
Doug99



Joined: 13 May 2004
Posts: 6

View user's profile Send private message

PostPosted: Thu May 13, 2004 12:46 pm     Reply with quote

Thanks for your replies!

I looked up median filters and found tons of info (even found an example in Microchip assembler). I am wondering how I can modifiy or create one to give a boolean output. As in 'yes' there is noise or 'no' there is not. It may not be so easy to give a true or false answer as it would be to simply eliminate the noise. Any ideas?
I apologize if this isn't making any sense.

Thanks again,

Doug
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Thu May 13, 2004 5:48 pm     Reply with quote

Filters, like the median filter, are good at removing noise - which really doesn't sound like what you want. Unless you filter the signal and use the filtered value to test against new values and call anything outside some bounds as 'noise'.

Can you supply more info?

- What is your 'good' signal like? Is it constant, varying, can it jump to a new level and still be considered valid (median filter can handle this well).

- What is the noise like? Does it have a different frequency component than the signal?

- At any instant do you have just good signal or just noise? Or is it noise on top of a good signal? The first would be like signal detection (it's there or not), the second is trying to extract signal from signal + noise.

Try to describe what needs to happen. If you can't it will be hard to build hardware and/or software to do it. If you can decribe it then you may be able to do something.

- SteveS
Doug99



Joined: 13 May 2004
Posts: 6

View user's profile Send private message

PostPosted: Fri May 14, 2004 10:04 am     Reply with quote

Hi Steve, I'll try to answer your questions the best I can.

Quote:
What is your 'good' signal like?


It will be varying but not random. If I were to collect all of the values and plot them on a graph (something I am working on right now) it would look smooth without any sharp peeks or valleys. Values can change at different rates but I would expect those changes to be fairly linear.


Quote:
What is the noise like?


I haven't had a chance to collect and analyze the data but I'm predicting I'll see a scatter of random points around the 'good' signal on a graph. I can artificiallly create some electrical noise which will make the servo jump and jitter all over the place. It is this kind of noise I am trying to detect. I have altered my program to send every pulse it receives as an 8bit value to a terminal over rs232. I'll import the data into Excel and try different algorithms as suggested by PCM programmer.

Quote:
At any instant do you have just good signal or just noise?


It will be good signal mixed with noise. There inlies the problem. I need to distinguish between 'good' and 'good with noise'. Its not imposible, but may prove to be more trouble than it is worth in the long run.

Thanks,

Doug
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri May 14, 2004 11:24 am     Reply with quote

If all you want is a Good/Bad how about finding the min and max and see how far they are apart? The math is dirt simple and if you just keep the min, max, and sum you don't even need the five bytes it would take to store the values. At the end divide the sum by the number of samples to get an average. Or better still if you take the sum, subtract the min and max, then divide by num-2 you get an average without outlyers. I do the latter all the time.
_________________
The search for better is endless. Instead simply find very good and get the job done.
SteveS



Joined: 27 Oct 2003
Posts: 126

View user's profile Send private message

PostPosted: Fri May 14, 2004 12:14 pm     Reply with quote

Along the same lines, you can filter the input signal using one of a variety of methods. Decide on a window that separates good signal from noise ( the tricky part). If the new sample is outside the window then it's noise. What you do then I'm not sure. Depends on what you are after.

Do you really want to do something with the noise data or are you just trying to get rid of it?

If you want to get rid of it, then 'just' choose the right filter. The median filter is very good when you get short, large spikes of noise. A low pass filter works well if the noise magnitude is small compared to the signal. If the noise completely masks the signal then you need a lock-in amplifier.

- SteveS
dfnr2



Joined: 26 Dec 2003
Posts: 2

View user's profile Send private message

PostPosted: Wed May 19, 2004 5:43 pm     Reply with quote

An autocorrelation function is numerically easy to compute, and its shape will give an idea how much signal vs. random noise is present. I believe excel has the ability to compute and plot autocorrelation functions. You may want to check your library or local tech bookstore for books on engineering communications or on spectral analysis. You could also try google. If you want to differentiate between different signal types in noise, you may want to look into Wiener or Kalman filters.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group