MATLAB中降采样为何要对滤波器系数进行缩放?
h = p*h/sum(h) in MATLAB's resample FIR Filter Design? Great question! Let's break down the purpose of that final scaling step and the theory behind it.
First, let's recap the context: this code is part of designing the anti-aliasing/interpolation FIR filter for resampling (adjusting the sample rate by a ratio p/q). The firls function designs a linear-phase FIR filter with a target passband gain of 1, and we apply a Kaiser window to control stopband attenuation. But why scale the filter by p/sum(h)?
Core Goal: Preserve DC Component Amplitude
The key reason for this scaling is to ensure the DC (constant) component of the input signal stays identical in the resampled output. MATLAB's resample function guarantees that if you input a constant signal (e.g., x(n) = A), the resampled output will also be A—matching the original amplitude—whether you're upsampling or downsampling.
How the Scaling Works
Let's break it down step by step:
- When you design the filter with
firlsand apply the Kaiser window, the actual DC gain of the filter (sum of its coefficients,sum(h)) won't be exactly 1. Windowing and minor design approximations introduce small deviations from the target passband gain. - The term
p/sum(h)normalizes the filter so that its new DC gain becomesp. Here's whypis the right choice for different resampling scenarios:- Upsampling case (p > q): First, we insert
p-1zeros between each input sample. This spreads the signal's energy across more samples, so the filter needs a DC gain ofpto "fill in" the zeros and restore the original amplitude. After downsampling byq, the final DC component matches the input perfectly. - Downsampling case (p < q): We first filter the input to prevent aliasing, then downsample by
q. The scaling bypensures that after downsampling, the DC component's amplitude stays the same as the input. For example, if you're downsampling by 2 (p=1,q=2), scaling by1/sum(h)sets the filter's DC gain to 1—so the filtered DC signal remainsA, and downsampling it keeps that amplitude intact.
- Upsampling case (p > q): First, we insert
Quick Mathematical Check
Suppose we have an input DC signal x(n) = A. For upsampling by p=2 (q=1):
- The upsampled signal is
A, 0, A, 0, ... - Filtering with
h_new(sum = 2) gives a steady-state output where each sample isA*sum(h_new)/2 = A*2/2 = A—matching the original input's amplitude.
For downsampling by q=2 (p=1):
- Filtering the constant input
Awithh_new(sum =1) givesA*1at every sample. Downsampling picks every 2nd sample, which is stillA—preserving the original amplitude.
This scaling step ensures signal integrity by keeping the most basic component of the signal (DC) consistent through the resampling process.
内容的提问来源于stack exchange,提问作者Danijel

