Library / Signal processing and digital filters / DSP-47
Signal processing and digital filters
Full upsample–FIR–downsample output length
Length of the full output when N input samples are upsampled by L, filtered by an H-tap FIR and downsampled by M, keeping indices 0, M, 2M, … of the full zero-extended convolution.
- Ref
- DSP-47
- Rev
- v1
- Field
- Signal processing and digital filters
- Result
- Nout [samples]
Upsampling a sequence of N samples by L inserts L − 1 zeros between samples, giving (N − 1)L + 1 samples. Convolving with an H-tap filter lengthens this to (N − 1)L + H. Keeping indices 0, M, 2M, … leaves ⌊((N − 1)L + H − 1)/M⌋ + 1 samples. If the output is trimmed to remove the filter delay, the count is different.
Length of the full output when N input samples are upsampled by L, filtered by an H-tap FIR and downsampled by M, keeping indices 0, M, 2M, … of the full zero-extended convolution. Delay-compensated trimming gives a different count.
Calculator
- Length after zero insertion, (N − 1)L + 113 samples
- Full filtered length, (N − 1)L + H16 samples
- Length if the filter had no tail, ⌊(N − 1)L/M⌋ + 17 samples
What drives the result
Each variable is moved across its typical range while the others stay at the values above. The longest bar is the key driver.
- 5 input samples become 8 output samples, 1.6 per input sample, against the ideal ratio of 1.5.
- The difference is the filter tail: 3 extra full-rate samples, which are trimmed or flushed depending on the implementation.
Chart data as tables
Ranked variables
| Variable | Typical range | Lowest result | Highest result | Swing (samples) | Local step | Change in result |
|---|---|---|---|---|---|---|
| N Input samples | 1 to 100,000 | 2 | 150,000 | 150,000 | +1 | +25 % |
| H FIR length | 1 to 10,000 taps | 7 | 5,006 | 4,999 | +1 taps | +12.5 % |
| L Interpolation factor | 1 to 1,000 | 4 | 2,002 | 1,998 | +1 | +25 % |
| M Decimation factor | 1 to 1,000 | 1 | 16 | 15 | +1 | −25 % |
Sweep of Input samples
| Input samples | Output length (samples) |
|---|---|
| 1 | 2 |
| 4.217 | 7 |
| 17.78 | 28 |
| 74.99 | 113 |
| 316.2 | 475 |
| 1,334 | 2,002 |
| 5,623 | 8,435 |
| 23,710 | 35,570 |
| 100,000 | 150,000 |
Sweep one variable
Variables and how each one contributes
Output length
What the equation gives you. Everything else feeds it.
Input samples
The number of input samples. Raises the output length in proportion to L/M. Raising it by 10 % (to 5.5) moves the result by +25 %, from 8 to 10 samples.
Interpolation factor
The interpolation factor. Raises the output length roughly in proportion to L. Raising it by 10 % (to 3.3) moves the result by +0 %, from 8 to 8 samples.
FIR length
The FIR filter length, in taps. Adds H − 1 samples of filter tail to the full convolution. Raising it by 10 % (to 4.4) moves the result by +0 %, from 8 to 8 samples.
Decimation factor
The decimation factor. Lowers the output length roughly in inverse proportion to M. Raising it by 10 % (to 2.2) moves the result by +0 %, from 8 to 8 samples.
Worked example with the values above
- Upsampled and filtered length: (N − 1)L + H = 4 × 3 + 4 = 16 samples.
- Last index: 15; keep every 2th sample.
- N_out = ⌊15/2⌋ + 1 = 8 samples.
Assumptions and limits
- Integer, positive resampling factors, with a low-pass filter that gives enough alias rejection.
- For analytic-signal formulas, a narrowband signal with a clean quadrature component and less than π of phase change per sample.
Common mistakes
- Not reducing L/M by the common factor, which wastes computation.
- Forgetting the filter delay when counting output samples.
- Using the phase difference when the true change per sample exceeds π.
Statistics and uncertainty
Rates and lengths here are exact integer relations. Estimates of envelope and frequency from analytic samples are sensitive to noise, since the phase of a small sample is poorly defined, so use only samples well above the noise floor.
Where it is used
- Converting between audio and instrumentation sample rates and sizing buffers.
- Demodulating amplitude and frequency from complex baseband data.
Maths you need
- Interpolation and decimation: raising and lowering the sampling rate by integer factors
- Analytic signal: a real signal plus i times its Hilbert transform
- Principal phase: phase wrapped to the range −π to π