PROBLEM WITH THE PLOT OF FOURIER SERIES

4 次查看(过去 30 天)
Hii everyone I have a small problem with the series,
the plot i am doind is not right this should be a plot at a height of 2 and I dont know why this is not what i get
this is what i want to plot when N=100 :
and this is what i get
this is my code :
clc;clear;close all;
syms t k
%D%
T=4; % Period Time
%D%
XT=[1,t,0]
ck=@(x,A,B)(1/T)*int((x*exp(2*pi*k*1i*t/-4)),t,[A,B])
ck1=ck(XT(1),0,1)
ck2=ck(XT(2),1,2)
ck3=ck(XT(3),2,4)
cktotal=ck1+ck2+ck3
%D.1%
NAGATIVESIDE5=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,-5,-1)
POSATIVESIDE5=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,+1,+5)
ALLBUTNOTZERO5=NAGATIVESIDE5+POSATIVESIDE5
%D.2%
NAGATIVESIDE10=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,-10,-1)
POSATIVESIDE10=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,1,10)
ALLBUTNOTZERO10=NAGATIVESIDE10+POSATIVESIDE10
%D.3%
NAGATIVESIDE100=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,-100,-1)
POSATIVESIDE100=symsum(cktotal*exp((2*pi*1i*k*t)/4),k,1,100)
ALLBUTNOTZERO100=NAGATIVESIDE100+POSATIVESIDE100
%plots%
fplot(ALLBUTNOTZERO5,[-10 10],"r")
ylabel("fourier approximation N=-5-->5")
xlabel("time")
grid on
ylim([0 2])
fplot(ALLBUTNOTZERO10,[-10 10],"g")
ylabel("fourier approximation N=-10-->10")
xlabel("time")
grid on
ylim([0 2])
fplot(ALLBUTNOTZERO100,[-10 10],"b")
ylabel("fourier approximation N=-100-->100")
xlabel("time")
grid on
ylim([0 2])

回答(1 个)

Yash
Yash 2023-10-4
Hi Daniel,
I understand that you are facing issues while calculating the Complex Fourier Series of the given piecewise function.
Upon reviewing your code, I have discovered that all the coefficients calculated by you are correct. However, you have not considered the coefficient for "k" equal to zero. You might have encountered a "Division by zero" error while substituting zero in the function for "ck". To overcome this issue, you can calculate the coefficient "c0" separately as follows:
c0 = (1/(2*L))*(int(XT(1),0,1)+int(XT(2),1,2)+ int(XT(3),2,4))
After calculating the coefficient "c0", you need to include it in your function calculation as shown below:
ALLBUTNOTZERO5=c0+NAGATIVESIDE5+POSATIVESIDE5;
By making these adjustments, the peak value should reach the desired value. You can refer to the obtained plot for N=100 below:
I hope this addresses your query.
Best Regards
Yash

类别

Help CenterFile Exchange 中查找有关 MATLAB 的更多信息

产品


版本

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by