Skip to content

Commit

Permalink
new additions
Browse files Browse the repository at this point in the history
  • Loading branch information
Ruben Noroian committed Nov 24, 2024
1 parent bab8efe commit 25814f7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 24 deletions.
19 changes: 18 additions & 1 deletion middleware/include/high_pass.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,23 @@

#include <stdio.h>

int high_pass(int alpha, int scale);
typedef struct {
//Function Parameters
float alpha;
float scale;

float prev_output;

} high_pass_st;

void high_pass_init(float alpha, float scale, high_pass_st filter);
/**
@brief Initialization for high pass values
*/

float high_pass(high_pass_st filter, float input);
/**
@brief Function for high pass filter
*/

#endif
37 changes: 14 additions & 23 deletions middleware/src/high_pass.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,27 @@ output = alpha * last_output + (1-alpha) * input
output = alpha * last_output + alpha * (avg - prev_avg)
*/
#include "high_pass.h"

//Samples can be modified
#define SAMPLES 12
#include "high_pass.h"

//Scale Var allows adjustment of output strength
//Alpha Var controls weight of prev input & sum difference
float high_pass(int alpha, int scale)
void high_pass_init(float alpha, float scale, high_pass_st filter)
{
static float buffer[SAMPLES] = { 0 }; //initialize changing buffer
static int index = 0;
static float prev_sum = 0.0;

//buffer[index] = freq; //-> adding the freq input into the

index = (index + 1) % SAMPLES;
filter->alpha = alpha;
filter->scale = scale;

float sum = 0.0;

//Iterates through all indices
for (int i = 0; i < SAMPLES; i++) {
sum += buffer[i];
}
filter->prev_output = 0.0;
}

//Algorithm
//
//y[n]=x[n]−SMA[n]
//The output is equal to the input - the moving average
float high_pass(high_pass_st filter, float input)
{
float output =
scale * (alpha * buffer[index - 1] + alpha * (sum - prev_sum));
filter->scale(input - (filter->alpha * input +
(1 - filter->alpha) * prev_output));

prev_sum = sum; //updates the prev_sum
filter->prev_output =
filter->alpha * input + (1 - filter->alpha) * prev_output;

return output;
}

0 comments on commit 25814f7

Please sign in to comment.