program for generating a signal giving pulse width and pulse repetition interval and perform fft for ontime signal using counter
10 views (last 30 days)
Show older comments
i need aprogram which generate a signal having on time and off time...by giving pulse width and pulse repetition interval and then perform fft for each 256 samples for on time signal..
0 Comments
Answers (1)
Hari
on 28 May 2025 at 7:54
Hi,
I understand that you want to generate a pulse signal with specified “on” time (pulse width) and “off” time (pulse repetition interval), and then perform an FFT on each block of 256 samples during the “on” time.
In order to generate the signal and perform FFT on the “on” time segments, you can follow the below steps:
Generate the Pulse Signal:
Create a signal with specified pulse width and pulse repetition interval. Use a sampling frequency to ensure accurate representation.
fs = 1000; % Sampling frequency in Hz
pulseWidth = 0.1; % Pulse width in seconds
pulseInterval = 0.5; % Pulse repetition interval in seconds
t = 0:1/fs:5; % Time vector for 5 seconds
pulseSignal = mod(t, pulseInterval) < pulseWidth; % Generate 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);
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, []);
Perform FFT on Each Segment:
Iterate over each segment and compute the FFT using MATLAB’s “fft” function.
fftResults = arrayfun(@(i) fft(pulseSignal(samples(:, i))), 1:numSegments, 'UniformOutput', false);
Analyze the FFT Results:
Each element in fftResults contains the FFT of a 256-sample “on” time segment. You can further analyze or plot these results.
% Example: Plot the magnitude of the FFT for the first segment
plot(abs(fftResults{1}));
title('FFT of First 256-Sample On-Time Segment');
xlabel('Frequency Bin');
ylabel('Magnitude');
Refer to the documentation of “fft” function to know more about its usage:
Hope this helps!
0 Comments
See Also
Categories
Find more on Signal Processing Toolbox in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!