calculating on time of signal

11 vues (au cours des 30 derniers jours)
ALI MUAAMAR
ALI MUAAMAR le 6 Mai 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.

Réponse acceptée

Naren
Naren le 7 Mai 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.

Plus de réponses (0)

Catégories

En savoir plus sur Simulink dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by