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

Feature/highpass #206

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion general/src/pca9539.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,4 @@ HAL_StatusTypeDef pca9539_write_pin(pca9539_t *pca, uint8_t reg_type,
data_new = (data & ~(1u << pin)) | (buf << pin);

return pca_write_reg(pca, reg_type, &data_new);
}
}
33 changes: 33 additions & 0 deletions middleware/include/high_pass.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef HIGH_PASS_H
#define HIGH_PASS_H

#include <stdio.h>

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

float prev_output;

} 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
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doxygen comments go above the function, and explain the parameters and what the function returns (if it returns anything)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to fill in doc comments

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
21 changes: 21 additions & 0 deletions middleware/src/high_pass.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "high_pass.h"

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect syntax and will not compile

filter->scale = scale;

filter->prev_output = 0.0;
}

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

filter->prev_output =
filter->alpha * input + (1 - filter->alpha) * prev_output;

return output;
}
Loading