Hello All .I want a solution with a simple explanation
1 次查看(过去 30 天)
显示 更早的评论
5 个评论
Sulaymon Eshkabilov
2021-10-31
Good attempts!
Always, post your work along with your question that helps the audience to see where and how they can help you with your question.
采纳的回答
William Rose
2021-11-1
Since I'm not good at symbolic math in Matlab, I'll give an example of how to do this problem non-symbolically. The code below shows off Matlab's great ability to be smart about adding things up without using for loops.
a0=0.5; A=1; T=2; %mean value; peak2peak amplitude; period
t=(0:.001:2)*T; %time vector for two cycles
b=(2*A/pi)./(1:2:9999); %coefficients for sines (odd only)
w=2*pi*(1:2:9999)/T; %frequencies for sines (odd only)
f=a0-A/2+A*(mod(t,T)<T/2); %exact square wave function
f1=a0+b(1)*sin(w(1)*t); %Fourier series, n=1
f9=a0+b(1:5)*sin(w(1:5)'*t); %Fourier series, n=1:9 odd
f99=a0+b(1:50)*sin(w(1:50)'*t); %Fourier series, n=1:99 odd
f999=a0+b(1:500)*sin(w(1:500)'*t); %Fourier series, n=1:999 odd
f9999=a0+b(1:5000)*sin(w(1:5000)'*t); %Fourier series, n=1:9999 odd
plot(t,f,'-k',t,f1,'-r',t,f9,'-g',t,f99,'-b',t,f999,'-c',t,f9999,'-m');
legend('f(t)','f1','f9','f99','f999','f9999');
Try code above.
3 个评论
William Rose
2021-11-1
@Ahmed Ali , you're welcome.
@Walter Roberson is really good at math and Matlab, so when he gives a hint, as he did in this case, I pay attention.
更多回答(3 个)
Walter Roberson
2021-10-31
Fixing your syntax, but not attempting to fix the logic.
Question: why do you calculate ao, an, bn, if you are not going to use them?
Note: the values for an and bn are correct for those expressions and that integration interval.
syms t n
T = 2 ;
w0 = 2 * pi / T ;
n = [1, 10, 100, 1000, 10000];
ao = ( 1 / T ) * int ( sym(1) , t , 0,2 )
an = ( 2 / T ) * int ( sym(1) * cos ( n * w0 * t ) , t , 0,2 )
bn = ( 2 / T ) * int ( sym(1) * sin ( n * w0 * t ) , t , 0,2 )
ft = (0.5 + 2/pi ) * sum ((1./n) .* sin(n*pi*t))
fplot(ft, [-10 10])
4 个评论
Walter Roberson
2021-11-1
syms t n
T = 2 ;
w0 = 2 * pi / T ;
n = [1, 10, 100, 1000, 10000];
ao = ( 1 / T ) * int ( sym(1) , t , 0,2 )
an = ( 2 / T ) * int ( sym(1) * cos ( n * w0 * t ) , t , 0,2 )
bn = ( 2 / T ) * int ( sym(1) * sin ( n * w0 * t ) , t , 0,2 )
ft = (0.5 + 2/pi ) * sum ((1./n) .* sin(n*pi*t))
fth = matlabFunction(ft);
fplot(fth, [-10 10])
William Rose
2021-11-1
@Walter Roberson said he is correcting your syntax, but not your logic. @Walter Roberson sees that there are logical errors in your code, in addition to syntax errors. Therefore it will not compute the Fourrier series correctly, even when you solve the syntax errors.
I assume the figure you provided represents an infinite pulse train.
Since the function f(t) is odd, except for the mean value, the Fourier series will involve odd terms with sine only, and not any cosine components. In other words, when you solve the integral for the Fourier series coefficients, you will find that all the cosine coefficients are zero, and the sine coefficients are zero when n is even. Therefore only the odd sine coefficients, and the coefficient for the mean value, are non-zero. The Fourier series is therefore
where
(n odd)
where is the mean value, A is the peak-to-peak amplitude, T is the period. In this case, =0.5, A=1, and T=2. Your code should do the summation above, stopping after n=1, 9, 99, 999, 9999.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!