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

4 views (last 30 days)

Show older comments

Kalasagarreddi Kottakota
on 13 Jan 2023

Commented: Paul
on 14 Jan 2023

##### 0 Comments

### Accepted Answer

Bruno Luong
on 13 Jan 2023

Edited: Bruno Luong
on 13 Jan 2023

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;

xlabel('Normalized Frequency (\times\pi rad/sample)')

ylabel('Magnitude (dB)')

##### 8 Comments

Paul
on 14 Jan 2023

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.

### More Answers (2)

Bjorn Gustavsson
on 13 Jan 2023

Edited: Bjorn Gustavsson
on 13 Jan 2023

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 Comments

Image Analyst
on 13 Jan 2023

##### 2 Comments

Bjorn Gustavsson
on 13 Jan 2023

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!