I want to convert matlab code to hdl code to dump it in FPGA. to convert this there are two files required i.e matlab file (with m extension) and test bench file (with tb.m extension) . I have only MATlab code what to do for testbench?

2 views (last 30 days)
MATlab software 2014a, windows 8.1 operating system. MAtlab code for transmit diversity technique for wireless communication

Accepted Answer

Tim McBrayer
Tim McBrayer on 13 Mar 2015
The simple answer is that you need to write a testbench.
How do you know that your MATLAB code is correct in implementing your algorithm? A testbench, written in MATLAB. It supplies inputs to your design and reads the design's outputs. It can perform whatever sort of checking you wish to ensure that your design file is operating correctly. It can plot output data, calculate the results using a different method, or whatever you can imagine to ensure that your code is correct. It is vastly faster to validate that your MATLAB code is correct using MATLAB, than it is to run through the full toolchain and see if the FPGA behaves as desired.
Unless you have provided explicit integer or fixed-point data types for every variable in your design, the testbench also helps define what the data types are. MATLAB code is typically written using double data types for variables, which is not generally synthesizable to an FPGA. HDL Coder can use the ranges of the data supplied by your testbench to the design to determine what data type to make each variable in the model. Thus, it is doubly important to write a good testbench, as the testbench will indirectly determine the size of your datapath throughout your design.
  2 Comments
Kairunnisha  Musthafa
Kairunnisha Musthafa on 17 Mar 2015
Thank you sir.This is our MATLAB code we want test bench code for this please help me sir.
#MATLAB code for transmit diversity
clc; clear; close all;
N = 10;
rand('state',0); input = rand(1,N) > 0.5; s = 2*input-1; nTx = 1; Eb_N0_dB = [0:25];
h = 1/sqrt(2)*[randn(nTx,N)+1j*randn(nTx,N)]; h1 = h.*exp(-1j*angle(h));
o1=zeros(1,2); for ii=1:length(Eb_N0_dB) for i=1:N
n= wgn(1,N,0,'complex');
n1= wgn(1,N,0,'complex');
y1 = (h(i).*s(i)) + 10^(-Eb_N0_dB(ii)/20)*n(i);
y2 = (h1(i).*s(i)) + 10^(-Eb_N0_dB(ii)/20)*n1(i);
approx_y1 = y1.*conj(h(i));
approx_y2 = y2.*conj(h1(i));
y=real(approx_y1+approx_y2);
b= [1 -1];
o1(1,1)=dist(y,b(1));
o1(1,2)=dist(y,b(2));
[o3,o4]=min(o1);
y5(1,i)=b(o4);
end Ber(ii)=length(find(s-y5)~=0)/N; end
semilogy(Eb_N0_dB,Ber); grid on; xlabel('Eb/No, dB'); ylabel('Bit Error Rate');

Sign in to comment.

More Answers (0)

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!