Data acquisition, also known as data collection, refers to the process of gathering information from external sources and inputting it into a system through an interface. This technique is widely used across various industries. For instance, cameras and microphones serve as common data acquisition tools. The collected data often represents physical quantities that have been converted into electrical signals, such as temperature, water level, wind speed, and pressure. These signals can be either analog or digital in nature. With the rapid development of the Internet industry, data acquisition has become increasingly important in fields like distributed systems, leading to significant advancements in how data is captured and processed.
Noise is a common issue in data acquisition systems. To address this, both analog and digital filtering techniques are employed. In this project, we use a microcontroller along with C programming to design and implement a digital filtering system. The focus is on handling random interference, which frequently occurs in single-chip microcomputer-based data acquisition systems. By simulating the data acquisition process manually, we test several digital filtering algorithms designed to mitigate such interference. We also provide corresponding C code implementations for these algorithms.
Among the methods tested, the median filter and the median average filter were improved upon. A comparison of these filtering techniques was conducted, highlighting their respective applications, limitations, and key considerations. Additionally, we used Proteus to simulate and verify the performance of these filters. We also integrated Analog-to-Digital (AD) and Digital-to-Analog (DA) conversion modules to collect and output data effectively.
### 1. Digital Filter Design Principles
There are multiple types of digital filtering methods available. Here, we will explore and implement a few commonly used ones, such as median filtering, arithmetic average filtering, weighted average filtering, and others. Each method has its own advantages and is suitable for different scenarios.
#### 1.1 Median Filtering
Median filtering works by taking N consecutive samples of a parameter, typically an odd number. The samples are then sorted in ascending order, and the middle value is selected as the filtered result. This method is essentially a sorting algorithm, and in our implementation, we use bubble sort to arrange the data. Since bubble sort compares adjacent elements and swaps them if they are in the wrong order, it ensures the correct sequence.
The sample code for this algorithm is as follows:
```c
#define N 11
char filter() {
char value_buf[N];
char count, i, j, temp;
for(count = 0; count < N; count++) {
value_buf[count] = get_data();
}
for(i = 0; i < N - 1; i++) {
for(j = 0; j < N - 1 - i; j++) {
if(value_buf[j] > value_buf[j + 1]) {
temp = value_buf[j];
value_buf[j] = value_buf[j + 1];
value_buf[j + 1] = temp;
}
}
}
return value_buf[N / 2];
}
```
Median filtering is effective in suppressing pulse noise caused by accidental factors or instability in the sampling device. It performs well for parameters like temperature and liquid level but is less suitable for data such as flow rate or pressure.
#### 1.2 Arithmetic Average Filtering
Arithmetic average filtering is ideal for signals with general random noise. This type of signal fluctuates around a central value, making it unsuitable to rely on a single sample. The algorithm calculates the average of N sampled values, minimizing the sum of squared deviations between each sample and the mean.
Here’s a sample implementation:
```c
#define N 12
char filter() {
int count;
int sum = 0;
for(count = 0; count < N; count++) {
sum += get_data();
}
return sum / N;
}
```
This method is effective for smoothing signals with random fluctuations. The degree of smoothing depends on the value of N. Larger N values produce smoother results but reduce sensitivity, while smaller N values increase responsiveness but may not smooth as effectively. Choosing an appropriate N is crucial for balancing performance and computational efficiency.
#### 1.3 Weighted Average Filtering
Unlike arithmetic average filtering, where all samples are treated equally, weighted average filtering assigns different weights to each sample. This allows newer samples to have a greater influence on the final result, improving the system's responsiveness to sudden changes.
In this approach, each sample is multiplied by a weight, and the weighted sum is divided by the total weight. The weights are usually fractions that add up to one, ensuring the final result is normalized.
An example implementation is:
```c
#define N 12
char code weight[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int total_weight = 78;
char filter() {
int sum = 0;
for(int i = 0; i < N; i++) {
sum += get_data() * weight[i];
}
return sum / total_weight;
}
```
This method enhances the system's ability to detect trends and improves sensitivity to current data points.
#### 1.4 Median-Average Filtering
This hybrid method combines the benefits of median and arithmetic average filtering. It takes N samples, removes the highest and lowest values, and computes the average of the remaining N-2 values. This helps reduce the impact of outliers while still maintaining some smoothing.
Here’s a sample implementation:
```c
#define N 12
char filter() {
char value_buf[N];
int sum = 0;
for(int i = 0; i < N; i++) {
value_buf[i] = get_data();
}
// Sort the array using bubble sort
for(int i = 0; i < N - 1; i++) {
for(int j = 0; j < N - 1 - i; j++) {
if(value_buf[j] > value_buf[j + 1]) {
char temp = value_buf[j];
value_buf[j] = value_buf[j + 1];
value_buf[j + 1] = temp;
}
}
}
// Exclude max and min, compute average of the rest
for(int i = 1; i < N - 1; i++) {
sum += value_buf[i];
}
return sum / (N - 2);
}
```
This method is particularly effective for both slow and fast-changing signals, offering better filtering performance than either median or average filtering alone.
#### 1.5 Limiting Filter
The limiting filter works by comparing the difference between two consecutive samples. If the absolute difference exceeds a predefined threshold, the new sample is considered invalid and the previous one is used instead. This method is useful for signals that change slowly, such as temperature or position measurements.
Here’s a sample implementation:
```c
#define A 10
char last_data;
char filter_1() {
char new_data = get_data();
if (abs(new_data - last_data) > A) {
return last_data;
} else {
last_data = new_data;
return new_data;
}
}
```
The threshold value ΔY is usually determined empirically based on the maximum expected change in the signal over the sampling period. This method is simple and effective for filtering out random noise in slow-changing signals.
12 volt lithium marine battery,optima marine battery,lithium ion marine battery,autozone marine battery,lithium deep cycle marine battery,12v battery deep cycle marine
EMoreShare International Trade (Suzhou) Co., Ltd , https://www.emoreshare.com