Medical IoT and AI
Wearable Health Data Processing
from scipy.signal import butter, filtfilt
import numpy as np
class WearableDataProcessor:
def __init__(self, sampling_rate=250):
self.fs = sampling_rate
def bandpass_filter(self, signal, lowcut=0.5, highcut=40.0, order=4):
nyq = 0.5 * self.fs
b, a = butter(order, [lowcut/nyq, highcut/nyq], btype='band')
return filtfilt(b, a, signal)
def normalize(self, signal):
return (signal - np.mean(signal)) / (np.std(signal) + 1e-8)
Anomaly Detection in IoT Streams
Statistical Process Control
LSTM-Based Detection
class IoTAnomalyDetector(nn.Module):
def __init__(self, n_features, hidden_size=64):
super().__init__()
self.lstm = nn.LSTM(n_features, hidden_size, batch_first=True)
self.decoder = nn.Sequential(
nn.Linear(hidden_size, n_features * 2), nn.ReLU(),
nn.Linear(n_features * 2, n_features))
def forward(self, x):
_, (h, _) = self.lstm(x)
return self.decoder(h.squeeze(0))
def anomaly_score(self, x):
return torch.mean((x - self.forward(x)) ** 2, dim=-1)
Edge Computing for Health
Model Compression
Quantization