Use higher precision Kaiser.

Add test case for Kaiser window in MATLAB.
This commit is contained in:
Themaister 2013-02-14 12:58:50 +01:00
parent dc413ab605
commit 3e3d9ec3af
4 changed files with 37 additions and 1 deletions

View File

@ -146,7 +146,7 @@ static inline double besseli0(double x)
// Approximate. This is an infinite sum.
// Luckily, it converges rather fast.
for (unsigned i = 0; i < 12; i++)
for (unsigned i = 0; i < 18; i++)
{
sum += x_pow * two_div_pow / (factorial * factorial);

View File

@ -0,0 +1,6 @@
function win = kaiser_window(N, beta)
% Create an N-point kaiser window with given beta.
indices = 2 * (0 : N - 1) / (N - 1) - 1;
mod = modified_bessel(beta);
win = modified_bessel(beta * sqrt(1 - indices.^2)) / mod;

View File

@ -0,0 +1,21 @@
function val = modified_bessel(x)
% Mirrors operation as done in RetroArch. Verify accuracy against Matlab's
% implementation.
sum = zeros(size(x));
factorial = ones(size(x));
factorial_mult = zeros(size(x));
x_pow = ones(size(x));
two_div_pow = ones(size(x));
x_sqr = x .* x;
for i = 0 : 17
sum = sum + x_pow .* two_div_pow ./ (factorial .* factorial);
factorial_mult = factorial_mult + 1.0;
x_pow = x_pow .* x_sqr;
two_div_pow = two_div_pow * 0.25;
factorial = factorial .* factorial_mult;
end
val = sum;

View File

@ -1,6 +1,15 @@
% MATLAB test case for RetroArch SINC upsampler.
close all;
%%
% Test RetroArch's kaiser function.
real_kaiser = kaiser(1024, 10.0)';
rarch_kaiser = kaiser_window(1024, 10.0);
figure('name', 'Bessel function test');
subplot(2, 1, 1), plot(rarch_kaiser), title('RetroArch kaiser');
subplot(2, 1, 2), plot(rarch_kaiser - real_kaiser), title('Error');
%%
% 4-tap and 8-tap are Lanczos windowed, but include here for completeness.
phases = 256;
bw = 0.375;