Coverstion of Matlab code to HDL

2 views (last 30 days)
Neha
Neha on 6 Sep 2013
I tried basic examples of MATLAB to HDL conversions like adder and subtractor. Then I tried running this code.
Code
function x = bpsk( ip , N , Eb_N0_dB)
%N = 10 % number of bits or symbols
% Transmitter
%ip = [0 1 0 1 0 1 0 1 0 1] % generating 0,1 with equal probability
s = 2*ip-1 % BPSK modulation 0 -> -1; 1 -> 1
n = 1/sqrt(2)*[randn(1,N) + j*randn(1,N)] % white gaussian noise, 0dB variance
%Eb_N0_dB = 10 % multiple Eb/N0 values
% Noise addition
y = s + 10^(Eb_N0_dB/20)*n % additive white gaussian noise
% receiver - hard decision decoding
ipHat = real(y)>0
% counting the errors
nErr = size(find([ip- ipHat]),2)
x = nErr/N % simulated ber
theoryBer = 0.5*erfc(sqrt(10.^(Eb_N0_dB/10))) % theoretical ber
end
Please help me in writing test bench. I am getting error when I try to validate the fixed point type conversion . It fails giving errors like function call fails.
My test bench is
f = bpsk( [1 0 1 0 1 0 1 0 1 0 ] ,10 , 2)
f= bpsk( [1 0 1 0 1 0 1 0 1 0 ] ,10 , 8)
Please help me for the same.
  3 Comments
Kaustubha Govind
Kaustubha Govind on 6 Sep 2013
Also, you may want to provide more information about the error message, etc.
Bharath Venkataraman
Bharath Venkataraman on 18 Oct 2013
The first thing you will have to do is replace calls to the functions like randn, erfc - these are not supported for HDL code generation. Do you really want to generate HDL code for the channel as well? If not, I suggest putting that into the testbench rather than the design. For the testbench, what you need to think about is the span of values that the input can take. Providing a good span of values allws float to fixed conversion to assess what the fixed-point datatype needs to be.

Sign in to comment.

Answers (2)

Tim McBrayer
Tim McBrayer on 6 Sep 2013
There are several obvious functions in your code that are not supported for HDL code generation. At first glance, the following are not supported:
  • randn (random number generation)
  • ^ (exponentiation)
  • real(n) (cast to real)
  • find
  • erfc (complementary error function)
  • size (unless the result can be statically determined)
The documentation contains the full list of functions that are supported for HDL code generation. Run this command in MATLAB to open the supported functions table in the doc viewer:
web(fullfile(docroot, 'hdlcoder/ug/fixed-point-run-time-library-support.html'))

Muthu Annamalai
Muthu Annamalai on 6 Sep 2013
@Neha I would recommend thinking your MATLAB function as a chip-design interface, when you want to generate HDL from it.
Whatever pieces of the MATLAB function don't make sense to go into the hardware, should be generated in the testbench and applied as input to the chip.
So really, in your case, you need to provide both input and RNG values to the function, like,
function x = bpsk( ip , n, N , Eb_N0_dB)
and then you want to compare the output of this function with the theoretical BER in the testbench.
Once you have done this, you can implement 10^(Eb_N0_dB/20) by LUT or using a constant input at function.
  1 Comment
Neha
Neha on 7 Sep 2013
Hello Sir
I have removed the step of calculating theoritical BER. I have attache scree shots of the error. I am not able to write the test bench properly. I am getting same errors " Funtion call failed" in Fixed point conversion window.. I would be thankful if u can explain me the steps.
Code {function x = bpsk( ip , N , Eb_N0_dB) %N = 10 % number of bits or symbols % Transmitter %ip = [0 1 0 1 0 1 0 1 0 1] % generating 0,1 with equal probability s = 2*ip-1 % BPSK modulation 0 -> -1; 1 -> 1 n = 1/sqrt(2)*[[ 0 0 0 0 1 1 1 1 1 0] + j*[ 0 0 0 0 1 1 1 1 1 0]] % white gaussian noise, 0dB variance %Eb_N0_dB = 10 % multiple Eb/N0 values % Noise addition y = s + 10^(Eb_N0_dB/20)*n % additive white gaussian noise % receiver - hard decision decoding ipHat = real(y)>0 % counting the errors nErr = size(find([ip- ipHat]),2) x = nErr/N % simulated ber
end }
Test Bench { f = bpsk( [1 0 1 0 1 0 1 0 1 0 ] ,10 , 2) }

Sign in to comment.

Products

Community Treasure Hunt

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

Start Hunting!