This shows you the differences between two versions of the page.
Previous revisionNext revision | |||
— | resources:tools-software:sigmastudio:toolbox:filters:firfilter [12 Jun 2020 01:00] – Added python example code Joshua Berlin | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ======FIR Filter====== | ||
+ | [[resources: | ||
+ | ----------------------------------------------------------------------------------------------------- | ||
+ | |||
+ | ====== Overview ====== | ||
+ | |||
+ | {{ firpic1.png}} | ||
+ | The FIR (finite impulse response) block lets you implement any FIR filter desired. | ||
+ | |||
+ | - Drag the block into the workspace. | ||
+ | - Click Table. | ||
+ | - Enter the coefficients as calculated by your chosen software (see below). (Max is 800.) | ||
+ | |||
+ | Frequency response can be shaped by specifying the appropriate filter coefficients, | ||
+ | \\ | ||
+ | {{firpic2.png}}\\ | ||
+ | \\ | ||
+ | |||
+ | You can use this popup window to input as many more coefficients as you desire, resulting in your own custom FIR filter. (Remember, the more numbers the closer to an ideal IIR filter, but at the cost of memory.) | ||
+ | |||
+ | CAD programs are available which simplify the design of lowpass, highpass, bandpass, or bandstop FIR filters. A popular one was developed by Parks and McClellan and uses the Remez exchange algorithm. The design begins by specifying such parameters as passband ripple, stopband [attenuation] ripple, and the transition region. One such CAD program is QED1000 from Momentum Data Systems; a free version is downloadable from www.mds.com. | ||
+ | |||
+ | The frequency response of the filter coefficients in the RMS Table editor figure shown above is pictured below:\\ | ||
+ | \\ | ||
+ | {{firpic3.png}}\\ | ||
+ | \\ | ||
+ | |||
+ | To add input / output sets, right-click and Add Algorithm, IC1, FIR. After the default algorithm is established, | ||
+ | |||
+ | For background detail and theory, see [[resources/ | ||
+ | |||
+ | ====== Scripting the FIR Filter from Python ====== | ||
+ | First, establish a connection between Python and SigmaStudio as described on the page [[resources: | ||
+ | |||
+ | After a connection between Python and SigmaStudio has been established, | ||
+ | |||
+ | Here, fir_filter_coeffs is a list containing the coefficients and ' | ||
+ | |||
+ | <code python> | ||
+ | fir_filter_coeffs = [0.1, 0.8, 0, 0.3, 0, 1, 0.7] | ||
+ | v_obj = VARIANT(pythoncom.VT_ARRAY | pythoncom.VT_R8, | ||
+ | server.SET_OBJECT_PROPERTY(' | ||
+ | # Update the coefficients in SigmaStudio; | ||
+ | server.SET_OBJECT_PROPERTY(' | ||
+ | # so recompile the project. | ||
+ | server.COMPILE_PROJECT | ||
+ | </ | ||
+ | |||
+ | The FIR Filter coefficients can also be read by Python: | ||
+ | |||
+ | <code python> | ||
+ | def print_object_property(block_name, | ||
+ | arg1 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, | ||
+ | arg2 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, | ||
+ | arg3 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, | ||
+ | arg4 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, | ||
+ | arg5 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, | ||
+ | arg6 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, | ||
+ | |||
+ | server.GET_OBJECT_PROPERTY(arg1, | ||
+ | |||
+ | print(block_name + ': ' + param_name + ' has value ' + str(arg4.value[0])) | ||
+ | | ||
+ | print_object_property(' | ||
+ | </ |