2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AD変換に使える量子化器MATLAB/Simulinkでの実装

Posted at

image.png

function [V_out, V_out_inverted, LSB] = stair_filter(V_in, V_min, V_max)
    % stair_filter: 入力電圧をN段階に量子化し、その反転と1 LSBを追加
    % V_in: 入力電圧 (スカラーまたはベクトル)
    % V_min: 最小電圧(グラウンド電圧)
    % V_max: 最大電圧(電源電圧)
    % V_out: 量子化された出力
    % V_out_inverted: 量子化された出力を反転させたもの
    % LSB: 1 LSBの値

    % Nを7に固定
    N = 7;

    % 各段階の幅(1 LSB)を計算
    LSB = (V_max - V_min) / (N - 1);

    % 入力電圧が0のときは出力も0に設定
    if V_in == 0
        V_out = V_min;
    else
        % 入力電圧をN段階に丸める
        V_out = round((V_in - V_min) / LSB) * LSB + V_min;

        % 出力が範囲外にならないように制限
        V_out = min(max(V_out, V_min), V_max);
    end

    % 反転させた出力を計算
    V_out_inverted = -V_out;
end

image.png

image.png

2
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?