I am trying to reinvent wheels of fft. But the recursive function of mine seems to be not working due to N
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Steven Lord
2024-5-9
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 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Programming Utilities 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!