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

ADC Median Filter

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







ADC Median Filter
PostPosted: Tue Apr 29, 2003 8:46 am     Reply with quote

I have a program that measures wheatstone bridge loadcells with a 16 Bit A/D. I would like to average 10 to 20 readings to smooth out the result and have seen several references to median filters in the list. I have spent the last 40 minutes searching for any kind of code snippets to get me coding in the right direction, but to no avail. I have receintly switched from a basic compiler to PCWH and am new to the C language. Does anyone have a code snippet for the median filter or a link on how to implement such a filter. The reading that I am getting from the ADC is stored in a int32 variable called value. Thanks in advance....
___________________________
This message was ported from CCS's old forum
Original Post ID: 14043
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

Re: ADC Median Filter
PostPosted: Tue Apr 29, 2003 10:14 am     Reply with quote

<font face="Courier New" size=-1>:=I have a program that measures wheatstone bridge loadcells with a 16 Bit A/D. I would like to average 10 to 20 readings to smooth out the result and have seen several references to median filters in the list. I have spent the last 40 minutes searching for any kind of code snippets to get me coding in the right direction, but to no avail.
---------------------------------------------------------

There's code in the archives. Here's the link.
<a href="http://www.pic-c.com/forum/general/posts/13211.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/13211.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/13211.html</a></a>

But here's how to use the Search engine of this forum.
Go to the Search page, here:
<a href="http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL" TARGET="_blank"> <a href="http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL" TARGET="_blank">http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL</a></a>

1. Type in your keywords in the top box.
2. Click the box for <b>Search in message body.</b>
3. Set the date range in the bottom boxes, so it says
Search from <b>300</b> to 0 days.
4. Leave all other boxes in their default state.

If you do those four things, you will get good results.
Sometimes, you might want to increase the search range
to 600 days. (This new forum started on August 24, 2001).




--

</font>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14055
William Meade
Guest







Re: ADC Median Filter
PostPosted: Tue Apr 29, 2003 10:37 am     Reply with quote

<html>
<body>
<pre>

Thanks for the quick reply and info on how to use the search
engine... I always try searching the list first so I don't
ask the same questions that have been asked before.

:=<font face="Courier New" size=-1>:=I have a program that
measures wheatstone bridge loadcells with a 16 Bit A/D. I
would like to average 10 to 20 readings to smooth out the
result and have seen several references to median filters in
the list. I have spent the last 40 minutes searching for any
kind of code snippets to get me coding in the right direction,
but to no avail.
:=---------------------------------------------------------
:=
:=There's code in the archives. Here's the link.
:= <a href="http://www.pic-c.com/forum/general/posts/13211.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/13211.html" TARGET="_blank"> <a href="http://www.pic-c.com/forum/general/posts/13211.html" TARGET="_blank">http://www.pic-c.com/forum/general/posts/13211.html</a></a></a>
:=
:=But here's how to use the Search engine of this forum.
:=Go to the Search page, here:
:= <a href="http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL" TARGET="_blank"> <a href="http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL" TARGET="_blank"> <a href="http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL" TARGET="_blank">http://www.pic-c.com/cgi-bin/anyboard.cgi?fvp=/general&cmd=qL</a></a></a>
:=
:=1. Type in your keywords in the top box.
:=2. Click the box for <b>Search in message body.</b>
:=3. Set the date range in the bottom boxes, so it says
:= Search from <b>300</b> to 0 days.
:=4. Leave all other boxes in their default state.
:=
:=If you do those four things, you will get good results.
:=Sometimes, you might want to increase the search range
:=to 600 days. (This new forum started on August 24, 2001).
:=
:=
:=
:=
:=--
:=
:=</font>

</html>
</body>
</pre>
___________________________
This message was ported from CCS's old forum
Original Post ID: 14057
chas
Guest







Re: ADC Median Filter
PostPosted: Tue Apr 29, 2003 11:57 am     Reply with quote

:=I have a program that measures wheatstone bridge loadcells with a 16 Bit A/D. I would like to average 10 to 20 readings to smooth out the result and have seen several references to median filters in the list. I have spent the last 40 minutes searching for any kind of code snippets to get me coding in the right direction, but to no avail. I have receintly switched from a basic compiler to PCWH and am new to the C language. Does anyone have a code snippet for the median filter or a link on how to implement such a filter. The reading that I am getting from the ADC is stored in a int32 variable called value. Thanks in advance....

In a recent application I needed to have several running averages of a number of pressure transducers. I created a stucture that holds the data in an array, the index into the data array, the running sum, and the average.

// declare the structure type
struct avg_pres
{
long pressure_reading[16];
int index;
long running_sum;
signed long int average;
};

// declare and initialize the 2 pressure structures
struct avg_pres pressure1 ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
struct avg_pres pressure2 ={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};

Then I use a function to update the data and the average:

void update_running_average (struct avg_pres *sptr, int external_adc_channel)
{
// subtract the oldest reading from the running sum
sptr->running_sum = sptr->running_sum - sptr->pressure_reading[sptr->index];
// read the adc channel for this transducer and store in array
// this is the latest reading
sptr->pressure_reading[sptr->index] = read_ext_adc(external_adc_channel);
// add the latest reading to the running sum
sptr->running_sum = sptr->running_sum + sptr->pressure_reading[sptr->index];
// calculate the average and cast to a signed long int
sptr->average = (signed long int)((sptr->running_sum)/16);

// update the index - points to the next element to update
if(++(sptr->index) > 15)
{
sptr->index = 0;
}
return;
}

The average is a signed long int because it is required in other calculations.

Then in the code I just call the function with the appropriate structure pointer:

update_running_average (&pressure1, PRESSURE1_ADC);
update_running_average (&pressure2, PRESSURE2_ADC);

Hope this helps.
___________________________
This message was ported from CCS's old forum
Original Post ID: 14060
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: ADC Median Filter
PostPosted: Thu May 01, 2003 3:27 pm     Reply with quote

:=I have a program that measures wheatstone bridge loadcells with a 16 Bit A/D. I would like to average 10 to 20 readings to smooth out the result and have seen several references to median filters in the list. I have spent the last 40 minutes searching for any kind of code snippets to get me coding in the right direction, but to no avail. I have receintly switched from a basic compiler to PCWH and am new to the C language. Does anyone have a code snippet for the median filter or a link on how to implement such a filter. The reading that I am getting from the ADC is stored in a int32 variable called value. Thanks in advance....


This one is fast and small but not a median filter. It's more like an RC filter but it's great for noise rejection.
Current_reading = Read_ADC;
Filtered_reading = (Current_reading + (Filtered_reading * 15)) /16;
___________________________
This message was ported from CCS's old forum
Original Post ID: 14131
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