Generation of basic signals

50 visualizaciones (últimos 30 días)
Thranthar
Thranthar el 21 de Feb. de 2023
Respondida: ileyms el 8 de Mayo de 2024
I just need the code for generating the basic codes like unit step signal, unit impulse signal. unit ramp signal and the sine wave signal.

Respuestas (2)

Sulaymon Eshkabilov
Sulaymon Eshkabilov el 21 de Feb. de 2023
In MATLAB and Simulink, there are few built in functions to generate, such signals as unit step, impulse, unit ramp, sine wave or just using logical and matrix oprations - e.g.:
t = (-.1:.005:2*pi)';
S_step = heaviside(t); % Step using heaviside()
plot(t, S_step, 'r-', 'LineWidth', 2.5, 'DisplayName', 'Unit Step')
legend show
title ('Generated signals')
S_impulse = 10*(t==0); % 10 magnitude Impulse
S_unitstep = t>=0; % Alt. unit step
S_ramp = t.*S_unitstep; % Unit Ramp
S_sine = sin(t); % Sine wave
plot(t, S_impulse, 'k-', 'LineWidth', 2, 'DisplayName', '10 Mag Impulse'),
legend show
plot(t, S_unitstep, 'g--', 'DisplayName', 'Unit Step'), legend show
plot(t, S_ramp, 'm--', 'DisplayName', 'Ramp')
legend show
plot(t, S_sine, 'b--','LineWidth', 1.5, 'displayname', 'Sine')
legend show
grid on
xlim([min(t) max(t)])
ylim([-1.1 1.1])

ileyms
ileyms el 8 de Mayo de 2024
% Define a range of t t = -1:0.01:3;
% Initialize x(t) as an array of zeros with the same length as t xt = zeros(size(t));
% Define x(t) for different ranges of t using conditional statements for i = 1:length(t) if t(i) < 0 xt(i) = 0; elseif t(i) >= 0 && t(i) < 2 xt(i) = 1; else xt(i) = 2; end end
% Plot x(t) figure; plot(t, xt); xlabel('t'); ylabel('x(t)'); title('Piecewise Function'); grid on;

Categorías

Más información sobre Legend en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by