calculating on time of signal

11 ビュー (過去 30 日間)
ALI MUAAMAR
ALI MUAAMAR 2024 年 5 月 6 日
回答済み: Naren 2024 年 5 月 7 日
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 Center および File ExchangeSimulink についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by