Clear Filters
Clear Filters

calculating on time of signal

7 views (last 30 days)
ALI MUAAMAR
ALI MUAAMAR on 6 May 2024
Answered: Naren on 7 May 2024
i have 2 square signal with the same amplitude=5 but 2 different on time the first one stays on for 0.4 seconds and the other one for 0.6 and i need a block or a code to use in matlab function that can calculate the time and if it is =0.4 a bit 0 will be the output and if on time was 0.6 bit 1 will be the output.

Accepted Answer

Naren
Naren on 7 May 2024
Hello Ali,
To achieve this in MATLAB, you can create a function that analyzes the square wave signal to determine its on-time duration and then outputs the corresponding bit value based on the duration.
Refer to the following sample code, this method assumes the square signal starts with an "on" state:
onStateDuration = find(sqaureWave==0,1)-1; %no of on state samples.
inSeconds = onStateDuration/samplingRate; %convert on state duration in to seconds.
if (inSeconds == 0.4)
bitOutput = 0;
else
bitOutput = 1;
end
Make changes to the code for desired behavior.
Regards.

More Answers (0)

Categories

Find more on Simulink 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!