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

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

 Accepted Answer

t=0:0.01:20;
y=square(t,50),
plot(t,y)

2 Comments

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

Sign in to comment.

More Answers (0)

Categories

Find more on Physics in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!