main content

hdl serial architectures for fir filters -凯发k8网页登录

this example illustrates how to generate hdl code for a symmetrical fir filter with fully parallel, fully serial, partly serial, and cascade-serial architectures for a lowpass filter for an audio filtering application.

design the filter

use an audio sampling rate of 44.1 khz and a passband edge frequency of 8.0 khz. set the allowable peak-to-peak passband ripple to 1 db and the stopband attenuation to -90 db. then, design the filter using fdesign.lowpass, and create the fir filter system object™ using the 'equiripple' method with the 'direct form symmetric' structure.

fs           = 44.1e3;         % sampling frequency in hz
fpass        = 8e3;            % passband frequency in hz
fstop        = 8.8e3;          % stopband frequency in hz
apass        = 1;              % passband ripple in db
astop        = 90;             % stopband attenuation in db
fdes = fdesign.lowpass('fp,fst,ap,ast',...
    fpass, fstop, apass, astop, fs);
lpfilter = design(fdes,'equiripple', 'filterstructure', 'dfsymfir', ...
    'systemobject', true);

quantize the filter

assume that the input for the audio filter comes from a 12 bit adc and output is a 12 bit dac.

nt_in = numerictype(1,12,11);
nt_out = nt_in;
lpfilter.fullprecisionoverride = false;
lpfilter.coefficientsdatatype = 'custom';
lpfilter.customcoefficientsdatatype = numerictype(1,16,16);
lpfilter.outputdatatype = 'custom';
lpfilter.customoutputdatatype = nt_out;
% check the response with fvtool.
fvtool(lpfilter,'fs',fs, 'arithmetic', 'fixed');

figure figure 1: magnitude response (db) contains an axes object. the axes object with title magnitude response (db), xlabel frequency (khz), ylabel magnitude (db) contains 3 objects of type line. these objects represent filter #1: quantized, filter #1: reference.

generate fully parallel hdl code from the quantized filter

starting with the correctly quantized filter, generate vhdl® or verilog® code. create a temporary work directory. after generating the hdl code (selecting vhdl in this case), open the generated vhdl file in the editor by clicking on the link displayed in the command line display messages.

the default settings generate a fully parallel architecture. there is a dedicated multiplier for each filter tap in direct form fir filter structure and one for every two symmetric taps in symmetric fir structure. this results in a lot of chip area (78 multipliers, in this example). you can implement the filter in a variety of serial architectures to obtain the desired speed/area trade-off. these architecture options are shown in further sections of this example.

workingdir = tempname;
% fully parallel (default)
generatehdl(lpfilter, 'name', 'fullyparallel', ...
            'targetlanguage', 'vhdl', ...
            'targetdirectory', workingdir, ...
            'inputdatatype', nt_in);
### starting vhdl code generation process for filter: fullyparallel
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/fullyparallel.vhd
### starting generation of fullyparallel vhdl entity
### starting generation of fullyparallel vhdl architecture
### successful completion of vhdl code generation process for filter: fullyparallel
### hdl latency is 2 samples

generate a test bench from the quantized filter

generate a vhdl test bench to make sure that the result matches the response you see in matlab® exactly. the generated vhdl code and vhdl test bench can be compiled and simulated using a simulator.

generate dtmf tones to be used as test stimulus for the filter. a dtmf signal consists of the sum of two sinusoids - or tones - with frequencies taken from two mutually exclusive groups. each pair of tones contains one frequency of the low group (697 hz, 770 hz, 852 hz, 941 hz) and one frequency of the high group (1209 hz, 1336 hz, 1477hz) and represents a unique symbol. this code generates all the dtmf signals and uses only one of them (digit 1 here) for test stimulus. this choice keeps the length of test stimulus to reasonable limit.

symbol = {'1','2','3','4','5','6','7','8','9','*','0','#'};
lfg = [697 770 852 941]; % low frequency group
hfg = [1209 1336 1477];  % high frequency group
% generate a matrix containing all possible combinations of high and low 
% frequencies, where each column represents one combination.
f  = zeros(2,12);
for c=1:4
    for r=1:3
        f(:,3*(c-1) r) = [lfg(c); hfg(r)];
    end
end

next, let's generate the dtmf tones

fs  = 8000;       % sampling frequency 8 khz
n = 800;          % tones of 100 ms
t   = (0:n-1)/fs; % 800 samples at fs
pit = 2*pi*t;
tones = zeros(n,size(f,2));
for tonechoice=1:12
    % generate tone
    tones(:,tonechoice) = sum(sin(f(:,tonechoice)*pit))';
end
% taking the tone for digit '1' for test stimulus.
userstim = tones(:,1);
generatehdl(lpfilter, 'name', 'fullyparallel',...
            'generatehdltestbench','on', ...
            'testbenchuserstimulus', userstim,...
            'targetlanguage', 'vhdl',...
            'targetdirectory', workingdir, ...
            'inputdatatype', nt_in);
### starting vhdl code generation process for filter: fullyparallel
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/fullyparallel.vhd
### starting generation of fullyparallel vhdl entity
### starting generation of fullyparallel vhdl architecture
### successful completion of vhdl code generation process for filter: fullyparallel
### hdl latency is 2 samples
### starting generation of vhdl test bench.
### generating input stimulus
### done generating input stimulus; length 800 samples.
warning: wrap on overflow detected. this originated from 'discretefir'
suggested actions:
    • suppress future instances of this diagnostic from this source. - suppress
### generating test bench: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/fullyparallel_tb.vhd
### creating stimulus vectors ...
### done generating vhdl test bench.

information regarding serial architectures

serial architectures present a variety of ways to share the hardware resources at the expense of increasing the clock rate with respect to the sample rate. in fir filters, we will share the multipliers between the inputs of each serial partition. this will have an effect of increasing the clock rate by a factor known as folding factor.

you can use the hdlfilterserialinfo function to get information regarding various filter lengths based on the value of coefficients. this function also displays an exhaustive table of possible options to specify serialpartition property with corresponding values of folding factor and number of multipliers.

hdlfilterserialinfo(lpfilter, 'inputdatatype', nt_in);
   | total coefficients | zeros | a/symm | effective |
   ---------------------------------------------------
   |         156        |   0   |   78   |     78    |
effective filter length for serialpartition value is 78.
  table of 'serialpartition' values with corresponding values of 
  folding factor and number of multipliers for the given filter.
   | folding factor | multipliers |   serialpartition   |
   ------------------------------------------------------
   |        1       |      78     |ones(1,78)           |
   |        2       |      39     |ones(1,39)*2         |
   |        3       |      26     |ones(1,26)*3         |
   |        4       |      20     |[ones(1,19)*4, 2]    |
   |        5       |      16     |[ones(1,15)*5, 3]    |
   |        6       |      13     |ones(1,13)*6         |
   |        7       |      12     |[ones(1,11)*7, 1]    |
   |        8       |      10     |[ones(1,9)*8, 6]     |
   |        9       |      9      |[9 9 9 9 9 9 9 9 6]  |
   |       10       |      8      |[ones(1,7)*10, 8]    |
   |       11       |      8      |[ones(1,7)*11, 1]    |
   |       12       |      7      |[ones(1,6)*12, 6]    |
   |       13       |      6      |[13 13 13 13 13 13]  |
   |       14       |      6      |[14 14 14 14 14 8]   |
   |       15       |      6      |[15 15 15 15 15 3]   |
   |       16       |      5      |[16 16 16 16 14]     |
   |       17       |      5      |[17 17 17 17 10]     |
   |       18       |      5      |[18 18 18 18 6]      |
   |       19       |      5      |[19 19 19 19 2]      |
   |       20       |      4      |[20 20 20 18]        |
   |       21       |      4      |[21 21 21 15]        |
   |       22       |      4      |[22 22 22 12]        |
   |       23       |      4      |[23 23 23 9]         |
   |       24       |      4      |[24 24 24 6]         |
   |       25       |      4      |[25 25 25 3]         |
   |       26       |      3      |[26 26 26]           |
   |       27       |      3      |[27 27 24]           |
   |       28       |      3      |[28 28 22]           |
   |       29       |      3      |[29 29 20]           |
   |       30       |      3      |[30 30 18]           |
   |       31       |      3      |[31 31 16]           |
   |       32       |      3      |[32 32 14]           |
   |       33       |      3      |[33 33 12]           |
   |       34       |      3      |[34 34 10]           |
   |       35       |      3      |[35 35 8]            |
   |       36       |      3      |[36 36 6]            |
   |       37       |      3      |[37 37 4]            |
   |       38       |      3      |[38 38 2]            |
   |       39       |      2      |[39 39]              |
   |       40       |      2      |[40 38]              |
   |       41       |      2      |[41 37]              |
   |       42       |      2      |[42 36]              |
   |       43       |      2      |[43 35]              |
   |       44       |      2      |[44 34]              |
   |       45       |      2      |[45 33]              |
   |       46       |      2      |[46 32]              |
   |       47       |      2      |[47 31]              |
   |       48       |      2      |[48 30]              |
   |       49       |      2      |[49 29]              |
   |       50       |      2      |[50 28]              |
   |       51       |      2      |[51 27]              |
   |       52       |      2      |[52 26]              |
   |       53       |      2      |[53 25]              |
   |       54       |      2      |[54 24]              |
   |       55       |      2      |[55 23]              |
   |       56       |      2      |[56 22]              |
   |       57       |      2      |[57 21]              |
   |       58       |      2      |[58 20]              |
   |       59       |      2      |[59 19]              |
   |       60       |      2      |[60 18]              |
   |       61       |      2      |[61 17]              |
   |       62       |      2      |[62 16]              |
   |       63       |      2      |[63 15]              |
   |       64       |      2      |[64 14]              |
   |       65       |      2      |[65 13]              |
   |       66       |      2      |[66 12]              |
   |       67       |      2      |[67 11]              |
   |       68       |      2      |[68 10]              |
   |       69       |      2      |[69 9]               |
   |       70       |      2      |[70 8]               |
   |       71       |      2      |[71 7]               |
   |       72       |      2      |[72 6]               |
   |       73       |      2      |[73 5]               |
   |       74       |      2      |[74 4]               |
   |       75       |      2      |[75 3]               |
   |       76       |      2      |[76 2]               |
   |       77       |      2      |[77 1]               |
   |       78       |      1      |[78]                 |

you can use the optional properties 'multipliers' and 'foldingfactor' to display the specific information.

hdlfilterserialinfo(lpfilter, 'multipliers', 4, ...
                    'inputdatatype', nt_in);
serial partition: [20 20 20 18], folding factor:   20, multipliers:    4
hdlfilterserialinfo(lpfilter, 'foldingfactor', 6, ...
                    'inputdatatype', nt_in);
serial partition: ones(1,13)*6, folding factor:    6, multipliers:   13

fully serial architecture

in fully serial architecture, instead of having a dedicated multiplier for each tap, the input sample for each tap is selected serially and is multiplied with the corresponding coefficient. for symmetric (and antisymmetrical) structures the input samples corresponding to each set of symmetric taps are preadded (for symmetric) or pre-subtracted (for anti-symmetric) before multiplication with the corresponding coefficients. the product is accumulated sequentially using a register and the final result is stored in a register before the next set of input samples arrive. this implementation needs a clock rate that is as many times faster than input sample rate as the number of products to be computed. this results in reducing the required chip area as the implementation involves just one multiplier with a few additional logic elements like multiplexers and registers. the clock rate will be 78 times the input sample rate (foldingfactor of 78) equal to 3.4398 mhz for this example.

to implement fully serial architecture, use the hdlfilterserialinfo function and set the 'multipliers' property to 1. you can also set the 'serialpartition' property equal to the effective filter length, which in this case is 78. the function also returns the folding factor and number of multipliers used for that serial partition setting.

[spart, foldingfact, nmults] = hdlfilterserialinfo(lpfilter, 'multipliers', 1, ...
                                    'inputdatatype', nt_in); %#ok
                      
generatehdl(lpfilter,'name', 'fullyserial', ...
           'serialpartition', spart, ...
           'targetlanguage', 'vhdl', ...
           'targetdirectory', workingdir, ...
           'inputdatatype', nt_in);
### starting vhdl code generation process for filter: fullyserial
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/fullyserial.vhd
### starting generation of fullyserial vhdl entity
### starting generation of fullyserial vhdl architecture
### clock rate is 78 times the input sample rate for this architecture.
### successful completion of vhdl code generation process for filter: fullyserial
### hdl latency is 3 samples

generate the test bench the same way, as in the fully parallel case. it is important to generate a test bench again for each architecture implementation.

partly serial architecture

fully parallel and fully serial represent two extremes of implementations. while fully serial is very low area, it inherently needs a faster clock rate to operate. fully parallel takes a lot of chip area but has very good performance. partly serial architecture covers all the cases that lie between these two extremes.

the input taps are divided into sets. each set is processed in parallel by a serial partition consisting of multiply accumulate and a multiplexer. here, a set of serial partitions process a given set of taps. these serial partitions operate in parallel with respect to each other but process each tap sequentially to accumulate the result corresponding to the taps served. finally, the result of each serial partition is added together using adders.

partly serial architecture for resource constraint

let us assume that you want to implement this filter on an fpga which has only 4 multipliers available for the filter. you can implement the filter using 4 serial partitions, each using one multiply accumulate circuit.

hdlfilterserialinfo(lpfilter, 'multipliers', 4, ...
                    'inputdatatype', nt_in);
serial partition: [20 20 20 18], folding factor:   20, multipliers:    4

the input taps that are processed by these serial partitions will be [20 20 20 18]. you will specify serialpartition with this vector indicating the decomposition of taps for serial partitions. the clock rate is determined by the largest element of this vector. in this case the clock rate will be 20 times the input sample rate, 0.882 mhz.

[spart, foldingfact, nmults] = hdlfilterserialinfo(lpfilter, 'multipliers', 4, ...
                                    'inputdatatype', nt_in);
generatehdl(lpfilter,'name', 'partlyserial1',...
            'serialpartition', spart,...
            'targetlanguage', 'vhdl', ...
            'targetdirectory', workingdir, ...
            'inputdatatype', nt_in);
### starting vhdl code generation process for filter: partlyserial1
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/partlyserial1.vhd
### starting generation of partlyserial1 vhdl entity
### starting generation of partlyserial1 vhdl architecture
### clock rate is 20 times the input sample rate for this architecture.
### successful completion of vhdl code generation process for filter: partlyserial1
### hdl latency is 3 samples

partly serial architecture for speed constraint

assume that you have a constraint on the clock rate for filter implementation and the maximum clock frequency is 2 mhz. this means that the clock rate can't be more than 45 times the input sample rate. for such a design constraint, specify the 'serialpartition' as [45 33]. note that this results in an additional serial partition hardware, implying additional circuitry to multiply-accumulate 33 taps. you can specify the 'serialpartition' property using hdlfilterserialinfo and its property 'foldingfactor' as follows.

spart = hdlfilterserialinfo(lpfilter, 'foldingfactor', 45, ...
                            'inputdatatype', nt_in);
generatehdl(lpfilter,'name', 'partlyserial2', ...
            'serialpartition', spart,...
            'targetlanguage', 'vhdl',...
            'targetdirectory', workingdir, ...
            'inputdatatype', nt_in);
### starting vhdl code generation process for filter: partlyserial2
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/partlyserial2.vhd
### starting generation of partlyserial2 vhdl entity
### starting generation of partlyserial2 vhdl architecture
### clock rate is 45 times the input sample rate for this architecture.
### successful completion of vhdl code generation process for filter: partlyserial2
### hdl latency is 3 samples

in general, you can specify any arbitrary decomposition of taps for serial partitions depending on other constraints. the only requirement is that the sum of elements of the vector should be equal the effective filter length.

cascade-serial architecture

the accumulators in serial partitions can be re-used to add the result of the next serial partition. this is possible if the number of taps being processed by one serial partition must be more than that by serial partition next to it by at least 1. the advantage of this technique is that the set of adders required to add the result of all serial partitions are removed. however, this increases the clock rate by 1, as an additional clock cycle is required to complete the additional accumulation step.

cascade-serial architecture can be specified using the property 'reuseaccum'. this can be done in two ways.

add 'reuseaccum' to generatehdl method and specify it as 'on'. note that the value specified for 'serialpartition' property has to be such that the accumulator reuse is feasible. the elements of the vector must be in descending order except for the last two which can be same.

if the property 'serialpartition' is not specified and 'reuseaccum' is specified as 'on', the decomposition of taps for serial partitions is determined internally. this decomposition minimizes the clock rate and reuses the accumulator logic. for this audio filter, the serial partitions are [12 11 10 9 8 7 6 5 4 3 3]. note that it uses 11 serial partitions, implying 11 multiply accumulate circuits. the clock rate will be 13 times the input sample rate, 573.3 khz.

generatehdl(lpfilter,'name', 'cascadeserial1',...
            'serialpartition', [45 33],...
            'reuseaccum', 'on', ...
            'targetlanguage', 'vhdl', ...
            'targetdirectory', workingdir, ...
            'inputdatatype', nt_in);
### starting vhdl code generation process for filter: cascadeserial1
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/cascadeserial1.vhd
### starting generation of cascadeserial1 vhdl entity
### starting generation of cascadeserial1 vhdl architecture
### clock rate is 46 times the input sample rate for this architecture.
### successful completion of vhdl code generation process for filter: cascadeserial1
### hdl latency is 3 samples

optimal decomposition into as many serial partitions required for minimum clock rate possible for reusing accumulator.

generatehdl(lpfilter,'name', 'cascadeserial2', ...
            'reuseaccum', 'on',...
            'targetlanguage', 'vhdl',...
            'targetdirectory', workingdir, ...
            'inputdatatype', nt_in);
### starting vhdl code generation process for filter: cascadeserial2
### generating: /tmp/bdoc23a_2213998_491196/tpa04d4254_1f5e_4ce0_a8bb_668705db1ca2/cascadeserial2.vhd
### starting generation of cascadeserial2 vhdl entity
### starting generation of cascadeserial2 vhdl architecture
### clock rate is 13 times the input sample rate for this architecture.
### serial partition # 1 has 12 inputs.
### serial partition # 2 has 11 inputs.
### serial partition # 3 has 10 inputs.
### serial partition # 4 has 9 inputs.
### serial partition # 5 has 8 inputs.
### serial partition # 6 has 7 inputs.
### serial partition # 7 has 6 inputs.
### serial partition # 8 has 5 inputs.
### serial partition # 9 has 4 inputs.
### serial partition # 10 has 3 inputs.
### serial partition # 11 has 3 inputs.
### successful completion of vhdl code generation process for filter: cascadeserial2
### hdl latency is 3 samples

conclusion

you designed a lowpass direct form symmetric fir filter to meet the given specification. you then quantized and checked your design. you generated vhdl code for fully parallel, fully serial, partly serial and cascade-serial architectures. you generated a vhdl test bench using a dtmf tone for one of the architectures.

you can use an hdl simulator to verify the generated hdl code for different serial architectures. you can use a synthesis tool to compare the area and speed of these architectures. you can also experiment with and generating verilog code and test benches.

网站地图