Rectangular window (source code)

= Rectangular window

A <rectangular window> keeps all samples in a selected finite record with equal weight and sets the signal outside it to zero. For $N$ discrete samples, $w_n=1$ for $0\le n<N$ and zero otherwise. Calling this no taper does not remove the effect of having a finite record. SciPy's primary implementation documentation identifies the boxcar and rectangular window as this same all-ones choice.<SciPy 1.16.2 documentation>[scipy.signal.windows.boxcar, description and Returns]{ref}

Its <discrete-time Fourier transform> at frequency $\nu$ in cycles per sample is a finite geometric sum:
$$
W_N(\nu)=\sum_{n=0}^{N-1}e^{-2\pi i n\nu}
=e^{-\pi i(N-1)\nu}\frac{\sin(\pi N\nu)}{\sin(\pi\nu)}.
$$
At integer $\nu$, the limiting value is $N$. The first zeros surrounding the central maximum are at $\nu=\pm1/N$, so the central zero-to-zero width is $2/N$. The phase factor depends on the record's time origin; the magnitude response does not.

For a continuous centered record of duration $T$, $w(t)=1$ on $[-T/2,T/2]$ has transform
$$
W(f)=\int_{-T/2}^{T/2}e^{-2\pi ift}\,dt
=T\,\operatorname{sinc}(Tf),
$$
where the normalized <sinc function> is $\operatorname{sinc}(x)=\sin(\pi x)/(\pi x)$. Multiplication by the finite window spreads a sharp spectral component according to this response, producing <spectral leakage>.

An original finite-record example quantifies an off-bin amplitude error. A complex tone of amplitude $A$ lying half a DFT bin from the nearest sampled frequency has normalized response
$$
\frac{|W_N(1/(2N))|}{N}
=\frac1{N\sin(\pi/(2N))}.
$$
At $N=64$ the ratio is about $0.6367$, or $-3.92\,\mathrm{dB}$ relative to the coherent peak. The <coherent gain of a window> is still one; it does not correct this <scalloping loss>. Zero-padding samples the same frequency response more densely rather than lengthening the measured record.

For independent equal-variance sample noise, rectangular weighting has <equivalent noise bandwidth> of one DFT bin under the usual coherent-amplitude normalization. A <Hann window> suppresses distant sidelobes but changes the central width and noise scaling. The primary analysis manual reports these separate window properties rather than one universal best window.<LabVIEW Analysis Concepts by National Instruments>[Printed pp.5-20–5-24 and Table 5-3]{ref}

A proposed test records a known sinusoidal input with an integer and then a non-integer number of cycles in the same record length, holding the sampling rate and amplitude fixed. Compare the raw DFT bins and the continuous window response. This separates finite-record leakage and bin placement from <aliasing>, which involves a different sampling ambiguity.