hdl implementation of variable-凯发k8网页登录
this example shows how to implement a variable-size fft by using a single fft core.
this example includes two models variablesizeffthdlexample and variablesizefftarbitraryvalidpatternhdlexample that show variable-size fft implementations for different input valid patterns.
many popular standards like wlan, wimax, digital video broadcast (dvb), digital audio broadcast (dab), and long term evolution (lte) provide multiple bandwidth options. the required fft length for ofdm modulation and demodulation for these standards varies with bandwidth option. for example, lte supports different channel bandwidth options from 1.4 mhz to 20 mhz, which require fft lengths of 128 to 2048 respectively. the block generates hdl code for a specific fft length. this example demonstrates how to use the fft block to implement a variable-size fft.
this example generates input data in matlab® and imports it to simulink® for the simulation. the imported data is fed to the implementations of variable-size fft using a single fft and multiple ffts. to demonstrate that the single-fft implementation matches the results of using multiple ffts of various sizes, both the output streams from the simulink simulation are exported to matlab and compared.
model architecture
the top-level subsystem in both the models implement a variable-sized fft. the top subsystem uses a single fft block and the bottom subsystem provides reference data by using multiple fft blocks of various sizes.
the model variablesizeffthdlexample can process data with a gap between valid samples, provided the gap depends on fft length.
modelname = 'variablesizeffthdlexample';
open_system(modelname);
configuration of fft lengths
the fft lengths are specified through a variable fftlenvecmulffts
. the largest of these lengths is stored in a variable fftlensinfft
and used as the fft length for the fft block in the 'variable size fft using single fft'
subsystem.
the input fftlenin
is generated by using the vector of fft lengths specified in fftlenvecmulffts
.
fftlenvecmulffts = [128;256;512;1024;2048]; % single fft length used by variable size fft. fftlensinfft = max(fftlenvecmulffts); % generate |fftlenin| by repeating each element of |fftlenvecmulffts| by % |fftlensinfft| times and arranging in a single column. fflen =repmat(fftlenvecmulffts.',fftlensinfft,1); fftlenin = uint16(fflen(:));
input generation
datain
, validin
, and fftlenin
inputs are generated in matlab and imported to the simulink model. random complex input data randinputdata
is generated for each of the fft lengths specified in fftlenvecmulffts
. different fft lengths correspond to different bandwidths and different sampling rates. for instance, in lte, the fft lengths of 128, 256, 512, 1024, and 2048 correspond to the sampling rates 1.92 mhz, 3.84 mhz, 7.68 mhz, 15.36 mhz, and 30.72 mhz respectively. the symbol time for any fft length is . the example operates at the highest rate among the fft lengths specified.
the datain
signal is generated by padding zeros in between the randinputdata
samples. the figure below shows the input data and valid patterns for fftlenvecmulffts
of 256 and 512 and fftlensinfft
being 2048. for the fft length of 256, the example inserts 7 invalid samples for every valid sample and for the fft length of 512, the code inserts 3 invalid samples for every valid sample.
the model variablesizeffthdlexample requires the input valid pattern to have a gap between valid samples as shown in the figure below.
rng('default'); datain = zeros(length(fftlenvecmulffts)*fftlensinfft,1); validin = false(length(fftlenvecmulffts)*fftlensinfft,1); % loop over the fft lengths for ind = 1:length(fftlenvecmulffts) % generate data of fft length samples randinputdata = complex(randn(1,fftlenvecmulffts(ind)),randn(1,fftlenvecmulffts(ind))); % zero padding in between input data samples upsamplingfac = fftlensinfft/fftlenvecmulffts(ind); datain((ind-1)*fftlensinfft 1:fftlensinfft*ind) = upsample(randinputdata,upsamplingfac); % valid corresponding to the generated data tempvalid = true(1,fftlenvecmulffts(ind)); validin((ind-1)*fftlensinfft 1:fftlensinfft*ind) = upsample(tempvalid,upsamplingfac); end inputdatatype = 'fixdt(1,16,14)'; % input data type can be modified here set_param('variablesizeffthdlexample/data type conversion','outdatatypestr', inputdatatype); % get fft latency fftobj = dsp.hdlfft('fftlength',fftlensinfft,... 'architecture','streaming radix 2^2',... 'complexmultiplication','use 3 multipliers and 5 adders',... 'bitreversedoutput',false,... 'bitreversedinput',false,... 'normalize',false); latency=getlatency(fftobj); % default latency is 4137 for 2048 point fft. additionpipelinedelay = 6; % number of additional pipeline delays % simulink simulation end time total latency = latency of fft latency of % data controller (5 clock cycles). % total simulation running time = total % number of input samples total latency pipeline delay. simtime = fftlensinfft*(length(fftlenvecmulffts) 1) latency additionpipelinedelay ;
variable-size fft using single fft
the 'variable-size fft using single fft'
design includes a data controller, an fft block, and a bin selection subsystem.
open_system([modelname '/variable size fft using single fft']);
the data controller
subsystem controls the input data so that the input to the fft block has data samples with zeros padded in between them. the fft block is configured for an fft length of 2048, the largest fft length required by the lte standard. to simplify selection of the output bins, the fft block is configured to output the samples in bit-natural order. the fft length is specified through input port and is sampled at the start of the frame. the requested fft length must be delayed to match the fft latency. the fft length is registered using the start output signal of the fft and the generated end of the frame signal. this method avoids implementing a large delay-matching memory. since the input data has zeros in between samples, the output of the large fft contains repeated copies of the fft length samples. to get the required fft output, the first fft length samples are collected from the fft output. this operation is performed by modifying the output valid signal of the fft using the bin selection
subsystem.
multiple ffts for reference
this subsystem is used as a reference to compare against the output of variable size fft using single fft. the subsystem includes five different fft blocks (fft 128, fft 256, fft 512, fft 1024, and fft 2048) and one matlab function block. the input data will be fed to all five ffts. depending on the requested fft length, one of the five fft blocks is activated and fft operation is performed. the matlab function block pickfftdata
selects the output from the appropriate fft block. the output is saved to matlab for comparison with the output of the variable-size fft using single fft.
open_system([modelname '/multiple ffts for reference']);
run simulink model
the matlab script configures desired vector of fft lengths, the size of the single fft, and generates input data with a valid signal. it then runs the model, and compares the output of the two subsystems in matlab.
run the model using the sim
command on the matlab command line.
sim(modelname);
verification
the output from both subsystems is sent to the matlab workspace and the difference is plotted. in this case, the output of the two subsystems are identical and the error between the two sets of values is 0.
dataout1 = out1(:); dataout2 = out2(:); figvsf = figure('visible', 'off'); plot(abs(dataout1-dataout2)); title('difference between the two outputs for fixed valid pattern') xlabel('sample index'); ylabel('error'); figvsf.visible = 'on'; bdclose(modelname);
support for arbitrary input valid patterns
the above model variablesizeffthdlexample has a requirement of having a minimum gap between input data samples. the gap depends on the specified fft length and the largest fft length handled by the design. there may be cases where the input data may not conform to this pattern. for example, the data may be continuous and padded with zeros at the end of the input data samples. the following figure shows a contiguous input valid pattern with invalid samples padded at the end of input data samples for fft lengths of 256 and 512. the single fft length is set to 2048. in this case, the 256 valid samples are followed by 1792 invalid samples and the 512 valid samples are followed by 1536 invalid samples.
in such scenario, the design has to store the input samples into a ram, and pad invalid samples between valid samples before sending it on to the fft. the model variablesizefftarbitraryvalidpatternhdlexample can handle any arbitrary pattern of valid input so long as the gap between frames is at least the single fft length (2048 samples for lte). this model is the same as the model variablesizeffthdlexample, except for the data controller subsystem. the data controller subsystem in the model uses a ram of size 2*fftlensinfft
(as shown in the figure below) to store input samples, reads out the valid samples while padding zeros between them and then passing them to the fft. while the input data is being written into one half of the memory, the data is read from the other half of the memory. as a result, the total latency is increased by fftlensinfft
.
modelname = 'variablesizefftarbitraryvalidpatternhdlexample'; load_system(modelname); open_system([modelname '/variable size fft using single fft/data controller']);
arbitrary input data and valid generation
for generating arbitrary data and valid inputs, users can select any of these three options: zero padding of fixed size in between data samples, zero padding at the end of data samples, and zero padding of random size in between data samples. the input data and valid generation for these three different zero padding patterns are shown below. the variablesizefftarbitraryvalidpatternhdlexample model uses the generated data and valid for simulation and verification.
% initialization of input data and valid datain = zeros(length(fftlenvecmulffts)*fftlensinfft,1); validin = false(length(fftlenvecmulffts)*fftlensinfft,1); zeropaddingpattern = 'inbetween'; %'atend','random' switch zeropaddingpattern case 'inbetween' % zero padding in between input data samples for ind = 1:length(fftlenvecmulffts) % generate data of fft length samples randinputdata = complex(randn(1,fftlenvecmulffts(ind)),randn(1,fftlenvecmulffts(ind))); % zero padding in between input data samples upsamplingfac = fftlensinfft/fftlenvecmulffts(ind); datain((ind-1)*fftlensinfft 1:fftlensinfft*ind) = upsample(randinputdata,upsamplingfac); % valid corresponding to the generated data validin((ind-1)*fftlensinfft 1:upsamplingfac:fftlensinfft*ind) = true; end case 'atend' % zero padding at the end of input data samples for ind = 1:length(fftlenvecmulffts) % generate data of fft length samples randinputdata = complex(randn(1,fftlenvecmulffts(ind)),randn(1,fftlenvecmulffts(ind))); % zero padded data datain(((ind-1)*fftlensinfft 1):((ind-1)*fftlensinfft fftlenvecmulffts(ind))) = randinputdata; % valid corresponding to data generated validin(((ind-1)*fftlensinfft 1):((ind-1)*fftlensinfft fftlenvecmulffts(ind))) = true; end otherwise % random for ind =1:length(fftlenvecmulffts) % zero padding at random randindices = randperm(fftlensinfft); % generate data of fft length samples randinputdata = complex(randn(1,fftlenvecmulffts(ind)),randn(1,fftlenvecmulffts(ind))); indices = randindices(1:fftlenvecmulffts(ind)); % if the random indices does not have the first sample if(sum(indices==1)==0) indices(1) = 1; end % zero padded data datain(indices (ind-1)*fftlensinfft) = randinputdata; % valid corresponding to data generated validin(indices (ind-1)*fftlensinfft) = true; end end
run the simulink model
before running the model, make sure that datain
, validin
, fftlenin
, and the necessary variables are initialized.
sim(modelname);
verification
dataout1 = out1(:); dataout2 = out2(:); figvsfaiv = figure('visible', 'off'); plot(abs(dataout1-dataout2)); title('difference between the two outputs for arbitrary valid pattern') xlabel('sample index'); ylabel('error'); figvsfaiv.visible = 'on'; bdclose(modelname);
hdl code generation and verification
to generate the hdl code referenced in this example, an hdl coder™ license is needed.
you can use the commands makehdl
and makehdltb
to generate the hdl code and the testbench for the subsystems.
hdl code generated for the variable size fft subsystems were synthesized for the xilinx® zynq®-7000 zc706 board. the synthesis results are shown in the following table.
the table above shows that implementing a variable-size fft using a single fft uses fewer hardware resources than using a multiple fft solution. to support an arbitrary input valid pattern, the hardware implementation uses more ram.