Making a pulse train function, given pulse width and period

7 views (last 30 days)
Hi, I'm trying to make a function, that takes in the pulse width, tau, and the period that each pulse is centred at, T, but I'm having some trouble
Here's what I have:
function [ x ] = pulse( T,tau )
D = [T]; % pulse delay times
t = -T : 1/fs : 2T; % signal evaluation time
w = tau; % width of each pulse
x = pulstran(t,D,@rectpuls,w);
y = rectpuls(t,tau);
plot(x);
plot(y);
end

Accepted Answer

Star Strider
Star Strider on 15 Apr 2014
This works:
pulse = @(T,tau, fs) [zeros(1, round(fs*(T-tau/2))) ones(1, round(fs*tau)) 0];
fs = 100;
T = 15;
tau = 5;
sqpulse = pulse(T,tau, fs);
figure(1)
plot( [1:length(sqpulse)]/fs, sqpulse)
axis([xlim 0 1.1])
grid

More Answers (0)

Products

Community Treasure Hunt

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

Start Hunting!