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

1 次查看(过去 30 天)
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

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2016-5-22
t=0:0.01:20;
y=square(t,50),
plot(t,y)
  2 个评论
NURRUZAINI MOHD NASIR
编辑:Azzi Abdelmalek 2016-5-23
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

请先登录,再进行评论。

更多回答(0 个)

Community Treasure Hunt

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

Start Hunting!

Translated by