hann function in matlab

The Hann window is a type of taper that is often applied to the edges of a signal to reduce spectral leakage. It is defined as:

w(n) = 0.5 - 0.5 * cos(2pin/(N-1))

where N is the window length and n is the sample number. In MATLAB, the hann function can be used to generate a Hann window of a specified length:

main.m
N = 100; % window length
w = hann(N); % generate Hann window
61 chars
3 lines

This will generate a Hann window of length 100 and store it in the vector 'w'. The window can then be applied to a signal using element-wise multiplication:

main.m
x = randn(1000,1); % generate random signal
x_windowed = x .* w; % apply Hann window
85 chars
3 lines

This will generate a random signal of length 1000 and store it in the vector 'x'. The Hann window is applied to the signal using element-wise multiplication, and the result is stored in the vector 'x_windowed'.

related categories

gistlibby LogSnag