can i know the way to code the square wave in Matlab?

1 Ansicht (letzte 30 Tage)
can i know the way to code the square wave in Matlab? the square wave that i need to solve just like in the picture

Akzeptierte Antwort

Azzi Abdelmalek
Azzi Abdelmalek am 22 Mai 2016
t=0:0.01:20;
y=square(t,50),
plot(t,y)
  2 Kommentare
NURRUZAINI MOHD NASIR
NURRUZAINI MOHD NASIR am 23 Mai 2016
Bearbeitet: Azzi Abdelmalek am 23 Mai 2016
by the way i already use this but some error occured... here i attached the appendix that i use
function [a0, a, b] = FourierSeries(f, T, N)
% symbolically calculate the Fourier Series, and return the numerical results
% f: the time domain signal within one period;
% it must have definition over 0<=t<=T
% it must be a symbolic function of t
% T: the period of the signal
% N: number of harmonics to be calculated
syms t % Time t
w0 = 2*pi/T; % Fundamental frequency w0
%%Calculate theFourier series coefficients
a0_sym = 1/T*int(f, t, 0, T); % Calculate a0
a0 = double(a0_sym); % Numerical values of a0
for n = 1:N
a_sym(n) = 2/T*int(f*cos(n*w0*t), t, 0, T); % Calculate an
b_sym(n) = 2/T*int(f*sin(n*w0*t), t, 0, T); % Calculate bn
a(n) = double(a_sym(n)); % Numerical values of an
b(n) = double(b_sym(n)); % Numerical values of bn
end

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by