# Effect of windowing on signals

I have an input signal of frequency 1000Hz. Sampling frequency=16kHz. I compute the FFT on 128 input samples and plot the magnitude spectrum. I am not doing the normalization by 128.

My two sided spectrum has magnitude value of 64 on bin frequency 1000Hz. The power spectrum and two sided power spectrum have magnitude values of 4096 on bin frequency 1000Hz.

Now I take Hanning window of length 128, multiply the input signal with the window and take the 128 point FFT. When I plot the two sided spectrum, I am getting a value of 32 on frequency bin 1000Hz, 16 on frequency bin 875Hz and 16 on 1125Hz. For the power spectrum, I get 1024 on frequency bin 1000Hz, 256 on frequency bin 875Hz and 256 on 1125Hz.

How do I check that the values that we get in the frequency domain after using windowing function are correct?

I am not doing the normalization by 128.

That's fine, but ask yourself: why do we sometimes normalize (or scale) by the FFT length? Let's look at Matlab's FFT implementation: $$Y[k] = \sum_{n=0}^{N-1}x[n]e^{-j2\pi kn/N}$$ We could write this as a windowed FFT: $$Y[k] = \sum_{n=0}^{N-1}w[n]\cdot x[n]e^{-j2\pi kn/N}$$ with $$w[n] = 1$$ for $$n = 0 \cdots N-1$$ in the case of a rectangular window, i.e. no windowing.

So for a given bin $$k$$, the value of the associated coefficient $$Y[k]$$ is a weighted sum of complex exponentials over length $$N$$ and weights $$w[n]$$. To have a consistent value regardless of the weights $$w[n]$$, you need some sort of normalization, the most straightforward of which is $$S = \sum_{n=0}^{N-1}w_n$$ This normalization coefficient takes into account both the length of the window $$N$$ and the window gains $$w[n]$$

• In the straight FFT computation, where $$w$$ is a rectangular window, $$S_{rect} = \sum_{n=0}^{N-1}1 = N$$

• In a windowed-FFT computation, $$S$$ takes on different values. For the Hanning window, $$S_{Hanning} \approx 0.5N$$

In your case, if you want the values to match whether you're computing a windowed or non-windowed FFT, you'll want to do some normalization, either of both methods using the correct associated normalization coefficients, or of one of them using the ratio of both coefficients. For your particular case, you'd want to scale the hanning-windowed result by $$\frac{N}{S_{Hanning}}$$

Matlab code:

fs = 16e3; % sampling frequency
N = 128; % input signal length
t = (0:N-1)/fs; % time vector
f = 1000; % input signal frequency

x = sin(2*pi*f*t);
window = hanning(N)';

X = abs(fft(x,N));
X1 = abs(fft(x.*window, N));

plot(X/N);
hold on
plot(X1/sum(window));

% or
plot(X)
hold on
plot(X1 * N/sum(window))

• Also, please do not let previous questions of yours stale. Either mark them accepted or ask for more details in the comment section
– Jdip
Commented Jul 24, 2023 at 17:13