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

1 visualización (últimos 30 días)
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

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 22 de Mayo de 2016
t=0:0.01:20;
y=square(t,50),
plot(t,y)
  2 comentarios
NURRUZAINI MOHD NASIR
NURRUZAINI MOHD NASIR el 23 de Mayo de 2016
Editada: Azzi Abdelmalek el 23 de Mayo de 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

Iniciar sesión para comentar.

Más respuestas (0)

Community Treasure Hunt

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

Start Hunting!

Translated by