This is a simplified version of the Savitzky-Golay MATLAB functions (sgolayfilt, sgolay).

function y = sgolay_simplified(x, order, frameLen)
% Compute the Vandermonde matrix
S = (-(frameLen-1)/2:(frameLen-1)/2)' .^ (0:order);

% Compute QR decomposition
[Q,R] = qr(S,0);
% Compute the projection matrix B
B = Q*Q';
% Find the matrix of differentiators
G = Q/R';

% Reshape X into the right dimension.
[x, nshifts] = shiftdim(x);

% Compute the transient on
ybegin = B(end:-1:(frameLen-1)/2+2,:) * x(frameLen:-1:1,:);

% Compute the steady state output
ycenter = filter(B((frameLen-1)./2+1,:), 1, x);

% Compute the transient off
yend = B((frameLen-1)/2:-1:1,:) * x(end:-1:end-(frameLen-1),:);

% Concatenate
y = [ybegin; ycenter(frameLen:end,:); yend];

% Convert Y to the original shape of X
y = shiftdim(y, -nshifts);

I understand how it works and why the math is made that way. But I want to know a bit more.

Question 1

In class I learned that filters have taps and these equal to the number of coefficients of the filter and when the filter is FIR, it equals to the length of the filter. So for this filter is the tap equal to the parameter frameLen?

I thought like this because when the action of the filter is visualized, the filter acts like the moving average filter and takes in a specific amount of points to process at each step.

Question 2

How does the impulse response of the system look like and how can I generate it in MATLAB? I searched online and figured out that it'll look something like below enter image description here

I want to make a function that'll take in parameters (x, order, frameLen) and output an impulse response plot. How can I do this?



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.