필터 지우기
필터 지우기

Help recreating square wave from equation

조회 수: 1 (최근 30일)
Mackenzie Weeks
Mackenzie Weeks 2021년 5월 24일
댓글: Mackenzie Weeks 2021년 5월 24일
Hello,
I need help recreating a square wave from the following equation:
Thanks!

채택된 답변

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 24일
편집: Sulaymon Eshkabilov 2021년 5월 24일
Hi,
IHere is the correct code:
t = ..
T = ..
n=1:2:15; % By increasing n = 1:2:25, you will get much better approximation.
U1 = sum((4/pi)*(1./n(:)).*sin(2*pi*n(:).*t/T));
figure
plot(t, U1, 'r')
Good luck.
  댓글 수: 3
Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 24일
편집: Sulaymon Eshkabilov 2021년 5월 24일
Run this or you can increase more n end value:
n=1:2:75; % By increasing, you will get much better approximation
You can run and plot n=1 and n=1:2:75.
Note that the Gibbs phenomenon (ripples on both ends of the rectangle wave) will be present no matter how big the number of series. Study Gibbs phenomenon: https://en.wikipedia.org/wiki/Gibbs_phenomenon
Rectangle wave shown in your given mathworks source is obtained with square() builtin function that is different from this Fourier series approximation.
Good luck.
Mackenzie Weeks
Mackenzie Weeks 2021년 5월 24일
Oh ok I see! Thank you!!

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

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 5월 24일
Hi,
It is a quite straightforward exercise. You can create this signal using a colon operator (:), or [for .. end] or [while .. end] loop. Colon operator is the most efficient one.
Good luck.
  댓글 수: 1
Mackenzie Weeks
Mackenzie Weeks 2021년 5월 24일
편집: Mackenzie Weeks 2021년 5월 24일
Hi
I'm confused by your answer.
This is currently what I have so far, which creates this plot. But im pretty sure the square wave should be closer to the wave itself? I'm supposed to plot where n = 1 3 5 7 and 15.
clc;clear all;
%u(t)= (4/pi) * (1/n)sin * (2*pi*n*
t=0:0.01:1;
T = 1;
n = 5;
x=(4/pi)*(1/n)*sin(2*pi*n*(t/T));
sq= square(x);
figure(1);
plot(t,x)
hold on;
plot(t,sq)

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

카테고리

Help CenterFile Exchange에서 Matrix Indexing에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by