Generated banner for Matlab Design Digital Filter
Generated logo for Matlab Design Digital Filter

Matlab Design Digital Filter

MathWorksOfficialCreated by MathWorks

  • Skill
  • Tool integration
  • Science and research
  • BSD-2-Clause
  • No issues found

From the author

Design and validate digital filters in MATLAB. Use when cleaning up noisy signals, removing interference, filtering signals, designing FIR/IIR filters (lowpass/highpass/bandpass/bandstop/notch), or comparing filters in Filter Analyzer.
— the description by MathWorks

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

This skill provides a structured workflow for designing and validating digital filters within MATLAB. It guides users through signal analysis, architecture selection, and verification, ensuring that filter designs meet specific frequency and magnitude requirements. The skill emphasizes the use of standard MATLAB functions like designfilt and filterAnalyzer, while enforcing best practices for numerical stability and frequency-aware design.

What it does

  • Designs FIR and IIR filters including lowpass, highpass, bandpass, bandstop, and notch types.
  • Provides a systematic workflow for signal analysis and architecture selection.
  • Facilitates visual comparison of filter designs using Filter Analyzer.
  • Enforces best practices for numerical stability, such as using SOS forms for IIR filters.
  • Includes validation steps to verify filter performance against specifications.
  • Supports both streaming and offline filtering implementation strategies.

When to use it

  • When you need to clean up noisy signals or remove specific interference.
  • When designing digital filters with specific frequency and ripple requirements.
  • When comparing different filter architectures like FIR versus IIR.
  • When working on streaming or batch signal processing pipelines.

Advantages

  • Ensures consistent design methodology through a preflight and verification checklist.
  • Promotes numerical stability by recommending specific filter forms.
  • Integrates directly with MATLAB's signal processing and DSP toolboxes.
  • Provides clear guidance on handling narrow transition bands.

Usage examples

“Design a lowpass filter for a 1000 Hz signal with a 200 Hz cutoff.”
The agent will ask for the sample rate (Fs), filter mode (streaming vs offline), and phase requirements before generating the design code.
“How do I compare two different filter designs in MATLAB?”
The agent will guide you to use the filterAnalyzer function and provide the necessary steps to visualize and compare their magnitude and group delay responses.

Install

  1. Download the skill as a ZIP:

    https://autogineer.com/agent-skills/matlab/matlab-design-digital-filter/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip matlab-design-digital-filter.zip -d .agents/skills

Documentation by MathWorks

Design Digital Filters in MATLAB

Design, implement, and validate digital filters using Signal Processing Toolbox and DSP System Toolbox. Choose the right architecture (single-stage vs efficient alternatives), generate correct code, and verify the result with plots and numbers.

When to Use

  • Designing lowpass, highpass, bandpass, bandstop, or notch filters

  • Cleaning up noisy signals or removing interference

  • Choosing between FIR and IIR filter architectures

  • Comparing filter designs in Filter Analyzer

  • Building streaming (real-time) or offline (batch) filtering pipelines

  • Handling narrow transition bands with multirate or IFIR approaches

When NOT to Use

  • Adaptive filtering (LMS, RLS) -- use Signal Processing Toolbox docs directly

  • Audio-specific processing (equalization, room correction) -- use Audio Toolbox

  • Image filtering (2D convolution, morphological ops) -- use Image Processing Toolbox

  • General spectral analysis without filtering intent -- FFT/periodogram docs suffice

Key Rules

  • Read references/INDEX.md before writing any filter design code.

  • Always write to .m files. Never put multi-line MATLAB code directly in evaluate_matlab_code. Write to a .m file, run with run_matlab_file, edit on error.

  • Preflight before ANY MATLAB call. Before calling any function listed in INDEX.md, read the required quick-ref first. State Preflight: [files] at the top of the response.

  • Do not guess key requirements. If Mode (streaming vs offline) or Phase requirement is not stated, ask.

  • No Hz designs without Fs. If Fs is unknown, stop and ask (unless the user explicitly wants normalized frequency).

  • Always pin the sample rate. Use designfilt(..., SampleRate=Fs) and freqz(d, [], Fs).

  • IIR stability: Prefer SOS/CTF forms (avoid high-order [b,a] polynomials).

Preflight Procedure
  1. List MATLAB functions to call

  2. Check references/INDEX.md for each (function-level + task-level tables)

  3. Read required quick-ref files

  4. State at response top: Preflight: quick-ref/filter-analyzer.md, quick-ref/designfilt.md (or Preflight: none required)

Workflow

Phase 1: Signal Analysis
  • Analyze input data via MCP (spectrum, signal length, interference location)

  • Compute trans_pct and identify interference characteristics

Phase 2: Clarify Intent

After signal analysis, ask Mode + Phase if not stated:

  • Mode: streaming (causal) | offline (batch)

  • Phase: zero-phase | linear-phase | don't-care

Wait for answer before showing any approach comparison or overview.

Phase 3: Architecture Selection
  • Open references/efficient-filtering.md if trans_pct < 2%

  • Show only viable candidates given Mode + Phase constraints

  • Explicitly state excluded families with one-line reason

  • Use Filter Analyzer for visual comparison

Design Intake Checklist

Required signal + frequency spec (cannot proceed without)
  • Fs (Hz)

  • Response type: lowpass / highpass / bandpass / bandstop / notch

  • Edge frequencies in Hz

If any item is missing, ask.

Required intent for architecture choice (ask if unknown)
  • Mode: streaming (causal) | offline (batch)

  • Phase: zero-phase | linear-phase | don't-care

  • Magnitude constraints: Rp_dB passband ripple (default 1 dB), Rs_dB stopband attenuation (default 60 dB)

If Mode or Phase is unknown, ask 1-2 clarifying questions and stop.

Architecture Checkpoint

Compute and state before finalizing an approach:

  • trans_bw = Fstop - Fpass

  • trans_pct = 100 * trans_bw / Fs

  • M_max = floor(Fs/(2*Fstop)) (only meaningful for lowpass-based multirate)

Decision rule:

  • trans_pct > 5% -- single-stage FIR or IIR is usually fine

  • 2% <= trans_pct <= 5% -- single-stage possible; mention efficient alternatives if cost/latency matters

  • trans_pct < 2% -- stop and do a narrow-transition comparison (see references/quick-ref/efficient-filtering.md)

Design + Verify

  1. Feasibility check -- Let designfilt choose minimum order, then query filtord(d). Optionally use kaiserord/firpmord for FIR length estimates.

  2. Design candidates -- Prefer designfilt() with explicit Rp/Rs and SampleRate=Fs. Streaming IIR: use SystemObject=true. Offline zero-phase: filtfilt() is allowed but state that it squares the magnitude response.

  3. Compare visually -- Use filterAnalyzer() for comparing 2+ designs. Read references/quick-ref/filter-analyzer.md first. Minimum displays: magnitude + group delay.

  4. Verify with numbers -- Worst-case passband ripple and stopband attenuation vs spec. For filtfilt(), verify the effective response (magnitude squared).

  5. Deliver the output -- Specs recap, derived metrics, chosen architecture + why, MATLAB code, verification snippet + results, implementation form.

Key Functions

FunctionPurpose
designfilt()Primary filter design (FIR and IIR, all response types)
filterAnalyzer()Visual comparison of 2+ filter designs
freqz(), grpdelay()Frequency response and group delay analysis
filtfilt()Zero-phase offline filtering
dsp.SOSFilterStreaming IIR via SystemObject=true
designMultirateFIR()Multirate decimator/interpolator design
ifir()Interpolated FIR for narrow transitions at constant rate
cost()MPIS (MultiplicationsPerInputSample) on DSP System objects
kaiserord(), firpmord()FIR order estimation

Conventions

  • Always specify SampleRate=Fs in designfilt() and plot in Hz with freqz(d, [], Fs)

  • Use filterAnalyzer() for multi-filter comparison, not custom freqz/grpdelay plots

  • Use SOS form for IIR (avoid [b,a] for order > 8)

  • Use tiledlayout/nexttile for multi-panel figures (not subplot)


Copyright 2026 The MathWorks, Inc.


Files

references/quick-ref/efficient-filtering.md

Efficient Filtering Card (trans_pct < 2%)

Use this card when the transition band is narrow or you need to compare compute cost across architectures.

trans_pct = 100 * (Fstop - Fpass) / Fs;

If trans_pct < 2%, a single-stage FIR may be hundreds of taps. Stop and compare architectures instead of committing early.

Step 0 — compute the planning metrics

trans_bw  = Fstop - Fpass;
trans_pct = 100 * trans_bw / Fs;
M_max     = floor(Fs/(2*Fstop));   % upper bound for lowpass-safe decimation

Step 1 — do not guess: confirm the intent

You must know:

  • Mode: streaming (causal) vs offline (batch)

  • Phase: zero-phase, linear-phase, or don't-care

  • Whether internal rate change is acceptable (multirate pipelines)

If any is unknown: ask, then stop.

Step 2 — pick the viable candidate families (don't force all four)

For trans_pct < 2%, present 2–4 viable candidates, not a fixed set.

Quick lookup: Mode × Phase → Viable families
ModePhaseSingle-stage IIRSingle-stage FIRMultirateIFIR
Streaminglinear-phase❌✅✅ polyphase✅
Streamingdon't-care✅✅✅ polyphase✅
Offlinezero-phase✅ filtfilt()✅ filtfilt()✅ resample()+filtfilt()✅ filtfilt()
Offlinelinear-phase❌✅✅ polyphase✅
Offlinedon't-care✅✅✅ either✅

Key insight: Polyphase multirate (FIR decimator/interpolator) gives linear-phase — it's NOT limited to offline zero-phase workflows.

Family details
FamilyViable whenQuick notes
Single-stage IIRphase ≠ "linear-phase"Offline can use filtfilt() for zero-phase. Streaming IIR is efficient but non-linear phase.
Single-stage FIRalways viableLinear phase possible, but may be long / high latency / high MPIS.
Multirate pipeline (dec→filter→interp)rate change OKStreaming: polyphase System objects (linear-phase). Offline zero-phase: resample() + filtfilt(). Never mix filtfilt with System objects.
Constant-rate multistage FIR (IFIR method)rate change NOT OKFIR-like behavior at constant rate with fewer multipliers than single-stage FIR in many narrow-band cases.

If a family is excluded, say so explicitly (one line), e.g.:

  • "Excluded IIR: user requires linear phase in streaming."

  • "Excluded multirate: user cannot change internal sample rate."

Choosing between IFIR and Notch+LP

When the spectrum shows a dominant tonal interferer near the transition band, consider a Notch + relaxed LP hybrid:

ApproachBest when
Notch + relaxed LPKnown tonal interferer you can notch out (allows wider transition)
IFIRGeneral narrow transition, no specific tone to exploit
Single-stage FIRBaseline (always works)

Decision rule:

  1. Analyze spectrum for dominant tones in/near transition band

  2. If tone found: try Notch (at tone freq) + relaxed LP (wider Fstop)

  3. Compare MPIS via cost() — pick the cheaper option

  4. If no identifiable tone → use IFIR or single FIR

Step 3 — feasibility check (order estimates)

Let designfilt pick the minimum order from Rp/Rs, then query filtord(d).

d_try = designfilt("lowpassfir", ...
    PassbandFrequency=Fpass, StopbandFrequency=Fstop, ...
    PassbandRipple=Rp, StopbandAttenuation=Rs, ...
    SampleRate=Fs, DesignMethod="equiripple");

N = filtord(d_try);
FIR planning estimates (useful for architecture decisions)
dev_p = (10^(Rp/20)-1)/(10^(Rp/20)+1);  % passband deviation (linear)
dev_s = 10^(-Rs/20);                    % stopband deviation (linear)

[Nk,~,~,~] = kaiserord([Fpass Fstop],[1 0],[dev_p dev_s], Fs);
[Np,~,~,~] = firpmord([Fpass Fstop],[1 0],[dev_p dev_s], Fs);

Use these as "order smell tests," not absolute truth.

Step 4 — compute MPIS with cost()

MPIS = Multiplications Per Input Sample, reported by cost() on DSP System objects.

80/20 rules
  • Tap count alone lies (multirate runs parts at lower rate; IIR cost isn't "sections × taps").

  • Prefer System objects + cost():

    • FIR → dsp.FIRFilter

    • IIR → dsp.SOSFilter (often easiest via designfilt(..., SystemObject=true))

    • Pipelines → dsp.FilterCascade

FIR MPIS
d_fir = designfilt("lowpassfir", ...
    PassbandFrequency=Fpass, StopbandFrequency=Fstop, ...
    PassbandRipple=Rp, StopbandAttenuation=Rs, ...
    SampleRate=Fs, DesignMethod="equiripple");

firSys = dsp.FIRFilter("Numerator", d_fir.Numerator);
mpis_fir = cost(firSys).MultiplicationsPerInputSample;
IIR MPIS (prefer SystemObject=true)
% Returns dsp.SOSFilter directly (stable + stateful)
iirSys = designfilt("lowpassiir", ...
    PassbandFrequency=Fpass, StopbandFrequency=Fstop, ...
    PassbandRipple=Rp, StopbandAttenuation=Rs, ...
    SampleRate=Fs, DesignMethod="ellip", ...
    SystemObject=true);

mpis_iir = cost(iirSys).MultiplicationsPerInputSample;
Pipeline MPIS
pipe = dsp.FilterCascade(stage1, stage2, stage3);
mpis_pipe = cost(pipe).MultiplicationsPerInputSample;

For multirate decimate→filter→interpolate pipelines, cost(pipe) accounts for polyphase structure and internal rates.

Offline filtfilt() note
  • filtfilt() runs the filter twice → compute cost is roughly 2× the single-pass cost.

  • The effective magnitude response is squared (≈ doubles attenuation in dB).

Step 5 — compare with Filter Analyzer

  • Open Filter Analyzer and overlay candidates (see references/INDEX.md for the filter-analyzer quick-ref).

Minimum comparisons to show:

  • Magnitude response (meet specs)

  • Group delay (latency + phase behavior)

  • MPIS (when compute matters)


resample() note

resample() uses internal filters not exposed to cost(). If you need performance numbers for an offline resample() pipeline, use timeit() on your machine.


Copyright 2026 The MathWorks, Inc.


Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
MathWorks
Publisher
MathWorks (Official)
Source
matlab/matlab-agentic-toolkit · skills-catalog/signal-processing/matlab-design-digital-filter · commit 2a7f215
Licence
BSD 2-Clause License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE.md)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by MathWorks or MathWorks.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-design-digital-filter.zip