Main Content

このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。

サンプル アンド ホールド システムのシミュレート

この例では、信号のアップサンプリングおよびフィルター処理を行うことでサンプル アンド ホールド システムの出力をシミュレートする方法をいくつか紹介します。

正弦波信号を作成します。16 サンプルといった、信号のちょうど 1 周期に対応するサンプル レートを指定します。信号のステム プロットを描画します。サンプル アンド ホールドを可視化するために階段状グラフを重ね合わせます。

fs = 16;
t = 0:1/fs:1-1/fs;

x = .9*sin(2*pi*t);

stem(t,x)
hold on
stairs(t,x)
hold off

Figure contains an axes object. The axes object contains 2 objects of type stem, stair.

信号を係数 4 でアップサンプリングします。結果を元の信号の一緒にプロットします。upsample は、既存サンプルの間にゼロを追加して信号のサンプル レートを上げます。

ups = 4;

fu = fs*ups;
tu = 0:1/fu:1-1/fu;

y = upsample(x,ups);

stem(tu,y,'--x')

hold on
stairs(t,x)
hold off

Figure contains an axes object. The axes object contains 2 objects of type stem, stair.

移動平均 FIR フィルターを使用したフィルター処理により、これらのゼロをサンプル アンド ホールドの値で埋めます。

h = ones(ups,1);

z = filter(h,1,y);

stem(tu,z,'--.')
hold on
stairs(t,x)
hold off

Figure contains an axes object. The axes object contains 2 objects of type stem, stair.

同じ動作は、MATLAB® 関数 interp1 を使用した最近傍内挿により行えます。その場合、元の信号をシフトしてシーケンスに整列させる必要があります。

zi = interp1(t,x,tu,'nearest');

dl = floor(ups/2);

stem(tu(1+dl:end),zi(1:end-dl),'--.')
hold on
stairs(t,x)
hold off

Figure contains an axes object. The axes object contains 2 objects of type stem, stair.

関数 resample は最後の入力引数をゼロに設定したときに同じ結果を生成します。

q = resample(x,ups,1,0);

stem(tu(1+dl:end),q(1:end-dl),'--.')
hold on
stairs(t,x)
hold off

Figure contains an axes object. The axes object contains 2 objects of type stem, stair.

参考

|