Skip to content

Commit 6a08d2d

Browse files
committed
Update filter for samplingrate
1 parent 8c5b620 commit 6a08d2d

File tree

3 files changed

+19
-18
lines changed

3 files changed

+19
-18
lines changed

src/components/Connection.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -891,10 +891,10 @@ const Connection: React.FC<ConnectionProps> = ({
891891
const notchFilters = Array.from({ length: maxCanvasElementCountRef.current }, () => new Notch());
892892
const EXGFilters = Array.from({ length: maxCanvasElementCountRef.current }, () => new EXGFilter());
893893
notchFilters.forEach((filter) => {
894-
filter.setbits(detectedBitsRef.current.toString()); // Set the bits value for all instances
894+
filter.setbits(currentSamplingRate); // Set the bits value for all instances
895895
});
896896
EXGFilters.forEach((filter) => {
897-
filter.setbits(detectedBitsRef.current.toString()); // Set the bits value for all instances
897+
filter.setbits(detectedBitsRef.current.toString(),currentSamplingRate); // Set the bits value for all instances
898898
});
899899
try {
900900
while (isDeviceConnectedRef.current) {

src/components/boards.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ export const BoardsList: ReadonlyArray<BoardConfig> = Object.freeze([
172172
field_pid: 22336,
173173
adc_resolution: 12,
174174
channel_count: 16,
175-
sampling_rate: 500,
175+
sampling_rate: 250,
176176
serial_timeout: HIGH_SPEED_TIMEOUT,
177177
}),
178178
createBoardConfig({

src/components/filters.tsx

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export class EXGFilter {
2121
private bits: string | null;
2222
private bitsPoints: number;
2323
private yScale: number;
24+
private currentSamplingRate:number;
2425

2526

2627
constructor() {
@@ -34,6 +35,7 @@ export class EXGFilter {
3435
this.bits = null;
3536
this.bitsPoints=0;
3637
this.yScale=0;
38+
this.currentSamplingRate=0;
3739
}
3840
//bits-
3941
//1.500
@@ -44,7 +46,8 @@ export class EXGFilter {
4446
//3.EEG
4547
//4.EMG
4648
// function to apply the
47-
setbits(bits: string): void {
49+
setbits(bits: string,currentSamplingRate:number): void {
50+
this.currentSamplingRate=currentSamplingRate;
4851
this.bits = bits;
4952
this.bitsPoints = Math.pow(2,parseInt(bits)
5053
); // Adjust according to your ADC resolution
@@ -55,11 +58,9 @@ export class EXGFilter {
5558
if(!type) return (input - this.bitsPoints / 2) * this.yScale;
5659
let output = input;
5760
let chData=0;
58-
switch (this.bits) {
61+
switch (this.currentSamplingRate) {
5962
//bitsrate 500Hz
60-
case "16":
61-
case "14":
62-
case "12":
63+
case 500:
6364
switch (type) {
6465
case 1: // ECG Sampling rate: 500.0 Hz, frequency: 30.0 Hz.
6566
// Filter is order 2, implemented as second-order sections (biquads).
@@ -97,7 +98,7 @@ export class EXGFilter {
9798
break;
9899
}
99100
break;
100-
case "10":
101+
case 250:
101102
//bitsrate 250Hz
102103
switch (type) {
103104
case 1: // ECG Sampling rate: 250.0 Hz, frequency: 30.0 Hz.
@@ -155,7 +156,8 @@ export class Notch {
155156
private z2_2: number;
156157
private x_1: number;
157158
private x_2: number;
158-
private bits: string | null;
159+
private currentSamplingRate:number;
160+
159161

160162
constructor() {
161163
// Initialize state variables for both filter sections
@@ -165,21 +167,20 @@ export class Notch {
165167
this.z2_2 = 0;
166168
this.x_1 = 0;
167169
this.x_2 = 0;
168-
this.bits = null;
170+
this.currentSamplingRate=0;
171+
169172
}
170173

171-
setbits(bits: string): void {
172-
this.bits = bits;
174+
setbits(currentSamplingRate:number): void {
175+
this.currentSamplingRate=currentSamplingRate;
173176
}
174177

175178
// Method to apply the filter
176179
process(input: number, type: number): number {
177180
if(!type) return input;
178181
let output = input;
179-
switch (this.bits) {
180-
case "16" :
181-
case "14": // 500Hz
182-
case "12": // 500Hz
182+
switch (this.currentSamplingRate) {
183+
case 500: // 500Hz
183184
switch (type) {
184185
case 1: // Notch Sampling rate: 500.0 Hz, frequency: [48.0, 52.0] Hz.
185186
this.x_1 = output - (-1.56858163 * this.z1_1) - (0.96424138 * this.z2_1);
@@ -208,7 +209,7 @@ export class Notch {
208209
}
209210
break;
210211

211-
case "10": // 250Hz
212+
case 250: // 250Hz
212213
switch (type) {
213214
case 1: // Notch Sampling rate: 250.0 Hz, frequency: [48.0, 52.0] Hz.
214215
this.x_1 = output - (-0.53127491 * this.z1_1) - (0.93061518 * this.z2_1);

0 commit comments

Comments
 (0)