This example use a MATLAB System object and a FPGA to verify a register transfer level (RTL) design of a Fast Fourier Transform (FFT) of size 8 written in Verilog. The FFT is commonly used in digital signal processing to produces frequency distribution of a signal.
To verify the correctness of this FFT, a MATLAB System object testbench is provided. This testbench generates a periodic sinusoidal input to the HDL design under test (DUT) and plots the Fourier Coefficients in the Complex Plane.
Before using FPGA-in-the-Loop, make sure your system environment is set up properly for accessing FPGA design software. You can use the function hdlsetuptoolpath to add ISE or Quartus II to the system path for the current MATLAB session.
For Xilinx FPGA boards, run
>>hdlsetuptoolpath('ToolName', 'Xilinx ISE', 'ToolPath', 'C:\Xilinx\13.1\ISE_DS\ISE\bin\nt64\ise.exe');
This example assumes that the Xilinx ISE executable is C:\Xilinx\13.1\ISE_DS\ISE\bin\nt64\ise.exe. Substitute with your actual executable if it is different.
For Altera boards, run
>>hdlsetuptoolpath('ToolName','Altera Quartus II','ToolPath','C:\altera\11.0\quartus\bin\quartus.exe');
This example assumes that the Altera Quartus II executable is C:\altera\11.0\quartus\bin\quartus.exe. Substitute with your actual executable if it is different.
Copy the HDL files for the FFT example into your local directory
Launch the FIL Wizard prepopulated with the FFT example information. Enter your FPGA board information in the first step, follow every step of the Wizard and generate the FPGA programming file and FIL System object.
Program the FPGA with the generated programming file. Before continuing, make sure the FIL Wizard has finished the FPGA programming file generation. Also make sure your FPGA board is turned on and connected properly.
### Generating iMPACT command file ### Checking iMPACT tool ### Start loading bitstream "S:\MATLAB\demo\fft8_fil\fft8_fil.bit" ### Loading bitstream "S:\MATLAB\demo\fft8_fil\fft8_fil.bit" completed successfully
The following code instantiates the system objects that represent the sine wave generator (F=100Hz, Sampling=1000Hz, complex fix point output).
SinGenerator = dsp.SineWave('Frequency ', 100, ... 'Amplitude', 1, ... 'Method', 'Table lookup', ... 'SampleRate', 1000, ... 'OutputDataType', 'Custom', ... 'CustomOutputDataType', numerictype(, 10, 9), ... 'ComplexOutput',true);
fft8_fil is a customized FILSimulation System object, which represents the HDL implementation of the FFT running on the FPGA in this simulation system.
Fft = fft8_fil;
This example simulates the sine wave generator and the FFT HDL implementation via the FPGA-in-the-Loop System object. This section of the code calls the processing loop to process the data sample-by-sample.
for ii=1:1000 % Read 1 sample from the sine wave generator ComplexSinus = step(SinGenerator); % Send/receive 1 sample to/from the HDL FFT on the FPGA [RealFft, ImagFft] = step(Fft,real(ComplexSinus),imag(ComplexSinus)); % Store the FFT sample in a vector ComplexFft(ii) = RealFft + ImagFft*1i; end
Plot the Fourier Coefficients in the Complex Plane.
% Discard the first 12 samples (initialization of the HDL FFT) ComplexFft(1:12)=; % Display the FFT plot(ComplexFft,'ro'); title('Fourier Coefficients in the Complex Plane'); xlabel('Real Axis'); ylabel('Imaginary Axis'); % This concludes the "FPGA-in-the-Loop simulation using MATLAB System % Object" example.