-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Ruben Noroian
committed
Nov 24, 2024
1 parent
c526b7c
commit bab8efe
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
#ifndef HIGH_PASS_H | ||
#define HIGH_PASS_H | ||
|
||
#include <stdio.h> | ||
|
||
int high_pass(int alpha, int scale); | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
Understanding High-Pass Filter Implementation | ||
Goal is to customize the cutoff frequency/strength | ||
One style: | ||
-alpha factor -> smoothing factor used to make the changes smoother | ||
-scale factor -> scales the output given by algo | ||
these two params correlate to strength | ||
Or user could pass desired cutoff frequency and that would be used | ||
Algorithm: | ||
1. first possibility | ||
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 | ||
|
||
//Scale Var allows adjustment of output strength | ||
//Alpha Var controls weight of prev input & sum difference | ||
float high_pass(int alpha, int scale) | ||
{ | ||
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; | ||
|
||
float sum = 0.0; | ||
|
||
//Iterates through all indices | ||
for (int i = 0; i < SAMPLES; i++) { | ||
sum += buffer[i]; | ||
} | ||
|
||
//Algorithm | ||
// | ||
float output = | ||
scale * (alpha * buffer[index - 1] + alpha * (sum - prev_sum)); | ||
|
||
prev_sum = sum; //updates the prev_sum | ||
|
||
return output; | ||
} |