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.m61 chars3 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.m85 chars3 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'.
gistlibby LogSnag