Data acquisition, also known as data collection, refers to the process of gathering information from external sources and transferring it into a system for further processing. This technique is widely applied across various fields such as engineering, science, and automation. Common examples of data acquisition devices include cameras, microphones, and sensors that convert physical quantities like temperature, water level, wind speed, and pressure into electrical signals—either analog or digital. With the rapid growth of the internet industry, data acquisition has become increasingly essential in distributed systems, leading to significant advancements in how data is collected and processed.
Noise is an unavoidable issue in data acquisition systems. To address this, both analog and digital filtering techniques are commonly used. In this project, we focus on designing a digital filtering system using a microcontroller and the C programming language. The system is designed to handle random interference that often occurs in single-chip microcomputer-based data acquisition setups.
To simulate the data acquisition process, manual input was used to test several digital filtering algorithms that effectively reduce random noise. These algorithms include median filtering, arithmetic mean filtering, weighted average filtering, and the median average filtering method. Each algorithm was implemented with corresponding C code, and improvements were made to enhance their performance. Additionally, these methods were compared to highlight their strengths, limitations, and suitable application scenarios.
We also used Proteus for simulation and verification of the filtering techniques. Furthermore, analog-to-digital (AD) and digital-to-analog (DA) conversion was integrated into the system to facilitate data input and output.
### 1. Digital Filter Design Principles
There are multiple digital filtering techniques available, and we have selected several for implementation, including median filtering, arithmetic average filtering, weighted average filtering, and median average filtering. Below is a detailed explanation of each method.
#### 1.1 Median Filtering
Median filtering involves taking N consecutive samples of a parameter (typically an odd number), sorting them in ascending order, and selecting the middle value as the output. This approach is effective in eliminating pulse noise caused by sudden disturbances or sensor instability. The algorithm uses a bubble sort method to arrange the sampled values. The following is a sample code:
```c
#define N 11
char filter() {
char value_buf[N];
int 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];
}
```
This method works well for parameters like temperature and liquid level but is not ideal for signals such as flow rate or pressure due to its non-linear nature.
#### 1.2 Arithmetic Average Filtering
Arithmetic average filtering is suitable for signals with general random noise. It calculates the average of N samples to minimize the deviation between the estimated value and the actual signal. This method is particularly useful for signals that fluctuate around a central value, such as flow or level measurements. Here is a sample implementation:
```c
#define N 12
char filter() {
int sum = 0;
for(int count = 0; count < N; count++) {
sum += get_data();
}
return sum / N;
}
```
The effectiveness of this method depends on the value of N. A larger N increases smoothing but reduces sensitivity, while a smaller N improves responsiveness at the cost of stability.
#### 1.3 Weighted Average Filtering
Weighted average filtering assigns different weights to each sample, giving more importance to recent data. This helps improve the system's sensitivity to changes and reduces lag. The weights are typically fractions that sum to one, and the final result is calculated by multiplying each sample by its weight and summing them up. A common approach is to use integer weights that sum to 256 for easier computation.
```c
#define N 12
char code weight[N] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12};
int sum_weight = 78; // Sum of weights
char filter_5() {
int sum = 0;
for(int count = 0; count < N; count++) {
sum += get_data() * weight[count];
}
return sum / 256;
}
```
This method is especially useful for time-varying signals where the most recent data carries more significance.
#### 1.4 Median Average Filtering
Median average filtering combines the benefits of median and arithmetic average filtering. It takes N samples, removes the maximum and minimum values, and then computes the average of the remaining N-2 samples. This approach is effective for both slow and fast-changing signals.
```c
#define N 12
char filter() {
char value_buf[N];
int sum = 0;
for(int count = 0; count < N; count++) {
value_buf[count] = get_data();
}
// 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]) {
int temp = value_buf[j];
value_buf[j] = value_buf[j+1];
value_buf[j+1] = temp;
}
}
}
for(int count = 1; count < N-1; count++) {
sum += value_buf[count];
}
return sum / (N-2);
}
```
#### 1.5 Limiting Filter
Limiting filters compare the difference between two consecutive samples and determine whether the new sample is valid based on a predefined threshold. If the change exceeds the threshold, the previous sample is used instead.
```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;
}
}
```
This method is ideal for slowly changing signals like temperature or position. The threshold value ΔY is usually determined empirically or based on the maximum expected change rate.
Utility Scale Energy Storage,Solar Energy System,Solar Photovoltaic Panels,Photovoltaic Pv Systems
EMoreShare International Trade (Suzhou) Co., Ltd , https://www.emoreshare.com