# I am having a problem in converting matlab to vhdl code

조회 수: 4(최근 30일)
Shubham Kapoor 2015년 3월 27일
답변: Kiran Kintali 2023년 3월 6일
I want to implement a 16 APSK modulation in hardware.I heard we could use a hdl coder tool to do this
For this,i need to write a test bench waveform too. I need help in writing the code for test bench.
Also,i heard matlab hdl coder does not work with random data function.I have the code for APSK.Please help me out for using it with fixed data.
% Radius of inner and outer circle r1 = 1; r2 = 2; mappingTable=zeros(1,16); % Define mapping table applying Gray mapping for n=0:1:5 mappingTable(n+1) = r1 * exp((1i*2*pi*n)/6); end; for m=0:1:11 mappingTable(m+7) =r2 * exp((1i*2*pi*m)/10); end if mod(numberOfBits, 4) ~= 0 error('numberOfBits must be a multiple of 4.'); end mappedSymbols = zeros(1, numberOfBits / 4); % Map bits to symbols for i = 1:4:length(x)
symbolBits = x(i:i+3);
symbolIndex = 2^3 * symbolBits(1) + 2^2 * symbolBits(2) + 2^1 * symbolBits(3) + 2^0 * symbolBits(4);
% Mapping
mappedSymbols((i - 1)/4 + 1) = mappingTable( symbolIndex +1);
end
SNRdB=20;
meanSignalPower = (r1^2 + r2^2)/2;
SNR = 10^(SNRdB/10); % linear scale
meanNoisePower = meanSignalPower/SNR;
receivedSignal = mappedSymbols + randn(1, length(mappedSymbols)) * sqrt(meanNoisePower/2) +...
1i * randn(1, length(mappedSymbols)) * sqrt(meanNoisePower/2);
% Decision and demapping
receivedBits = zeros(1, numberOfBits / 4);
symbolIndex = minIndex - 1;
bitString = dec2bin(symbolIndex, 4);
end
Error = nnz( x - receivedBits );
BER_sim=Error / numberOfBits; % bit error rate
figure(1);
plot( real(mappedSymbols), imag(mappedSymbols), '.r'); hold off;
xlabel('real part');
ylabel('imaginary part');
grid on;

댓글을 달려면 로그인하십시오.

### 답변(1개)

Kiran Kintali 2023년 3월 6일
Consider reviewing the example below for best practices for MATLAB to HDL code generation.
>> mlhdlc_demo_setup('mlhdlc_fft_channelizer')

댓글을 달려면 로그인하십시오.

### 범주

Find more on Video Formats and Interfaces in Help Center and File Exchange

### Community Treasure Hunt

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

Start Hunting!