@@ -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