필터 지우기
필터 지우기

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

답변 (1개)

Steven Lord
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.

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by