implement fft algorithm for fpga -凯发k8网页登录
this example shows how to implement a hardware-targeted fft by using dsp hdl toolbox™ blocks.
signal processing functions and blocks from dsp system toolbox™ provide frame-based, floating-point algorithms and can serve as behavioral references for hardware designs. however, efficient hardware designs must use streaming data interfaces and fixed-point data types. hardware designs also often require control signals such as valid, reset, and backpressure.
the blocks in dsp hdl toolbox libraries provide hardware-optimized algorithms that model streaming data interfaces, hardware latency, and control signals in simulink®. the blocks can process a number of samples in parallel to achieve high throughput such as gigasample-per-second (gsps) rates. you can change the block parameters to explore different hardware implementations. these blocks support hdl code generation and deployment to fpgas with hdl coder™.
this example introduces the hardware-friendly streaming data interface and control signals used by dsp hdl toolbox blocks, and shows how to use the two hardware architectures provided by the fft block. then, it shows how to generate hdl code for your design.
the dsp hdl toolbox fft block provides two architectures optimized for different use cases. you can set the architecture parameter on the block to one of these options.
streaming radix 2^2
— use this option for high throughput applications. the architecture achieves gigasamples per second (gsps) when you use vector input.burst radix 2
— use this option for low area applications. the architecture uses only one complex butterfly.
this example includes two models, which show how to use the streaming and burst architectures of the fft block. the streaming model shows how to use the input and output valid control signals to model data rate independently from the clock rate. the burst model shows how to use the valid control signal to model bursty data streams and how to use a ready signal that indicates when the algorithm can and cannot accept new data samples.
streaming radix 2^2 architecture
modern adcs are capable of sampling signals at sample rates up to several gigasamples per second. however, clock speeds for the fastest fpga fall short of this sample rate. fpgas typically run at hundreds of mhz. one way to perform gsps processing on an fpga is to process multiple samples at the same time at a much lower clock rate. many modern fpgas support the jesd204b standard interface which accepts scalar input at a ghz clock rate, and produces a vector of samples at a lower clock rate. therefore, modern signal processing requires vector processing.
the streaming radix 2^2
architecture is designed to support high-throughput applications. this example model uses an input vector size of 8 and the architecture parameter of the fft block is set to streaming radix 2^2
. for a timing diagram, supported features, and fpga resource usage, see .
modelname = 'ffthdloptimizedexample_streaming';
open_system(modelname);
the initfcn callback function (model properties > callbacks > initfcn) sets parameters for the model. in this example, the parameters control the size of the fft and the input data characteristics.
fftlength = 512;
the input data is two sine waves, 200 khz and 250 khz, each sampled at 1*2e6 hz. the input vector size is 8 samples.
framesize = 8; fs = 1*2e6;
to demonstrate the use of a valid control signal for noncontinuous input data, this example applies valid input every other cycle.
validpattern = [1,0];
open the spectrum viewer and run the example model.
open_system('ffthdloptimizedexample_streaming/spectrum viewer/power spectrum viewer'); set_param(modelname,'simulationcommand','start')
use the logic analyzer to view the input and output signals of the fft streaming
subsystem. the waveform shows that the input valid signal is high every second cycle, and that there is some latency before the block returns the first valid output sample. the block mask displays the latency from the first valid input to the first valid output, assuming no gaps in input valid samples. in this case, the actual latency is longer than the displayed latency because of the gaps in the input stream. the block returns the output data with no gaps in the valid samples.
burst radix 2 (minimum resource) architecture
use the burst radix 2
architecture for applications with limited fpga resources, especially when the fft length is large. this architecture uses only one complex butterfly to calculate the fft. in this model, the architecture parameter of the fft block is set to burst radix 2
.
when you select this architecture, the block has an output control signal, ready, that indicates when the block can accept new input data. the block sets the ready signal to 1 (true
) when it can accept data and starts processing once the whole fft frame is saved into the memory. while processing, the block cannot accept data, so the block sets the ready signal to 0 (false
). you must apply data only when the ready signal is 1. the block ignores any data applied while the ready signal is 0.
for a timing diagram, supported features, and fpga resource usage, see .
modelname = 'ffthdloptimizedexample_burst';
open_system(modelname);
the initfcn callback function (model properties > callbacks > initfcn) sets parameters for the model. in this example, the parameters control the size of the fft and the input data characteristics.
fftlength = 512;
the input data is two sine waves, 200 khz and 250 khz, each sampled at 1*2e6 hz. data is valid every cycle.
fs = 1*2e6; validpattern = 1;
open the spectrum viewer and run the example model.
open_system('ffthdloptimizedexample_burst/spectrum viewer/power spectrum viewer'); set_param(modelname,'simulationcommand','start')
use the logic analyzer to view the input and output signals of the fft burst
subsystem. the waveform shows that the input data arrives in bursts of valid samples, and that there is some latency before the block returns the valid output samples. the latency in the waveform matches the latency displayed on the block mask. the block also returns an output ready signal that indicates when it has room to start accepting the next burst of input data. to ensure that the next burst of input data is not applied before the block sets the ready signal to 1 (true), the model uses the ready signal as an enable signal for the input data generation.
generate hdl code and test bench
you must have the hdl coder product to generate hdl code for this example. your model must have a subsystem that is targeted for hdl code generation.
choose one of the models to generate hdl code and test bench for the fft subsystem.
systemname = 'ffthdloptimizedexample_burst/fft burst';
or
systemname = 'ffthdloptimizedexample_streaming/fft streaming';
then, use this command to generate hdl code for that subsystem. the generated code can be used for any fpga or asic target.
makehdl(systemname);
use this command to generate a test bench that compares the results of an hdl simulation against the simulink simulation behavior.
makehdltb(systemname);
see also
|