Wiki

no way to compare when less than two revisions

Differences

This shows you the differences between two versions of the page.


Previous revision
Next 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:tools-software:sigmastudio:toolbox:filters|Click here to return to the Filters page]]\\
 +-----------------------------------------------------------------------------------------------------
 +
 +====== 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, as shown here:\\
 +\\
 +{{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, this block can have algorithms added to it. (If you're using more than one DSP board, you will need to add the initial default algorithm for the desired board.) Right-click the block and select Add Algorithm > IC N > Pink Noise Filter. This adds another set of input/output pins for connection. 
 +
 +For background detail and theory, see [[resources/tools-software/sigmastudio/algorithminformation/firfilter|FIR Filter Algorithm]].
 +
 +====== Scripting the FIR Filter from Python ======
 +First, establish a connection between Python and SigmaStudio as described on the page [[resources:tools-software:sigmastudio:usingsigmastudio:scripting:python|SigmaStudio Scripting from Python]].
 +
 +After a connection between Python and SigmaStudio has been established, the FIR Filter can be updated with new coefficients using the following code.
 +
 +Here, fir_filter_coeffs is a list containing the coefficients and 'FIR1' is the name of the FIR block in SigmaStudio.
 +
 +<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, fir_filter_coeffs)
 +server.SET_OBJECT_PROPERTY('setControlValue', 'FIR1', 0, 0, 'Number_of_Coeffs', len(fir_filter_coeffs))
 +# Update the coefficients in SigmaStudio; this reverts the schematic back to design mode...
 +server.SET_OBJECT_PROPERTY('setControlValue', 'FIR1', 0, 0, 'Coefficients', v_obj)
 +# so recompile the project.
 +server.COMPILE_PROJECT
 +</code>
 +
 +The FIR Filter coefficients can also be read by Python:
 +
 +<code python>
 +def print_object_property(block_name, param_name, grow_idx, repeat_idx):
 +    arg1 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, 'getControlValue')
 +    arg2 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, block_name)
 +    arg3 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_ARRAY | pythoncom.VT_VARIANT, [])
 +    arg4 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, grow_idx)
 +    arg5 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_I4, repeat_idx)
 +    arg6 = VARIANT(pythoncom.VT_BYREF | pythoncom.VT_BSTR, param_name)
 +
 +    server.GET_OBJECT_PROPERTY(arg1, arg2, arg3, arg4, arg5, arg6)
 +
 +    print(block_name + ': ' + param_name + ' has value ' + str(arg4.value[0]))
 +    
 +print_object_property('FIR1', 'Coefficients', 0, 0)
 +</code>
resources/tools-software/sigmastudio/toolbox/filters/firfilter.txt · Last modified: 16 Jun 2020 03:15 by Joshua Berlin