I had an application running well a couple of days ago. Suddenly, I see weird values in my board when I am computing a different function, for averaging the data in a vector.
The code I have implemented is:
int16_t algo::Process(int input)
{
bool detection = false;
bool excitation = false;
uint8_t event = 0;
int32_t debug_avgFilter = 0;
int32_t debug_stdFilter = 0;
int32_t debug_threshold = 0;
int32_t output = 0;
for (int i = lag_ - 1; i > 0; i--)
{
backwardBuffer[i] = backwardBuffer[i - 1];
filteredY[i] = filteredY[i - 1];
}
backwardBuffer[0] = input;
filteredY[0] = mean(backwardBuffer, lag_);
output = filteredY[0];
return output;
}
// Vector functions
// Calculates the mean of a vector given the size of the array
int16_t algo::mean(const int16_t *y, int16_t size)
{
float sum = 0.0f;
for (int i = 0; i < size; ++i)
{
sum += y[i];
}
return sum / size;
}
The front of my application is through this function:
#include "ap_axi_sdata.h"
#include "hls_stream.h"
#include "algo.h"
void example(hls::stream< ap_axis<32,2,5,6> > &A,
hls::stream< ap_axis<32,2,5,6> > &B)
{
#pragma HLS INTERFACE axis port=A
#pragma HLS INTERFACE axis port=B
#pragma hls interface s_axilite port=return
algo algo_instance(2000);
ap_axis<32,2,5,6> tmp;
ap_axis<32,2,5,6> tmp2;
while(1)
{
A.read(tmp);
tmp.data = algo_instance.Process(tmp.data.to_int());
B.write(tmp);
//tmp2.data = 0;
//B.write(tmp2);
if(tmp.last)
{
break;
}
}
}
and the block design is:
I expect to have as output the mean of the signal, basically the moving window average. I am using a size of 200 samples and a sampling frequency of 2KHsz, that is a 1% of the fs for averaging. I however, get very weird output:
I have been literally racking my brain wit hthe issue. If I set an output value of, let’s say 500, I have that output correctly shown in the plot. But when I use the mean function, the output is all 1e09.
Any ideas? Suggestions? I am really stuck with this.