Where is the problem with my code. it never ends !!
1 view (last 30 days)
Show older comments
What is the problem with the following code?
It calculates the exponential coefficients fo fourier series of periodic function f(t).
when I run it the compilation never ends !! and I must close matlab and run it again.
function [an]=fc(f,T)
syms t n
n=-20:1:20;
an=(1/T)*int(f*exp(-1i*n*2*pi*t/T),t,0,T);
end
syms t n
f=rectangularPulse(t/4)*(abs(t)-1);
%f=rectangularPulse(t);
% f=sin(t);
Y=fc(f,20);
subplot(211)
stem(-20:1:20,abs(Y));
ylabel('|an|')
grid;
subplot(212)
stem(-20:1:20,angle(Y));
ylabel('<an')
grid;
0 Comments
Answers (1)
Geoff Hayes
on 18 May 2018
geometry - your function appears to be recursive
function [an]=fc(f,T)
syms t n
n=-20:1:20;
an=(1/T)*int(f*exp(-1i*n*2*pi*t/T),t,0,T);
end
syms t n
f=rectangularPulse(t/4)*(abs(t)-1);
%f=rectangularPulse(t);
% f=sin(t);
Y=fc(f,20); % <------------------
So it continually calls itself and without a stopping condition, it will call itself forever (!).
0 Comments
See Also
Categories
Find more on Fourier Analysis and Filtering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!