Can someone convert this pseudocode to MATLAB code?
Afficher commentaires plus anciens
Algorithm FFT(a, omega)
Input: An n-length coefficient vector a = [a_0,a_1,...,a_(n-1)]
and a primitive nth root of unity omega (n = a power of 2)
Output: A vector y of values of the polynomial for a at the nth roots of unity.
if n=1 then
return y = a.
end
// divide step
a_even = [a_0,a_2,a_4,...,a_(n-2)]
a_odd = [a_1,a_3,a_5,...,a_(n-1)]
// recursive calls with omega^2 as n/2th root of unity
y_even = FFT(a_even, omega^2)
y_odd = FFT(a_odd, omega^2)
x = 1 // storing powers of omega
// combine step, using x = omega^i
for (i=0;i<n/2,i++)
y[i] = y_even[i]+x*y_odd[i]
y[i+n/2] = y_even[i]-x*y_odd[i] // because of reflective prop.
x = x*omega
end
return y
end
1 commentaire
Réponses (1)
Voss
le 17 Déc 2021
function y = myFFT(a, omega)
% Input: An n-length coefficient vector a = [a_0,a_1,...,a_(n-1)]
% and a primitive nth root of unity omega (n = a power of 2)
% Output: A vector y of values of the polynomial for a at the nth roots of unity.
n = numel(a);
if n == 1
y = a;
return
end
% divide step
% a_even = [a_0,a_2,a_4,...,a_(n-2)]
% a_odd = [a_1,a_3,a_5,...,a_(n-1)]
a_even = a(1:2:end);
a_odd = a(2:2:end);
% recursive calls with omega^2 as n/2th root of unity
y_even = myFFT(a_even, omega^2);
y_odd = myFFT(a_odd, omega^2);
x = 1; % storing powers of omega
% combine step, using x = omega^i
for i = 1:n/2
y(i) = y_even(i)+x*y_odd(i);
y(i+n/2) = y_even(i)-x*y_odd(i); % because of reflective prop.
x = x*omega;
end
end
Catégories
En savoir plus sur MATLAB dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!