In my iOS application, using swift
i am getting audio from digital health device (BLE). In the form of audio data, to hear heart beats.
- We apply ADPCM decoder on received data. When playing it has background noise with heart beats.
- To filter that, we apply filter to remove background noise. It is band pass IIR filter.
IIR Parameters for frequency 20 - 200 Hz
B 0.3468218078469383,0.0,-1.3872872313877531,0.0,2.0809308470816297,0.0,-1.3872872313877531,0.0,0.346821807846938
A 1.0,-0.692931448722861,-1.7554648142444358,0.7966332180729667,1.6060001719379677,-0.4353468784755548,-0.691339842239745,0.08285290618602029,0.12038959989624454
Below is a Filter code
Код: Выделить всё
func applyFilterToData(decoded: Data) -> Data { // Example usage var lastData = Data() for decodedData in decoded { let unsignedData = UInt8(decodedData) let lowPassUInt8 = iirFilterNew.filter(Double(unsignedData)) lastData.append(lowPassUInt8) filteredDataToShare.append(lastData) self.n = (self.n + 1) % 9 } // Receive UInt8 -> Data return lastData } func filter(_ input: Double) -> UInt8 { // Update input history xHistory.insert(input, at: 0) xHistory.removeLast() // Calculate output var output = b[0] * xHistory[0] for i in 1.. 127.0 { val = 127.0 } if val < -128.0 { val = -128.0 } var signedInt: Int8 = 0 if val.isNaN { signedInt = 0 } else { signedInt = Int8(val) } return UInt8.init(bitPattern: Int8(signedInt)) } https://drive.google.com/file/d/1qV8YBF ... sp=sharing
Источник: https://stackoverflow.com/questions/780 ... beat-sound
Мобильная версия