Question

In: Advanced Math

solve any question about fourier series by using MATLAB

solve any question about fourier series by using MATLAB

Solutions

Expert Solution

this is an example how to plot fourier series in MATLAB.

clear variables
close all
% Fourier series of neither even nor odd function
% Decompose f(x) into even (fe) and odd (fo) functions.
% fe = (f(x) + f(-x))/2, fo = (f(x) - f(-x))/2
N = 500;
L = 4;
xd = -L:2*L/(N-1):L;
y1 = -1/8*xd.^2;
y2 = 1/8*xd.^2;
fo = y1.*(-L<=xd & xd<=0) +y2.*(0<=xd & xd<=L);
fe = 4-xd.^2/8;
f2 = fe + fo;
a0 = 10/3;
% Generate the fourier series of f(x)
y = zeros(1,N);
x = [];
K = 80;
for k = 1:K
ck = 1/(pi*k);
an = (2*L*(-1).^(k+1))*ck^2;
bn = L*(-1).^(k+1)*ck + (2*L*ck^3)*((-1)^k-1);
y = y + (an*cos(pi*k/L*xd)+ bn*sin(pi*k/L*xd)); % For fe and fo
x = [x;y];
end
y = a0 +y;
x = a0 +x;

% Color codes
s = distinguishable_colors(K); % search this function on mathworks

figure
subplot(121) % Plot f(t)
plot(xd,f2,'linewidth',2.5,'color',s(1,:))
line(xlim,[0 0],'color',s(6,:),'linewidth',3);
line([0 0],ylim,'color',s(6,:)','linewidth',3);
ylim([-.5 4]);
a= xlabel('\itt\rm (seconds)');
set(a,'fontsize',20);
a = ylabel('\itf\rm(\itt\rm)');
set(a,'fontsize',20);
a= title('f(t)');
set(a,'fontsize',14);
grid

subplot(122) % Plot fouries series of f(t);
hold on
q = length(x(:,1));
M = 1:q;
for i = 1:6:q
plot(xd,x(i,:),'linewidth',2.5,'color',s(i,:),'DisplayName',sprintf('S = %1.2f',M(i)))
end
a= title('Fourier series of f(t)');
set(a,'fontsize',14);
a= xlabel('\itt\rm (seconds)');
set(a,'fontsize',20);
a = ylabel('\itf\rm(\itt\rm)');
set(a,'fontsize',20);
line(xlim,[0 0],'color',s(6,:),'linewidth',3);
line([0 0],ylim,'color',s(6,:)','linewidth',3);
legend('-DynamicLegend','location','bestoutside');
grid


Related Solutions

Using the method of separation of variables and Fourier series, solve the following heat conduction problem...
Using the method of separation of variables and Fourier series, solve the following heat conduction problem in a rod. ∂u/∂t =∂2u/∂x2 , u(0, t) = 0, u(π, t) = 3π, u(x, 0) = 0
sir I want to make discrete time Fourier series on GUI MATLAB can any one tell...
sir I want to make discrete time Fourier series on GUI MATLAB can any one tell me step by step procedure or coding for Discrete time Fourier series on GUI? pleaseeeee
Solve the following heat equation using Fourier Series uxx = ut, 0 < x < 1,...
Solve the following heat equation using Fourier Series uxx = ut, 0 < x < 1, t > 0, u(0,t) = 0 = u(1,t), u(x,0) = x/2
Solve the following heat equation using Fourier Series uxx = ut, 0 < x < pi,...
Solve the following heat equation using Fourier Series uxx = ut, 0 < x < pi, t > 0, u(0,t) = 0 = u(pi,t), u(x,0) = sinx - sin3x
Solve the following heat equation using Fourier Series uxx = ut, 0 < x < 1,...
Solve the following heat equation using Fourier Series uxx = ut, 0 < x < 1, t > 0, ux(0,t) = 0 = ux(1,t), u(x,0) = 1 - x2
Solve the following wave equation using Fourier Series a2uxx = utt, 0 < x < 1,...
Solve the following wave equation using Fourier Series a2uxx = utt, 0 < x < 1, t > 0, u(0,t) = 0 = u(1,t), u(x,0) = x2, ut(x,0) = 0
Solve the following wave equation using Fourier Series a2uxx = utt, 0 < x < pi,...
Solve the following wave equation using Fourier Series a2uxx = utt, 0 < x < pi, t > 0, u(0,t) = 0 = u(pi,t), u(x,0) = sinx, ut(x,0) = pi - x
Both the Fourier Series and the Discrete Fourier Transform are calculated using summation. Explain the key...
Both the Fourier Series and the Discrete Fourier Transform are calculated using summation. Explain the key differences in what the inputs each of the Fourier Series and the DFT are AND the requirements the inputs.
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft...
Hello, I need the Matlab code of the Fourier Transform without using the Matlab functions fft and dft. Applied to discrete signals. If you can with an example.Thank you!!
define a matlab question and solve with matlab codes (rlc circuts)
define a matlab question and solve with matlab codes (rlc circuts)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT