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!