Matlab Design Digital Filter
MathWorksOfficialCreated by MathWorks
- Skill
- Tool integration
- Science and research
- BSD-2-Clause
- No issues found
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
Download the skill as a ZIP:
https://mp-staging.autogineer.com/agent-skills/matlab/matlab-design-digital-filter/downloadUnzip 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.mfile, run withrun_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
Fsis unknown, stop and ask (unless the user explicitly wants normalized frequency).Always pin the sample rate. Use
designfilt(..., SampleRate=Fs)andfreqz(d, [], Fs).IIR stability: Prefer SOS/CTF forms (avoid high-order
[b,a]polynomials).
Preflight Procedure
List MATLAB functions to call
Check
references/INDEX.mdfor each (function-level + task-level tables)Read required quick-ref files
State at response top:
Preflight: quick-ref/filter-analyzer.md, quick-ref/designfilt.md(orPreflight: none required)
Workflow
Phase 1: Signal Analysis
Analyze input data via MCP (spectrum, signal length, interference location)
Compute
trans_pctand 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.mdiftrans_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_dBpassband ripple (default 1 dB),Rs_dBstopband 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 - Fpasstrans_pct = 100 * trans_bw / FsM_max = floor(Fs/(2*Fstop))(only meaningful for lowpass-based multirate)
Decision rule:
trans_pct > 5%-- single-stage FIR or IIR is usually fine2% <= trans_pct <= 5%-- single-stage possible; mention efficient alternatives if cost/latency matterstrans_pct < 2%-- stop and do a narrow-transition comparison (seereferences/quick-ref/efficient-filtering.md)
Design + Verify
Feasibility check -- Let
designfiltchoose minimum order, then queryfiltord(d). Optionally usekaiserord/firpmordfor FIR length estimates.Design candidates -- Prefer
designfilt()with explicitRp/RsandSampleRate=Fs. Streaming IIR: useSystemObject=true. Offline zero-phase:filtfilt()is allowed but state that it squares the magnitude response.Compare visually -- Use
filterAnalyzer()for comparing 2+ designs. Readreferences/quick-ref/filter-analyzer.mdfirst. Minimum displays: magnitude + group delay.Verify with numbers -- Worst-case passband ripple and stopband attenuation vs spec. For
filtfilt(), verify the effective response (magnitude squared).Deliver the output -- Specs recap, derived metrics, chosen architecture + why, MATLAB code, verification snippet + results, implementation form.
Key Functions
| Function | Purpose |
|---|---|
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.SOSFilter | Streaming 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=Fsindesignfilt()and plot in Hz withfreqz(d, [], Fs)Use
filterAnalyzer()for multi-filter comparison, not customfreqz/grpdelayplotsUse SOS form for IIR (avoid
[b,a]for order > 8)Use
tiledlayout/nexttilefor multi-panel figures (notsubplot)
Copyright 2026 The MathWorks, Inc.
Files
- ATTRIBUTION.mdAdded by AutoGineer1.0 KiB
- LICENSELicence file added by AutoGineer1.4 KiB
- SKILL.md6.1 KiB
- manifest.yaml473 B
- references/INDEX.md2.9 KiB
- references/best-practices.md7.8 KiB
- references/efficient-filtering.md14.4 KiB
- references/filter-analyzer.md18.1 KiB
- references/multirate.md13.2 KiB
- references/multistage-ifir.md8.5 KiB
- references/patterns.md16.2 KiB
- references/quick-ref/designfilt.md6.0 KiB
- references/quick-ref/efficient-filtering.md6.1 KiB
- references/quick-ref/filter-analyzer.md3.0 KiB
- references/quick-ref/general-iir-fir.md3.0 KiB
- references/quick-ref/multirate-offline.md2.3 KiB
- references/quick-ref/multirate-streaming.md3.6 KiB
- references/quick-ref/multistage-ifir.md2.8 KiB
references/quick-ref/designfilt.md
designfilt Reference Card
Open this card before writing any designfilt(...) call.
Response Type Quick Reference
| Filter type | Response string | Key parameters |
|---|---|---|
| Lowpass FIR | "lowpassfir" | PassbandFrequency, StopbandFrequency |
| Lowpass IIR | "lowpassiir" | PassbandFrequency, StopbandFrequency |
| Highpass FIR | "highpassfir" | StopbandFrequency, PassbandFrequency |
| Highpass IIR | "highpassiir" | StopbandFrequency, PassbandFrequency |
| Bandpass FIR | "bandpassfir" | PassbandFrequency=[f1 f2] (vector OK) |
| Bandpass IIR | "bandpassiir" | PassbandFrequency1, PassbandFrequency2 (scalar!) |
| Bandstop FIR | "bandstopfir" | StopbandFrequency=[f1 f2] (vector OK) |
| Bandstop IIR | "bandstopiir" | StopbandFrequency1, StopbandFrequency2 (scalar!) |
| Notch (single tone) | "notchiir" | CenterFrequency, QualityFactor |
| Peak (boost) | "peakiir" | CenterFrequency, QualityFactor, PassbandRipple |
Core Patterns
FIR (linear phase by default)
d = designfilt("lowpassfir", ...
PassbandFrequency=Fpass, StopbandFrequency=Fstop, ...
PassbandRipple=Rp, StopbandAttenuation=Rs, ...
SampleRate=Fs, DesignMethod="equiripple");IIR (minimum order)
d = designfilt("lowpassiir", ...
PassbandFrequency=Fpass, StopbandFrequency=Fstop, ...
PassbandRipple=Rp, StopbandAttenuation=Rs, ...
SampleRate=Fs, DesignMethod="ellip");Notch (single tone removal)
d = designfilt("notchiir", ...
FilterOrder=2, CenterFrequency=f0, QualityFactor=Q, ...
SampleRate=Fs);FilterOrder is required for notchiir — omitting it causes a runtime error. Order 2 (single biquad) is standard; use higher even orders for deeper notches.
Q guidelines: 10-50 typical. Higher Q = sharper notch but more ringing.
Bandpass IIR (scalar edges required!)
d = designfilt("bandpassiir", ...
StopbandFrequency1=fs1, PassbandFrequency1=f1, ...
PassbandFrequency2=f2, StopbandFrequency2=fs2, ...
PassbandRipple=Rp, ...
StopbandAttenuation1=Rs, StopbandAttenuation2=Rs, ...
SampleRate=Fs, DesignMethod="ellip");Bandstop IIR (scalar edges + numbered ripple!)
d = designfilt("bandstopiir", ...
PassbandFrequency1=fp1, StopbandFrequency1=fs1, ...
StopbandFrequency2=fs2, PassbandFrequency2=fp2, ...
PassbandRipple1=Rp, StopbandAttenuation=Rs, PassbandRipple2=Rp, ...
SampleRate=Fs, DesignMethod="ellip");Mirror of bandpassiir: two passbands need PassbandRipple1/2, one stopband uses singular StopbandAttenuation.
Design Methods
| Method | Characteristics |
|---|---|
"ellip" | Minimum order, equiripple in pass & stop |
"butter" | Maximally flat, monotonic response |
"cheby1" | Ripple in passband only |
"cheby2" | Ripple in stopband only |
"equiripple" | Parks-McClellan (FIR only) |
SystemObject=true (streaming)
For streaming applications, get a System object directly:
% Returns dsp.SOSFilter (IIR) or dsp.FIRFilter (FIR)
sosFilter = designfilt("lowpassiir", ...
PassbandFrequency=Fpass, StopbandFrequency=Fstop, ...
SampleRate=Fs, DesignMethod="ellip", ...
SystemObject=true);
y = sosFilter(x); % Stateful, ready for streamingGotchas
IIR bandpass/bandstop vector error
Wrong:
% Anti-pattern
d = designfilt("bandpassiir", ...
PassbandFrequency=[300 3400], ...); % ERROR! Vector not allowed for IIRCorrect: Use scalar properties with ...1/...2 suffixes.
Note: FIR bandpass/bandstop CAN use vectors: PassbandFrequency=[f1 f2]
IIR bandpass/bandstop ripple and attenuation naming
Suffix follows the number of bands in minimum-order designs:
bandpassiir (1 passband, 2 stopbands):
PassbandRipple+StopbandAttenuation1/2bandstopiir (2 passbands, 1 stopband):
PassbandRipple1/2+StopbandAttenuation
Using the wrong form (e.g., PassbandRipple for minimum-order bandstopiir, or StopbandAttenuation1/2 for bandstopiir) produces an invalid parameter set error.
Deprecated Coefficients property
Wrong: sos = d.Coefficients; (removed in recent versions)
Correct:
B = d.Numerator; % Lx3 per-section
A = d.Denominator; % Lx3 per-section
sos = [B A]; % Lx6 if neededManual dsp.SOSFilter vs SystemObject=true
Don't manually extract coefficients to create a System object:
% Template
% Inefficient
d = designfilt(...); B = d.Numerator; A = d.Denominator;
sosFilter = dsp.SOSFilter('Numerator', B, 'Denominator', A);
% Efficient - get System object directly
sosFilter = designfilt(..., SystemObject=true);Narrow bandpass FIR undershoot
Equiripple minimum-order designs for narrow bandpass filters can undershoot specs — the optimizer distributes error across bands and may exceed Rp or miss Rs.
Fix: Over-design by tightening specs (e.g., Rp×0.5, Rs+5 dB), then verify the actual measured response against the real spec.
% Real spec: Rp=1 dB, Rs=50 dB
% Over-design to compensate for equiripple undershoot:
d = designfilt("bandpassfir", ...
StopbandFrequency1=150, PassbandFrequency1=180, ...
PassbandFrequency2=220, StopbandFrequency2=250, ...
StopbandAttenuation1=55, PassbandRipple=0.5, StopbandAttenuation2=55, ...
SampleRate=Fs, DesignMethod="equiripple");
% Then verify: freqz(d, [], Fs) and check measured Rp/Rs against REAL specBoundary over-spec for minimum-order designs
designfilt minimum-order designs can land exactly on the spec boundary (e.g., measured Rs = 60.0 dB for Rs=60 spec). Over-specify Rs by 1 dB to ensure margin.
Ultra-high-Q notch (excessive ringing)
Problematic: QualityFactor=1000 causes long ringing
Better: Use moderate Q (10-50). For multiple tones, use several moderate notches instead of one ultra-sharp notch.
Legacy notch APIs
iirnotch— deprecated (to be removed). Usedesignfilt("notchiir")instead.
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.
Download ZIP
The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download matlab-design-digital-filter.zip