# How can I find the filter bandwidth of Savitzky-Golay filtering?

4 ビュー (過去 30 日間)
Kalasagarreddi Kottakota 2023 年 1 月 13 日
コメント済み: Paul 2023 年 1 月 14 日
The matlab function sgolayfilt(x,order,framelength) takes polynomial order and framelength as input arguments. As savitzky acts as a lowpass filter. Is there a possibility to find the filter bandwidth based on the input arguments (order and framelength)?

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

### 採用された回答

Bruno Luong 2023 年 1 月 13 日

sa-golay filter is just non-causal FIR filter, where the coefficients are computed as following
order=3;framelength=11;
B = sgolay(order,framelength,[]);
b = B((framelength-1)./2+1,:);
a = 1;
Here is the frequency response using freqz function
[h,w] = freqz(b,a,2001);
plot(w/pi,20*log10(abs(h)))
ax = gca;
ax.YLim = [-100 20];
ax.XTick = 0:.5:2;
ylabel('Magnitude (dB)')
##### 8 件のコメント表示非表示 7 件の古いコメント
Paul 2023 年 1 月 14 日
I don't understand why you're asking about a causal filter. Did anything in my comment imply that the filter with coefficients b is causal?
To the contrary, the reason for the additional phase shift is that freqz assumes the inputs b,a describe a causal filter, but in this case it isn't. Hence the phase correction is needed.
Assume a simple case with a frame length of 5. The values in b are the coeffiecients of a noncausal filter of the form:
H(z) = b(1)*z^2 + b(2)*z + b(3) + b(4)*z^-1 + b(5)*z^-2
which can be rewritten as
H(z) = z^2 * (b(1) + b(2)*z^-1 + b(3)*z^-2 + b(4)*z^-3 + b(5)*z^-4)
With inputs b and a=1, freqz computes the response of the quantity inside the parentheses. The additional phase shift accounts for the z^2 outside the parentheses.
For completeness, the tf command, w/o additional arguments to specify otherwise, assumes that b, with a=1, describes a filter of the form
H(z) = b(1)*z^4 + b(2)*z^3 + b(3)*z^2 + b(4)*z + b(5)
which is why in that construction we'd divide by z^2.

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

### その他の回答 (2 件)

Bjorn Gustavsson 2023 年 1 月 13 日

QD suggestion:
x = randn(4096,1);
x_sgf = sgolayfilt(x,order,framelength);
fx = fftshift(fft(x));
fxsgf = fftshift(fft(x_sgf));
plot(medtilt1(abs(fxsgf)./abs(fx),3))
That should give you some sense of the filter characteristics. It is a rather brute-force, neither clever nor elegant way of calculating the frequency-response of the filter, but should give you a hint. The medfilt1 step I put in because the ratio became a bit spikey most likely due to numerical precision issues.
HTH
##### 0 件のコメント表示非表示 -1 件の古いコメント

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

Image Analyst 2023 年 1 月 13 日
I'm pretty sure the SG filter is a non-linear, non-causal filter like @Bruno Luong says. (The median filter is another such non-linear filter.) Thus there is no "frequency response" per se for the SG filter with certain parameters. You can only get the empirical frequency response if you know the actual input signal and compare actual, original signal to the filtered version of it. This is what @Bjorn Gustavsson showed. And of course it will vary depending on what your original input signal is.
##### 2 件のコメント表示非表示 1 件の古いコメント
Bjorn Gustavsson 2023 年 1 月 13 日
@Image Analyst, I'm of the understanding that the SG-filters are linear filters (at least I recall reading it that way and getting a proper "aha-moment" when I read that the polynomial fitting actually corresponded to a normal convolution with clever filtering kernels), are you sure that you're right about the non-linear part?

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

### カテゴリ

Find more on Digital Filter Analysis in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!

Translated by