Help recreating square wave from equation
1 visualizzazione (ultimi 30 giorni)
Mostra commenti meno recenti
Mackenzie Weeks
il 24 Mag 2021
Commentato: Mackenzie Weeks
il 24 Mag 2021
Hello,
I need help recreating a square wave from the following equation:![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/628023/image.jpeg)
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/628023/image.jpeg)
Thanks!
0 Commenti
Risposta accettata
Sulaymon Eshkabilov
il 24 Mag 2021
Modificato: Sulaymon Eshkabilov
il 24 Mag 2021
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 Commenti
Sulaymon Eshkabilov
il 24 Mag 2021
Modificato: Sulaymon Eshkabilov
il 24 Mag 2021
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.
Più risposte (1)
Sulaymon Eshkabilov
il 24 Mag 2021
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 Commento
Vedere anche
Categorie
Scopri di più su Matrix Indexing in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!