This is the implementation guide for the Bohman window. For theoretical background, including mathematical formula, frequency response, and spectral analysis, see the the article on Bohman window.
All code examples are written in C for maximum performance and portability.
Direct Implementation
The following function computes the Bohman window value for a given sample index n and total window length N. The Bohman window is constructed by convolving two cosine lobes, resulting in very fast sidelobe roll-off.
#include <math.h>
/**
* Compute Bohman window coefficient for a single sample.
*
* @param n Sample index (0 to N-1)
* @param N Total window length
* @return Window coefficient (0.0 to 1.0)
*/
double bohman_window_sample(int n, int N) {
if (N <= 1) return 1.0;
if (n < 0 || n >= N) return 0.0;
double m = (N - 1) / 2.0;
double k = fabs(n - m);
double t = 2.0 * k / (N - 1);
if (t <= 1.0) {
return (1.0 - t) * cos(M_PI * t) + (1.0 / M_PI) * sin(M_PI * t);
} else {
return 0.0;
}
}
Full Array Implementation
For better performance when the entire window is needed, the following function fills a pre-allocated array with all coefficients at once.
#include <math.h>
#include <stdlib.h>
/**
* Generate full Bohman window array.
*
* @param N Length of the window (number of samples)
* @param out Output array of length N (must be pre-allocated)
*/
void bohman_window_array(int N, double *out) {
if (N <= 0) return;
if (N == 1) {
out[0] = 1.0;
return;
}
double m = (N - 1) / 2.0;
for (int i = 0; i < N; i++) {
double k = fabs(i - m);
double t = 2.0 * k / (N - 1);
if (t <= 1.0) {
out[i] = (1.0 - t) * cos(M_PI * t) + (1.0 / M_PI) * sin(M_PI * t);
} else {
out[i] = 0.0;
}
}
}
Optimized Implementation
To avoid recomputing constants repeatedly, here is an optimized version:
/**
* Generate full Bohman window array (optimized).
*
* @param N Length of the window (number of samples)
* @param out Output array of length N (must be pre-allocated)
*/
void bohman_window_array_opt(int N, double *out) {
if (N <= 0) return;
if (N == 1) {
out[0] = 1.0;
return;
}
const double inv_pi = 1.0 / M_PI;
const double m = (N - 1) / 2.0;
const double scale = 2.0 / (N - 1);
for (int i = 0; i < N; i++) {
double t = fabs(i - m) * scale;
if (t <= 1.0) {
out[i] = (1.0 - t) * cos(M_PI * t) + inv_pi * sin(M_PI * t);
} else {
out[i] = 0.0;
}
}
}
Usage Example
The following example demonstrates how to apply the Bohman window to a real signal.
#include <stdio.h>
#include <math.h>
#define N 512
int main() {
double window[N];
double signal[N];
double windowed[N];
/* Generate Bohman window */
bohman_window_array(N, window);
/* Generate test signal (sinusoid with non-integer period) */
for (int i = 0; i < N; i++) {
signal[i] = sin(2 * M_PI * i / 9.5);
}
/* Apply window to signal */
for (int i = 0; i < N; i++) {
windowed[i] = signal[i] * window[i];
}
/* Print first 10 samples */
printf("n window signal windowed\n");
for (int i = 0; i < 10; i++) {
printf("%d %.6f %.6f %.6f\n",
i, window[i], signal[i], windowed[i]);
}
return 0;
}
Expected Output (first 5 samples, N=512)
n window signal windowed 0 0.000000 0.000000 0.000000 1 0.000038 0.647387 0.000025 2 0.000150 0.998351 0.000150 3 0.000335 0.907575 0.000304 4 0.000591 0.460073 0.000272
Implementation Notes
- Convolution of cosine lobes: The Bohman window is constructed by convolving two half-duration cosine lobes.
- Continuous first derivatives: The window has continuous derivatives at the boundaries.
- Endpoints: The window tapers exactly to zero at both ends (n=0 and n=N-1).
- Sidelobe level: First sidelobe at approximately -46 dB.
- Roll-off rate: Very fast – approximately 18 dB per octave.
- Main lobe width: Approximately 0.12–0.13 normalized frequency (wider than Parzen).
- Symmetry: The window is perfectly symmetric:
w[n] = w[N-1-n]for all n. - Edge case N=1: The only coefficient is 1.0.
- Precomputation: For real-time applications, precompute the window once and reuse it for multiple signal blocks.
Alternative: Precomputed Lookup Table
For embedded systems or when speed is critical, precompute the window at compile time:
#define N 512
static const double BOHMAN_WINDOW[N] = {
0.000000, 0.000038, 0.000150, 0.000335, 0.000591, /* ... */
/* Full table would be generated by a script */
};
/* Usage */
for (int i = 0; i < N; i++) {
windowed[i] = signal[i] * BOHMAN_WINDOW[i];
}
Comparison with Other Windows
Window Main lobe First sidelobe Roll-off Best for Rectangular 0.04 -13 dB ~6 dB/oct Resolution Hann 0.08 -31 dB ~18 dB/oct General Hamming 0.08 -41 dB ~6 dB/oct General Parzen 0.09 -40 dB Fast Balance Bohman 0.13 -46 dB ~18 dB/oct High dynamic range Blackman 0.12 -58 dB ~18 dB/oct Leakage suppression
When to Use Bohman
- High dynamic range: Excellent suppression of distant frequency components.
- Fast roll-off required: Approximately 18 dB per octave decay rate.
- Antenna pattern synthesis: Smooth taper with good sidelobe characteristics.
- Precision measurements: When distant interference must be minimized below -80 dB.
Performance Characteristics
Property Value Computational cost Low (one cos, one sin per sample) Memory usage O(N) for array version Numerical stability Excellent Platform suitability Any (no special hardware required)
See also: The Bohman Window in DSP