Filter löschen
Filter löschen

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

16 Ansichten (letzte 30 Tage)
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)?

Akzeptierte Antwort

Bruno Luong
Bruno Luong am 13 Jan. 2023
Bearbeitet: Bruno Luong am 13 Jan. 2023
sa-golay filter is just non-causal FIR filter, where the coefficients are computed as following
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);
ax = gca;
ax.YLim = [-100 20];
ax.XTick = 0:.5:2;
xlabel('Normalized Frequency (\times\pi rad/sample)')
ylabel('Magnitude (dB)')
  8 Kommentare
Bruno Luong
Bruno Luong am 14 Jan. 2023
@Bjorn Gustavsson to me as soon as one use f(i+j) with j>0 it is non-causal.
This negative lag is translated by the phase shift of exp(1j*w*N) in the transfer function as Paul correctly expressed.
Paul am 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.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (2)

Bjorn Gustavsson
Bjorn Gustavsson am 13 Jan. 2023
Bearbeitet: Bjorn Gustavsson am 13 Jan. 2023
QD suggestion:
x = randn(4096,1);
x_sgf = sgolayfilt(x,order,framelength);
fx = fftshift(fft(x));
fxsgf = fftshift(fft(x_sgf));
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.

Image Analyst
Image Analyst am 13 Jan. 2023
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 Kommentare
Bruno Luong
Bruno Luong am 13 Jan. 2023
Bearbeitet: Bruno Luong am 13 Jan. 2023
I'm pretty sure the SG filter is a non-linear ...
Anything to backup your claim? I give the formula for the (linear) filter corresponds to SG. Ses B = sgolay(order,framelength,[]);
b = B((framelength-1)./2+1,:);
where B is pseudo-inverse of the Vandermonth matrix. b abd B are written as c and J in the wikipedia (section derivation of convolustion coefficients). It is linear since it ths result of l^2 fitting of the polynomial of fix order through a fix number of data.
Bjorn Gustavsson
Bjorn Gustavsson am 13 Jan. 2023
@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?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by