Hamming Window Function
Tapering function for spectral analysis. Reduces spectral leakage. Used before FFT. Better frequency resolution than rectangular window.
Visualization
Interactive visualization for Hamming Window Function
Hamming Window:
- • w(n) = 0.54-0.46cos(2πn/(N-1))
- • Reduces spectral leakage
Interactive visualization with step-by-step execution
Implementation
1function hammingWindow(length: number): number[] {
2 const window: number[] = new Array(length);
3 const alpha = 0.54;
4 const beta = 0.46;
5
6 for (let n = 0; n < length; n++) {
7 window[n] = alpha - beta * Math.cos(2 * Math.PI * n / (length - 1));
8 }
9
10 return window;
11}
12
13function applyWindow(signal: number[], window: number[]): number[] {
14 if (signal.length !== window.length) {
15 throw new Error('Signal and window must be same length');
16 }
17
18 return signal.map((s, i) => s * window[i]);
19}
20
21// Common windows
22const windows = {
23 hamming: (n: number) => 0.54 - 0.46 * Math.cos(2 * Math.PI * n),
24 hann: (n: number) => 0.5 - 0.5 * Math.cos(2 * Math.PI * n),
25 blackman: (n: number) => 0.42 - 0.5 * Math.cos(2 * Math.PI * n) + 0.08 * Math.cos(4 * Math.PI * n)
26};Deep Dive
Theoretical Foundation
w[n] = 0.54 - 0.46×cos(2πn/(N-1)). Raised cosine with specific coefficients. Reduces sidelobe level to -43dB. Trade-off: wider main lobe vs lower sidelobes. Hann, Blackman, Kaiser are alternatives.
Complexity
Time
O(n)
O(n)
O(n)
Space
O(n)
Applications
Industry Use
Audio spectrum analysis and visualization
Speech processing and recognition
Vibration analysis in mechanical systems
Radio frequency spectrum monitoring
Biomedical signal analysis (EEG, ECG)
Radar and sonar signal processing
Musical instrument analysis
Use Cases
Related Algorithms
GCD (Euclidean Algorithm)
Compute the Greatest Common Divisor (GCD) of two integers using the Euclidean algorithm. Dating back to around 300 BC and appearing in Euclid's Elements, it's one of the oldest algorithms still in common use. The algorithm is based on the principle that GCD(a,b) = GCD(b, a mod b) and is remarkably efficient with O(log min(a,b)) time complexity. The GCD is the largest positive integer that divides both numbers without remainder.
LCM (Least Common Multiple)
Calculate the Least Common Multiple (LCM) of two integers - the smallest positive integer that is divisible by both numbers. The LCM is intimately related to the GCD through the formula: LCM(a,b) = |a×b| / GCD(a,b). This relationship allows us to compute LCM efficiently using the Euclidean algorithm for GCD, achieving O(log min(a,b)) time complexity instead of naive factorization methods.
Sieve of Eratosthenes
Ancient and highly efficient algorithm to find all prime numbers up to a given limit n. Invented by Greek mathematician Eratosthenes of Cyrene (276-194 BC), this sieve method systematically eliminates multiples of primes, leaving only primes in the array. With O(n log log n) time complexity, it remains one of the most practical algorithms for generating large lists of primes, vastly superior to trial division which runs in O(n² / log n) time.
Prime Factorization
Decompose a positive integer into its unique prime factor representation. Every integer greater than 1 can be expressed as a product of prime numbers in exactly one way (Fundamental Theorem of Arithmetic). This algorithm uses trial division optimized to check only up to √n, as any composite number must have a prime factor ≤ √n. Returns a map of prime factors to their powers, e.g., 360 = 2³ × 3² × 5¹.