how can I get binary output '0'or '1' according to sign of the input value ?

36 ビュー (過去 30 日間)
Sarfaraz Ahmed
Sarfaraz Ahmed 2018 年 10 月 24 日
編集済み: Sarfaraz Ahmed 2018 年 10 月 25 日
Hi. I have output of ADC which give sampled value either negative or positive. I want to decode these values in binary form '1' or '0'. let say if positive value appear, the logic should show '1' otherwise '0'. it means it should be sign-based detection. this logic I need at the end of the system (difference block in attached file). is there any block in simulink or can I make customized code in MATLAB function block ? It would be appreciated if someone can help in this regard.
Thanks in Advance
  2 件のコメント
KSSV
KSSV 2018 年 10 月 24 日
Have a look on sign
Sarfaraz Ahmed
Sarfaraz Ahmed 2018 年 10 月 24 日
編集済み: Sarfaraz Ahmed 2018 年 10 月 24 日
The sign function gives -1 and 1. for example: V = [-0.5 3]; sign(V) Ans -1 1
But I want to get 0 and 1 because I have to forward these binary to XOR logic gate. so how can I decode signed values into binary ?
Thanks

サインインしてコメントする。

採用された回答

Ghetto blaster
Ghetto blaster 2018 年 10 月 24 日
Actually what you would want is step function. heaviside() is most optimal except I assume that you want for the input value of 0 for output to also be 0? In that case you would need to set the HeavisideAtOrigin to be 0. Also I assume you want output to be logical or floating point? heaviside outputs floating.
oldparam = sympref('HeavisideAtOrigin',0);
output_logical = heaviside(input_voltage);
  5 件のコメント
Ghetto blaster
Ghetto blaster 2018 年 10 月 24 日
No worries Ahmed. Glad I could help you.
Sarfaraz Ahmed
Sarfaraz Ahmed 2018 年 10 月 25 日
編集済み: Sarfaraz Ahmed 2018 年 10 月 25 日
Hi. I embed this code in MATLAB function block but it shows an error that: Size mismatch for MATLAB expression 'heaviside'. Expected = 1x1 Actual = 1x0 and if I put output_logical = logical(heaviside(input_voltage)); then it shows an error Class mismatch for variable 'logical'. Expected 'double', Actual 'logical'.
it must be some dimension error how can I resolve this error ? snap is attached.
Thanks

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSubsystems についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by