simulink matlab function code error?

hello every one , i have been tring to implement calculating twiddle factors in matlab editor using "function", my code is working fine , the same thing i am implementing in the matlab function block in simulink its not working please kindly help, my code in matlab function block is
function y = twiddles_12345(u)
fft_length = input('u');
for mm = 0:1:(fft_length-1)
theta = (-2*pi*mm*1/fft_length);
twiddle(mm+1) = cos(theta) + (1i*(sin(theta)));
y = real(twiddle);
y = y'
end

Antworten (1)

Walter Roberson
Walter Roberson am 30 Nov. 2015

0 Stimmen

Before the loop use
twiddle = complex(zeros(1,fft_length), zeros(1,fft_length));
In the loop you might need
twiddle(mm+1) = complex(cos(theta), sin(theta));

3 Kommentare

Sandeep Kumar
Sandeep Kumar am 2 Dez. 2015
Bearbeitet: Walter Roberson am 2 Dez. 2015
sir, i have made the necessary changes which u said, but still it is showing some errors? it is working in matlab editor, but not in matlab function of simulink???
function y = twiddles_123(u)
fft_length = input('u');
twiddle = complex(zeros(1,fft_length), zeros(1,fft_length));
for mm = 0:1:(fft_length-1)
theta = (-2*pi*mm*1/fft_length);
twiddle(mm+1) = cos(theta) + (1i*(sin(theta)));
twiddle(mm+1) = complex(cos(theta), sin(theta));
y = real(twiddle);
y = y'
end
Walter Roberson
Walter Roberson am 2 Dez. 2015
What errors is it showing?
The
y = real(twiddle);
y = y'
should not be inside the loop.

Melden Sie sich an, um zu kommentieren.

Gefragt:

am 30 Nov. 2015

Kommentiert:

am 2 Dez. 2015

Community Treasure Hunt

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

Start Hunting!

Translated by