I am trying to reinvent wheels of fft. But the recursive function of mine seems to be not working due to N
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
The following is my code.
return_arr = zeros(N,1);
will create Size inputs must be scalar error.
since N is array. Why did N becomes array?
N =16;
x = zeros(N,1); % original equation to be DFT
for n = 0:(N-1)
x(n+1) = sin((n*x_length*pi/N)) + 5*sin(2*(n)*x_length*pi/N) + 3*sin(4*pi*(n)*x_length*pi/N); % original function
end
for k = 0:(N-1)
test_fft = my_fft(N, x, k);
end
function return_arr = my_fft(N, arr, k)
return_arr = zeros(N,1);
if N > 1
arr_odd = arr(1:2:end);
arr_even = arr(2:2:end);
temp = 2*pi*(k)/N;
return_arr(k+1, 1) = my_fft(arr_even, N/2, k) + (cos(temp) + 1i*sin(temp)) * my_fft(arr_odd, N/2, k);
else
temp = 2*pi*(k)/N;
return_arr(1, 1) = arr * (cos(temp) + 1i*sin(temp));
end
end
0 commentaires
Réponses (1)
Steven Lord
le 9 Mai 2024
Why did N becomes array?
Because in your recursive call:
return_arr(k+1, 1) = my_fft(arr_even, N/2, k) + (cos(temp) + 1i*sin(temp)) * my_fft(arr_odd, N/2, k);
arr_even and arr_odd are non-scalar but you pass them in as the first input to your function.
0 commentaires
Voir également
Catégories
En savoir plus sur Programming Utilities dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!