Coder Error Matlab Function

10 ビュー (過去 30 日間)
ZHAO HONG QIU
ZHAO HONG QIU 2016 年 2 月 20 日
コメント済み: Rena Berman 2017 年 1 月 24 日
Hi all,
Here is my code
%#eml
function y = m_FFT1(u)
%#codegen
x=u;
Fs=128; %sampling frequency
Ts=1/Fs; %sampling period
N=128; %Sampling point
x=complex(zeros(N,1));
Xre=complex(zeros(N/2,1));
Xim=complex(zeros(N/2,1));
Xre1=complex(zeros(N/2,1));
Xim1=complex(zeros(N/2,1));
sum_all=complex(zeros(N/2,1));
sum_odd=complex(zeros(N/2,1));
sum_even=complex(zeros(N/2,1));
for k=0:N/2-1
% Xre=0; %each one always reset the sum
% Xim=0;
% Xre1=0;
% Xim1=0;
for n=0:N/2-1
%DFT even of x[n]
Xre = Xre+x(2*n+1)*cos(2*pi*k*n/(N/2))/N;
Xim = Xim+x(2*n+1)*(-1j)*sin(2*pi*k*n/(N/2))/N;
%DFT odd of x[n]
Xre1 = Xre1+x(2*n+2)*cos(2*pi*k*n/(N/2))/N;
Xim1 = Xim1+x(2*n+2)*(-1j)*sin(2*pi*k*n/(N/2))/N;
end
sum_even(k+1) = (Xre+Xim);
sum_odd(k+1) = (cos(2*pi*k/N)-1j*sin(2*pi*k/N))*(Xre1+Xim1);
sum_all=(sum_even+sum_odd);
end
y = sum_all;
end
Then display these errors
The right and left hand sides must have the same number of elements.
Function 'm_FFT1' (#44.747.772), line 30, column 6:
"sum_even(k+1) = (Xre+Xim)"
Launch diagnostic report.
Another mistake
The right and left hand sides must have the same number of elements.
Function 'm_FFT1' (#44.781.840), line 31, column 6:
"sum_odd(k+1) = (cos(2*pi*k/N)-1j*sin(2*pi*k/N))*(Xre1+Xim1)"
Launch diagnostic report.
Can anyone help me? Thanks a lot!
  1 件のコメント
Rena Berman
Rena Berman 2017 年 1 月 24 日
(Answers dev) Restored question.

サインインしてコメントする。

回答 (1 件)

Walter Roberson
Walter Roberson 2016 年 2 月 20 日
You defined
Xre=complex(zeros(N/2,1));
Xim=complex(zeros(N/2,1));
so Xre and Xim must be vectors (unless N=2 that is)
Then you have
sum_even(k+1) = (Xre+Xim);
With the Xre and Xim being vectors, adding the two of them will give a vector. And you are trying to store that vector into sum_even(k+1) which is a single location, a scalar.

カテゴリ

Help Center および File ExchangeMATLAB Coder についてさらに検索

タグ

タグが未入力です。

Community Treasure Hunt

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

Start Hunting!

Translated by