# plot Gibbs phenomenon individually???

45 views (last 30 days)
Neptune16 on 25 Nov 2019
Edited: David Goodmanson on 26 Nov 2019 1. In exponential fourier series as above equation(1111.png), theoritically gibb's phenomenon is summation of Xn as above equation (1111.png)... The larger the summation of XN the waveform will get back to its original waveform
2. My question is as in below image (2222.png) 3. I want to plot seperately X1, X2, X3,X4 and X5 ( gibbs phenomenon) . after that I want to plot the summation of yT= X1 + X2 +X3 +X4 +X5
4. I have code it by referring some of the sources in internet as in below image (3333.png). 5.the waveform shape of yT= X1 + X2 +X3 +X4 +X5 is okay. but if we compare the amplitude of yT is not same as the original waveform as in (2222.png)
6. I attached the file of my coding name "individual n=1,2,3,4,5 & sum.m"
##### 2 CommentsShowHide 1 older comment
Neptune16 on 25 Nov 2019
hello, sir.
But have you tried to run my coding that I have attached above? maybe you can help me to modify it.

David Goodmanson on 26 Nov 2019
Edited: David Goodmanson on 26 Nov 2019
Hi Neptune,
I agree that my comment on what the Gibbs phenomenon actually is was not very helpful to the actual problem at hand. The expression for the sawtooth is
A*( 1/2 - Sum((1/(pi*n))*sin(n*w0*t)) ).
where A is the double amplitude of the triangle wave, A = 4 in this case. Since the coefficients are A / (pi*n), your code is too low by a factor of 2. With the method you used, if you had included both positive and negative frequencies in the sum instead of just the positive ones, you would have got the factor of 2.
You have c0 = 2 in the code but it is not being added in successfully. Also your for loops are not exactly for loops since each set of instructions is only done once.
Making a new variable name for every value of n (dynamic variable naming) as you are doing is highly unrecommended. For one thing, if you want to do this process for, say, 100 terms, it’s just not practical. Rather than naming row vectors c1,c2 etc. it’s much better to put all the rows into a matrix and address each row with a row index. So you can do the following.
t = -10:.1:30;
wo=pi/5;
c0 = 2; % c0 = A/2
N= 5;
y = zeros(N,length(t)); % n index down, time across
for n = 1:N
cn1 = 4j/(n*pi);
y(n,:) = real(cn1*exp(1j*n*wo*t)); % drop it into the appropriate row
end
yT = c0 + sum(y); % sum down each column for the sum c1,c2,c3 ...
figure(1)
plot(t,yT);
grid on
Now to do 50 terms you just change N to 50. I hope you will agree that this is highly efficient compared to making a new variable name for every term.
If you do change N to 50 you can see the actual Gibbs phenomenon which are the spikes at y = 4.3 and y = –0.3, approximately. Those get narrower with large N, but they don’t go away. Everywhere else the fourier sum gets closer and closer to the sawtooth wave.

R2018b

### Community Treasure Hunt

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

Start Hunting!