このページの内容は最新ではありません。最新版の英語を参照するには、ここをクリックします。
任意の係数による効率的なサンプル レート変換
この例では、任意の係数間で効率的にサンプル レートを変換する方法を示します。
任意の係数によるサンプル レート変換は、数多くのアプリケーション (デジタル受信器のシンボルの同期、音声処理符号化および合成、連続時間システムのコンピューター シミュレーションなど) で必要になります。この例では、信号のサンプリング レートを 8 kHz から 44.1 kHz に変換する場合に、多項式ベースのフィルターおよびポリフェーズ フィルターのカスケードによって効率的なソリューションを形成できる例を見ていきます。
単一ステージおよび 2 ステージのポリフェーズ FIR アプローチ
ポリフェーズ構造は、一般的にマルチレート フィルターの効率的な実装であると見なされます。ただし、分数のサンプル レート変換の場合には、位相数、したがってフィルターの次数が急激に過剰に高くなることがあります。たとえば、信号を 8 kHz から 44.1 kHz にリサンプリングするために、441 で内挿し、80 で間引きするとします (8*441/80=44.1)。ネイティブの単一ステージ FIR レート コンバーターの実装には 10560 個の係数が必要です。
FIRRC = designMultirateFIR(InterpolationFactor=441,DecimationFactor=80,...
StopbandAttenuation=50,SystemObject=true);
cost(FIRRC)
ans = struct with fields:
NumCoefficients: 10560
NumStates: 23
MultiplicationsPerInputSample: 132
AdditionsPerInputSample: 126.5000
これは、2 ステージの場合 (dsp.SampleRateConverter
によって提供される設計など) に、より効率的に実行できます。
SRC = dsp.SampleRateConverter(Bandwidth=6e3, ... InputSampleRate=8e3,OutputSampleRate=44.1e3, ... StopbandAttenuation=50);
info(SRC)
ans = 'Overall Interpolation Factor : 441 Overall Decimation Factor : 80 Number of Filters : 2 Multiplications per Input Sample: 95.175000 Number of Coefficients : 1774 Filters: Filter 1: dsp.FIRRateConverter - Interpolation Factor: 147 - Decimation Factor : 80 Filter 2: dsp.FIRInterpolator - Interpolation Factor: 3 '
cost(SRC)
ans = struct with fields:
NumCoefficients: 1774
NumStates: 30
MultiplicationsPerInputSample: 95.1750
AdditionsPerInputSample: 89.6750
入力サンプルあたりの演算数 (1 段目の終了後に周波数が 14.7 kHz に増加することを考慮して、約 95 の乗算と加算) は妥当な数ですが、この場合には 1774 の係数をメモリに格納しなければなりません。
出力レートの許容誤差の緩和
多数の係数を軽減する方法の 1 つは、出力サンプルの正確なレートが重要でない場合にはレートの許容誤差を設けることです。たとえば、許容誤差 1% を設定すると、出力レートは 44.1 kHz ではなく 44 kHz になります。これは、11 で内挿して 2 で間引きする必要があります。これは単一ステージで効率的に実行できます。この場合、120 係数が必要で、入力サンプルあたりの乗算の数は 60 です。
SRCWithTol = dsp.SampleRateConverter(Bandwidth=6e3, ... InputSampleRate=8e3,OutputSampleRate=44.1e3, ... StopbandAttenuation=50,OutputRateTolerance=0.01); cost(SRCWithTol)
ans = struct with fields:
NumCoefficients: 120
NumStates: 12
MultiplicationsPerInputSample: 60
AdditionsPerInputSample: 55
単一 Farrow アプローチ
多数の係数を保存しなければならないという問題を克服するもう 1 つの方法は、多項式ベースのフィルターです。Farrow 構造は、このようなフィルターの効率的な実装です。
FRC3 = dsp.FarrowRateConverter(InputSampleRate=8e3, ... OutputSampleRate=44.1e3,PolynomialOrder=3); FRC4 = dsp.FarrowRateConverter(InputSampleRate=8e3, ... OutputSampleRate=44.1e3,PolynomialOrder=4); cost(FRC3)
ans = struct with fields:
NumCoefficients: 16
NumStates: 3
MultiplicationsPerInputSample: 66.1500
AdditionsPerInputSample: 60.6375
cost(FRC4)
ans = struct with fields:
NumCoefficients: 25
NumStates: 4
MultiplicationsPerInputSample: 121.2750
AdditionsPerInputSample: 99.2250
3 次多項式では、16 の係数と入力サンプルあたり約 66 の乗算が必要です。4 次多項式は、より高コストでわずかに優れたローパス応答を提供します。係数は 25、入力サンプルあたりの乗算は 121 です。等価の FIR 周波数応答をプロットします。2 ステージ ポリフェーズ FIR 設計は、より鋭い遷移幅をもつ優れたローパス特性を備えています。
SRCstages = getFilters(SRC); F = linspace(0,44.1e3,2048); % Define the frequency range analysis Fs1 = 8e3*147; % The equivalent single stage filter is clocked at 3.53 MHz SRCmag = freqz(SRCstages.Stage1,F,"half",Fs1); FRC3mag = freqz(FRC3,F,"half",3*Fs1); FRC4mag = freqz(FRC4,F,"half",3*Fs1); plot(F/1e3,db(SRCmag/147)); hold on plot(F/1e3,db(FRC3mag/441)); plot(F/1e3,db(FRC4mag/441)); hold off xlabel("Frequency (kHz)") ylabel("Magnitude (dB) (Normalized to 0 dB)") legend(["Polyphase Sample-Rate Converter", ... "3rd-Order Farrow Interpolator","4th-Order Farrow Interpolator"]); ylim([-100 10]) grid on
関数 freqzmr を使用して、各フィルターのインパルス応答の DTFT をプロットします。これらのプロットは、典型的な出力信号のスペクトルがどのように見えるかを示しています。理想的な出力スペクトルは 0 ~ 4 kHz のフラットなローパス信号ですが、FIR フィルター処理および Farrow フィルター処理の制限により、遷移効果と非ゼロの阻止帯域が発生します。それにもかかわらず、サンプル レート コンバーターは、出力スペクトルにおいて優れた遷移帯域および阻止帯域の性能を備えています。
[SRCoutMag,SRCFreq] = freqzmr(SRC); [FRC3outMag,FRC3Freq] = freqzmr(FRC3); [FRC4outMag,FRC4Freq] = freqzmr(FRC4); plot(SRCFreq/1e3,db(SRCoutMag)); hold on plot(FRC3Freq/1e3,db(FRC3outMag)); plot(FRC4Freq/1e3,db(FRC4outMag)); hold off legend(["Polyphase Sample-Rate Converter", ... "3rd-Order Farrow Interpolator",... "4th-Order Farrow Interpolator"]) xlabel("Frequency (kHz)") ylabel("Magnitude (dB)")
出力レートの許容誤差を設定しても、Farrow フィルターの実装コストには大きな影響はありません。しかし、dsp.SampleRateConverter
と同様に、内挿係数と間引き係数は変わります。
FRC_4thWithTol = dsp.FarrowRateConverter(InputSampleRate=8e3, ... OutputSampleRate=44.1e3,PolynomialOrder=4, ... OutputRateTolerance=0.01); info(FRC_4thWithTol)
ans = 12×52 char array
'Discrete-Time FIR Multirate Filter (real) '
'----------------------------------------- '
'Filter Structure : Farrow Sample-Rate Converter'
'Interpolation Factor : 11 '
'Decimation Factor : 2 '
'Filter Length : 5 '
'Stable : Yes '
'Linear Phase : No '
' '
'Arithmetic : double '
'Output Rate Tolerance : 1.000000 % '
'Adjusted Output Rate : 44000.000000 '
cost(FRC_4thWithTol)
ans = struct with fields:
NumCoefficients: 25
NumStates: 4
MultiplicationsPerInputSample: 121
AdditionsPerInputSample: 99
Farrow および FIR ポリフェーズ構造のカスケード
次に、これまでに見てきた 2 種類のフィルターを利用した複合ソリューションを設計してみましょう。ポリフェーズ フィルターは、整数ファクターによる内挿または間引きと、内挿係数および間引き係数が低い非整数レート変換に特に適しています。Farrow フィルターは任意の (無理数を含む) レート変換ファクターを効果的に実装できます。まず、FIR ハーフバンド フィルターのカスケードを使用して、元の 8 kHz 信号を 4 で内挿します。
intSRC = dsp.SampleRateConverter(Bandwidth=6e3, ... InputSampleRate=8e3,OutputSampleRate=32e3, ... StopbandAttenuation=50); info(intSRC)
ans = 'Overall Interpolation Factor : 4 Overall Decimation Factor : 1 Number of Filters : 1 Multiplications per Input Sample: 34.000000 Number of Coefficients : 34 Filters: Filter 1: dsp.FIRInterpolator - Interpolation Factor: 4 '
次に、44.1/32 = 1.378125 によって中間の 32 kHz 信号を内挿し、目的の最終的な 44.1 kHz のサンプリング周波数を取得します。この目的には 3 次ラグランジュ多項式ベース フィルターを使用します。
FRC = dsp.FarrowRateConverter(InputSampleRate=32e3, ...
OutputSampleRate=44.1e3,PolynomialOrder=3);
全体的なフィルターは、単に 2 つのフィルターをカスケードすることで求めます。
cost(intSRC)
ans = struct with fields:
NumCoefficients: 34
NumStates: 11
MultiplicationsPerInputSample: 34
AdditionsPerInputSample: 31
cost(FRC)
ans = struct with fields:
NumCoefficients: 16
NumStates: 3
MultiplicationsPerInputSample: 16.5375
AdditionsPerInputSample: 15.1594
このハイブリッド設計の非ゼロかつ 1 でない係数の数は比較的低く (34+12=46)、入力サンプルあたりの乗算の数も比較的低く (34 + 16.5375*4 ≈ 92) なります。
hybrid = cascade(intSRC, FRC); cost(hybrid)
ans = struct with fields:
NumCoefficients: 46
NumStates: 14
MultiplicationsPerInputSample: 100.1500
AdditionsPerInputSample: 91.6375
単一ステージ設計と多段設計の周波数応答を重ねます。明らかに、多段応答 (ハイブリッドおよび SRC) は互いに同等であり、FRC3 フィルターと FRC4 フィルターの応答よりも優れています。
[HybridOutMag, HybridFreq] = freqzmr(hybrid); plot(SRCFreq,db(SRCoutMag)); hold on plot(FRC3Freq,db(FRC3outMag)); plot(FRC4Freq,db(FRC4outMag)); plot(HybridFreq,db(HybridOutMag)); hold off xlabel("Frequency (Hz)") ylabel("Magnitude (dB)") legend(["Polyphase Sample-Rate Converter", ... "3rd-Order Farrow Interpolator",... "4th-Order Farrow Interpolator",... "Combined polyphase and Farrow sample rate converters"],... Location="SouthWest")
ホワイト ノイズによるランダムな入力励起に対する応答を経験的に解析することで、パフォーマンスを検証できます。
scope = spectrumAnalyzer(SampleRate=44.1e3,PlotAsTwoSidedSpectrum=false, ... YLimits=[-80 20],ShowLegend=true, ... ChannelNames=["Multi-stage design","Hybrid Farrow-Polyphase design"]); tic, while toc < 10 % Run for 20 seconds x = randn(8000,1); % Convert rate using multistage FIR filters y1 = SRC(x); % Convert rate using cascade of multistage FIR and Farrow filter y2 = hybrid(x); % Compare the output from both approaches scope([y1,y2]) end