Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/workinghighpass #230

Merged
merged 2 commits into from
Jan 30, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions middleware/include/high_pass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#ifndef HIGH_PASS_H
#define HIGH_PASS_H

#include <stdio.h>

typedef struct {
//Function Parameters
float alpha;
float scale;

float prev_output;
float prev_input;

} high_pass_t;

/**
* @brief Initiailzing the high pass filter with filter coefficient & desired scale
*
* @param alpha filter coefficient controlling freq response
* @param scale desired scaling for filter
* @param filter pointer to a new high pass struct
*/
void high_pass_init(float alpha, float scale, high_pass_t *filter);

/**
* @brief Function applying filter to a new sample, returning the filtered output
*
* @param filter passing pointer to initialized high pass struct
* @param input new sample to be filtered
* @return float Filtered & Scaled output value based on prev values
*/
float high_pass(high_pass_t *filter, float input);

#endif
22 changes: 22 additions & 0 deletions middleware/src/high_pass.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#include "high_pass.h"

void high_pass_init(float alpha, float scale, high_pass_t *filter)
{
filter->alpha = alpha;
filter->scale = scale;

filter->prev_output = 0.0;
filter->prev_input = 0.0;
}

float high_pass(high_pass_t *filter, float input)
{
float output =
filter->scale * (filter->alpha * (input - filter->prev_input) +
(1 - filter->alpha) * filter->prev_output);

filter->prev_input = input;
filter->prev_output = output;

return output;
}
Loading