필터 지우기
필터 지우기

Using the fourier series to approximate a triangular wave.

조회 수: 38 (최근 30일)
Gidel
Gidel 2023년 4월 2일
댓글: Walter Roberson 2023년 4월 3일
I want to approximate a triangular waveform, with the Fourier Series. The triangular waveform has an amplitude of 1 and a frequency of 30 Hz.
and N-values of 1, 5, 10, and 20 number of Fourier terms for approximation.
The only function that I can think of is the sawtooth function. I was wondering if there is a more fitting function for this.
  댓글 수: 1
John D'Errico
John D'Errico 2023년 4월 2일
편집: John D'Errico 2023년 4월 2일
A sawtooth does exactly what you want. So what is the problem?

댓글을 달려면 로그인하십시오.

답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2023년 4월 3일
편집: Sulaymon Eshkabilov 2023년 4월 3일
Here is one simple code how to generate sawtooth approximation using different Fourier series:
t = linspace(0, 10, 1000);
Phase_shift = pi;
ST = sawtooth(2*pi*t*.5+Phase_shift);
plot(t, ST, 'm', 'LineWidth', 2.5, 'DisplayName', 'SawTooth'), hold on
t = linspace(0, 10, 1000);
N = 1;
FS1 = (2/pi)*sin(pi*t*N);
plot(t,FS1, 'r', 'LineWidth', 2, 'DisplayName','N=1')
N=5;
F=0;
for ii = 1:N
F = F+(-1)^(ii+1)*sin(pi*t*ii)*(1/ii);
FS5 = (2/pi)*F;
end
plot(t,FS5, 'g', 'LineWidth', 2, 'DisplayName','N=5')
hold on
N=10;
F=0;
for ii = 1:N
F = F+(-1)^(ii+1)*sin(pi*t*ii)*(1/ii);
FS10 = (2/pi)*F;
end
plot(t,FS10, 'b', 'LineWidth', 2 , 'DisplayName','N=10')
hold on
N=20;
F=0;
for ii = 1:N
F = F+(-1)^(ii+1)*sin(pi*t*ii)*(1/ii);
FS10 = (2/pi)*F;
end
plot(t,FS10, 'k', 'LineWidth', 1.5, 'DisplayName','N=20')
hold off
legend("show")
xlabel("Time, [s]")
ylabel('x(t)')
grid on
title('Sawtooth Approximation with Fourier Series: N = [1, 5, 10, 20]')
xlim([0, 5.5])
  댓글 수: 2
Gidel
Gidel 2023년 4월 3일
The script does not display the figure showed, sorry.
Walter Roberson
Walter Roberson 2023년 4월 3일
The figure you see in @Sulaymon Eshkabilov Answer is the result of running the posted code inside the Answers facility itself. The figure was not inserted as an image: that is actual R2023a output.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Just for fun에 대해 자세히 알아보기

제품


릴리스

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by