Hello All,
Does anyone know if it is possible to enter the filter coefficents for the digital filter block manually? Also, can IIR filters be supported? Is any of this functionality scheduled to be released in creator 2.0?
Thanks,
Alex
Solved! Go to Solution.
The process which you have to follow to put your own Coefficients are as follows:
1) Place the filter component.
2) Configure Filter component appropriately
a. If you are inserting your own custom coefficients, then parameters such as sample rate, cutoff, and window doesn’t matter.
3) Make sure you don’t need to generate any component code before inserting your custom coefficients.
4) Convert your coefficients, which should be fractions of 1, to a signed fixed point 24-bit number. For example, if you want a coefficient of 2/3, use 2^23 * 2/3 as your filter coefficient.
5) Separate your coefficients out into the format used in Filter_RAM_Data.c. Remember to use little endian format.
6) Once you’ve inserted your custom coefficients into the file, copy them into a text file and save it. You will need to replace the coefficients in Filter_RAM_Data.c next time you generate any components in the project.
7) Build the project, and program your PSoC
Hi AlexB,
Yes, it is possible to enter the filter coefficients for the digital filter block manually.
The Filter component uses the digital filter block (DFB) to implement digital FIR filters. The Filter component is a simplified GUI based component that allows you to create digital filters and implement them, without giving access to the filter coefficients or filter topology. Currently, the tool doesn't allow you to input the custom soefficients directly.
In order to edit the filter’s coefficients, you will need to edit a file called Filter_RAM_Data.c. This file contains the coefficients used by the Filter component.
The filter coefficients are contained in the block named CYCODE Filter_data_b[ ], and are recorded as 32-bit signed hex values.
The hex values are formatted in little endian, so the 0xAA, 0xAA, 0x2A, 0x00 represents the number 0x002AAAAA. The figure above shows the coefficients for a 3-tap FIR moving average filter.
Even though the DFB only uses 24-bit data outside the multiplier/accumulator, the RAM is 32 bits wide. In order to convert from your floating point filter coefficients into appropriate integer values, you can simply multiply your filter coefficient by 2^23 – 1 = 8,388,607.
The hex values are formatted in little endian, so in the figure attached, the 0xAA, 0xAA, 0x2A, 0x00 represents the number 0x002AAAAA. This figure shows the coefficients for a 3-tap FIR moving average filter.
Even though the DFB only uses 24-bit data outside the multiplier/accumulator, the RAM is 32 bits wide. In order to convert from your floating point filter coefficients into appropriate integer values, you can simply multiply your filter coefficient by 2^23 – 1 = 8,388,607.
The process which you have to follow to put your own Coefficients are as follows:
1) Place the filter component.
2) Configure Filter component appropriately
a. If you are inserting your own custom coefficients, then parameters such as sample rate, cutoff, and window doesn’t matter.
3) Make sure you don’t need to generate any component code before inserting your custom coefficients.
4) Convert your coefficients, which should be fractions of 1, to a signed fixed point 24-bit number. For example, if you want a coefficient of 2/3, use 2^23 * 2/3 as your filter coefficient.
5) Separate your coefficients out into the format used in Filter_RAM_Data.c. Remember to use little endian format.
6) Once you’ve inserted your custom coefficients into the file, copy them into a text file and save it. You will need to replace the coefficients in Filter_RAM_Data.c next time you generate any components in the project.
7) Build the project, and program your PSoC
Would Cypress release tools so that we can program the digital filter ourself? Any idea if/when?
Thanks
Dasg,
Thanks for that detailed answer. So it is my understanding that it does not matter what the configurations are in the setup dialog? For example, if my filter is 54 taps, then I just add 54 taps coefficents into the memory array? How does the filter know only to use those set number of taps?
Also, this is for FIR filters only, right? What if I need to do IIR?
Thanks,
Alex
I think you should set the tap number same as what you want in the Creator, and change the coef. manually later.
Ok, we need some explanation to do here. There is som intelligence that the DFB filter itself has as follows. Whenever you configure the DFB component for certain number of taps and stages. The DFB component generates an assembly code that is very similar to a microcontroller code. This assembly code is compiled and loaded in to the filter block. The compiled code knows where to load the coefficients and the data from. It knows how many coeifficients exist and so on. If the filter is configured for multistage operation, the code generated stores the intermediate results and so on. In addition to the assembly code the DFB component in PSoC Creator is also calculating the coefficients based on the component configuration. So if you change the coeifficients yourself, you should be careful to replace the coefficients in the appropriate place.
The above posts put you on the right track.
1) Place the filter component and generate an arbitrary filter with the SAME # of coefficents as your desired response
2) Take your coefficents and scale them with the 2^15, and then represent them in little endian (flipped bit order)
3) Paste them into the coefficents file. Remember to have them copied and pasted somewhere because the file will regenerate!
4) Use the filter
this is what I want to do too... Basically make it work like a variable low pass filter where the knee is variable from a pot (like your radio knob).
does this imply that I have to have discrete designs at particular frequencies and then approximate the knob to that? Or is it possible to cacluate those parmeters and stuff them in the matrix? If so, how?
I am not aware of any ap note yet but you can take a look
at the workspace files for the example filter project in Creator.
There you will find the file with the coefficients that is sourced
out of FLASH from the GUI when you designed the filter.
And you can see the start API and where it places them and
how it does it in DFB engine. That would then give you the tool
to effect your own updates.
I would think in terms of clearing the DFB, stopping it and clearing
it, before Coefficient changes, especially if this is being used in some
feedback loop and involves lifesaving applications.
Regards, Dana.