FIR synthesis by frequency sampling
By default, Scilab contains no routine for synthesis FIR
by sampling frequency (equivalent to
fir2 MATLAB function).
There is a function called
fsfirlin but it only computes the
continuous frequency response, without returning the filter coefficients.
However, this method is convenient because it is a very simple way to design
a filter with an arbitrary response, which can be used in particular
to make compensation filters.
This little script is a basic implementation of this technique. Any suggestions for improvements are welcome!
In this example, we do not force the number of coefficients. It is then computed automatically to be 2 times the dimension of the frequential template.
// Example : half-band filter f = [ones(1,8) zeros(1,8)]; h = fsfir_plot(f); // h = a + b * %z^-1 + ...
This example enables to illustrate the fact that if the dimension of the frequential template is not equal to the desired number of coefficients, then the frequencial template is automatically interpolated (linear interpolation).
// Example : half-band filter, with automatic interpolation f = [ones(1,8) zeros(1,8)]; h = fsfir_plot(f,64);
In this example, we designe a filter with arbitrary response:
f = [0:10 10*ones(1,10)]; h = fsfir_plot(f);