fir1 — Design windowed-sinc FIR filters.
fir1(n, Wn) designs an order-n FIR filter using a Hamming-windowed sinc response. Scalar Wn creates a low-pass filter by default; a two-element Wn creates a band-pass filter by default. Add a filter type string for high-pass or stop-band designs.
Syntax
fir1(n, Wn)How fir1 works
- Returns a row vector with
n + 1coefficients. Wnuses MATLAB's normalized digital convention where1is Nyquist.- Supported filter types are
low,high,bandpass, andstop. - A custom window vector of length
n + 1may be supplied. - Filters are scaled by default; pass
noscaleto skip passband normalization.
Does RunMat run fir1 on the GPU?
Host-side coefficient design only.
The resulting coefficient vector can be passed to filter or filtfilt with gpuArray signal data.
Examples
Design a low-pass FIR filter
b = fir1(4, 0.5);
fprintf('%d %.4f\n', length(b), sum(b));Expected output:
5 1.0000Design coefficients for a FIR low-pass response plot
fs = 1000;
fc = 100;
N = 51;
wn = fc / (fs/2);
b = fir1(N-1, wn, 'low');
[H, w] = freqz(b, 1, 512, fs);
fprintf('%d %.1f %.1f\n', length(b), w(1), w(end));Expected output:
51 0.0 499.0Use a custom rectangular window without scaling
w = ones(1, 11);
b = fir1(10, 0.3, w, 'noscale');Using fir1 with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how fir1 changes the result.
Run a small fir1 example, explain the result, then change one input and compare the output.
FAQ
What window does fir1 use by default?⌄
RunMat uses a symmetric Hamming window, matching MATLAB's default FIR design workflow.
Can the coefficients be used with filtfilt?⌄
Yes. Use filtfilt(b, 1, x) for zero-phase FIR filtering.
Does fir1 run on the GPU?⌄
No. It generates a small coefficient vector on the host. GPU acceleration applies when those coefficients are used by filtering builtins with gpuArray signals.
Related Math functions
Signal
blackman · butter · conv · conv2 · deconv · downsample · filter · filtfilt · freqz · gauspuls · hamming · hann · hilbert · pulstran · rectpuls · sawtooth · sinc · square · tripuls · unwrap · upsample
Elementwise
abs · angle · complex · conj · double · exp · expm1 · factorial · gamma · heaviside · hypot · imag · ldivide · log · log10 · log1p · log2 · minus · nextpow2 · plus · pow2 · power · rdivide · real · sign · single · sqrt · times
Trigonometry
acos · acosh · asin · asinh · atan · atan2 · atanh · cos · cosd · cosh · deg2rad · rad2deg · sin · sind · sinh · tan · tand · tanh
Reduction
all · any · cummax · cummin · cumprod · cumsum · cumtrapz · diff · gradient · max · mean · median · min · nnz · prod · std · sum · trapz · var
Structure
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how fir1 is executed, line by line, in Rust.
- View the source for fir1 in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.