calculating on time of signal

7 次查看(过去 30 天)
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.

采纳的回答

Naren
Naren 2024-5-7
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Simulink 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by