How to construct a Fourier series using a for loop?
이전 댓글 표시
3. Construct a Fourier series by using a for loop.
Hint: Be reminded from your work on Taylor series in Lab 1.
Note 1: Go with n until 17 instead of ∞.
댓글 수: 6
madhan ravi
2018년 10월 27일
Show us what you have tried
Brandon Burmeister
2018년 10월 27일
편집: Walter Roberson
2026년 3월 7일
Brandon Burmeister
2018년 10월 27일
편집: Brandon Burmeister
2018년 10월 27일
Kevin Chng
2018년 10월 27일
clear all; close all; clc;
incrm=0.01; T0=2; w0=pi;
t=0:0.01:10;
xt = ones(1,numel(t));
xt(t>=1 & t<2 | t>=3 & t<4 | t>=5 & t<=6 | t>=7 & t<=8 | t>=9 & t<=10)=0;
a0 = (1/T0) * trapz(t(1:1+T0/incrm), xt(1:1+T0/incrm), 2);
k=1:17;
for kk = 1 : size(k,2)
ak(kk) = (2/T0) * trapz(t(1:1+T0/incrm-1), xt(1:1+T0/incrm-1).*cos(k(kk)*w0*t(1:1+T0/incrm-1)), 2);
bk(kk) = (2/T0) * trapz(t(1:1+T0/incrm-1), xt(1:1+T0/incrm-1).*sin(k(kk)*w0*t(1:1+T0/incrm-1)), 2);
end
sumk = 0;
for kk = 1 : size(k,2)
sumk = ??
end
xt_FS = ??
figure;
plot(t, xt, 'LineWidth', 2)
grid on
hold on
plot(t, xt_FS, 'r', 'LineWidth', 2)
xlabel('t')
ylabel('x(t)')
legend('x(t)','FS approximation')
title('Approximated Signal vs. Fourier Series')
Help you to make your code easier for reading.
Kevin Chng
2018년 10월 27일
What is the error/problem encountering from the code above? Do you mind to elaborate more?
Brandon Burmeister
2018년 10월 27일
편집: Brandon Burmeister
2018년 10월 27일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Programming에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!