how to sample a pulse signal in to 256 samples each?
13 views (last 30 days)
Show older comments
after generating a pulse signal which has on time and off time ..how we sample the on time signal into 256 samples each
0 Comments
Answers (1)
Hari
on 28 May 2025 at 7:56
Hi,
I understand that you want to sample the “on” time of a pulse signal into 256 samples each time the pulse is active.
I assume you have a pulse signal with specified “on” and “off” times and you want to extract and sample only the active “on” parts of this signal.
In order to sample the “on” time of a pulse signal into 256 samples each, you can follow the below steps:
Generate the Pulse Signal:
Use the “Pulse Generator” block in Simulink or create a pulse signal in MATLAB using logical conditions.
fs = 1000; % Sampling frequency in Hz
t = 0:1/fs:5; % Time vector for 5 seconds
dutyCycle = 0.5; % Duty cycle of 50%
pulseSignal = square(2 * pi * 1 * t, dutyCycle * 100); % 1 Hz pulse signal
Identify the “On” Time Indices:
Find the indices where the pulse signal is active (i.e., where the signal is 1).
onIndices = find(pulseSignal > 0);
Segment the “On” Time:
Extract segments of 256 samples each from the “on” time indices.
numSegments = floor(length(onIndices) / 256);
samples = reshape(onIndices(1:numSegments*256), 256, []);
Sample Each Segment:
Iterate over each segment and extract the corresponding signal values.
sampledOnTimes = arrayfun(@(i) pulseSignal(samples(:, i)), 1:numSegments, 'UniformOutput', false);
Use the Sampled Data:
Each element in sampledOnTimes contains 256 samples of the “on” time, which you can further process or analyze.
Refer to the documentation of “square” function to know more about its usage:
Hope this helps!
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!