Skip to content

Instantly share code, notes, and snippets.

@SzShow
Last active October 31, 2019 12:01
Show Gist options
  • Save SzShow/9ce079240140dadf502ff6f42ac2d7cf to your computer and use it in GitHub Desktop.
Save SzShow/9ce079240140dadf502ff6f42ac2d7cf to your computer and use it in GitHub Desktop.
D-subピンの入力から指定したチャンネルを出力する関数
% trg: 元のトリガ波形
% ch: 抽出したいチャンネルの番号
% delay: 一度入力を受け取って、次の入力を受け付けるまでのサンプル数
function out = ExtractTrigger(trg, ch, delay)
% 最初に出力をすべて0で埋める
out = zeros(size(trg));
isTrgGotten = false;
delayCount = 0;
% 全サンプル点を走査
for index = 1:length(trg)
% 1. 現在のサンプル点に変数chで指定したチャンネルの出力がある
% 2. delayで指定した個数分前までに指定したチャンネルの出力がない
% 上記2つの条件を満たした場合に1を出力
if bitand(trg(index), ch, 'int16') == ch && ...
~isTrgGotten
out(index) = 1;
isTrgGotten = true;
end
if isTrgGotten
delayCount = delayCount + 1;
if delayCount == delay
delayCount = 0;
isTrgGotten = false;
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment