skills/timeseries/learnable-fir-filter/SKILL.md
Initialize a depthwise Conv1d with FIR filter coefficients as a trainable high-pass/low-pass filter for sensor signal preprocessing
npx skillsauth add wenmin-wu/ds-skills timeseries-learnable-fir-filterInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
Instead of fixed signal preprocessing, initialize a depthwise 1D convolution with FIR filter coefficients (e.g. high-pass from scipy.signal.firwin), then let it fine-tune during training. The model learns the optimal frequency response for the task while starting from a sensible prior.
import torch
import torch.nn as nn
import torch.nn.functional as F
from scipy.signal import firwin
class LearnableFIR(nn.Module):
def __init__(self, n_channels, numtaps=33, cutoff=1.0, fs=200.0):
super().__init__()
# Initialize with FIR high-pass coefficients
fir_coeff = firwin(numtaps, cutoff=cutoff, fs=fs, pass_zero=False)
kernel = torch.tensor(fir_coeff, dtype=torch.float32)
kernel = kernel.view(1, 1, -1).repeat(n_channels, 1, 1)
self.weight = nn.Parameter(kernel)
self.n_channels = n_channels
self.pad = numtaps // 2
def forward(self, x): # x: (B, C, T)
filtered = F.conv1d(x, self.weight, padding=self.pad,
groups=self.n_channels)
residual = x - filtered # complementary filter (low-pass)
return torch.cat([filtered, residual], dim=1) # both HPF + LPF
data-ai
Scaled Pinball Loss (SPL) metric for evaluating quantile forecasts, normalized by mean absolute successive differences of training data
data-ai
Walk backward through a time series and multiplicatively rescale segments when jumps exceed a fraction of the running mean to correct data collection anomalies
testing
Transform forecasting target to next/current ratio minus one so that optimizing MAE or squared error implicitly minimizes SMAPE
tools
Convert point forecasts to prediction intervals by scaling with logit-transformed quantile ratios passed through a Normal CDF