You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
939 B
C++
31 lines
939 B
C++
4 years ago
|
/**
|
||
4 years ago
|
* 5_fir_differentiator.cpp
|
||
4 years ago
|
* Written by Clyne Sullivan.
|
||
|
*
|
||
4 years ago
|
* Does an FIR differentiation on the incoming signal, so that the output is representative of the
|
||
4 years ago
|
* rate of change of the input.
|
||
|
* A scaling factor is applied so that the output's form is more clearly visible.
|
||
|
*/
|
||
|
|
||
|
adcsample_t *process_data(adcsample_t *samples, unsigned int size)
|
||
|
{
|
||
|
constexpr int scaling_factor = 4;
|
||
4 years ago
|
static adcsample_t output[SIZE];
|
||
4 years ago
|
static adcsample_t prev = 2048;
|
||
|
|
||
|
// Compute the first output value using the saved sample.
|
||
4 years ago
|
output[0] = 2048 + ((samples[0] - prev) * scaling_factor);
|
||
4 years ago
|
|
||
|
for (unsigned int i = 1; i < size; i++) {
|
||
|
// Take the rate of change and scale it.
|
||
|
// 2048 is added as the output should be centered in the voltage range.
|
||
4 years ago
|
output[i] = 2048 + ((samples[i] - samples[i - 1]) * scaling_factor);
|
||
4 years ago
|
}
|
||
|
|
||
4 years ago
|
// Save the last sample for the next iteration.
|
||
|
prev = samples[size - 1];
|
||
|
|
||
|
return output;
|
||
4 years ago
|
}
|
||
|
|