hanning2.m
Final code
function w = hanning2(n,b)
if nargin==1
b='symmetric';
end
if strcmp(b,'symmetric')
n = n+2;
i = 1:n;
w(i,1) = 0.5*(1-cos((2*pi*(i-1))/(n-1)));
elseif strcmp(b,'periodic')
i = 1:n;
w(i,1) = 0.5*(1-cos((2*pi*(i-1))/(n)));
else
disp('Error')
end
Explanation
Matlab's HANNING function does almost exactly the same thing as Matlab's HANN function, except it doesn't include the first and last zeros in the output.
To compare hann(5,'symmetric') VS. hanning(5,'symmetric'):
>>hann(5,'symmetric')
ans=
0
0.5
1
0.5
0
VS.
>>hanning(5,'symmetric')
ans=
0.25
0.75
1
0.75
0.25
HANNING and HAN output is the same for periodic windows (the first zeros is present, the last one isn't, this allows the windows to be appended together without repeating the last point in the first point of the next window).
Code run-through
See Alternative function: hann, it's basically exactly the same except for two lines. When a symmetric window is requested, the index n is extended by two points, the window calculated over the requested length+2, and then the extra line w = w(2:end-1); chops off the first and last values (which are zeros).
No comments:
Post a Comment