필터 지우기
필터 지우기

I am having a problem in converting matlab to vhdl code

조회 수: 1 (최근 30일)
Shubham Kapoor
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);
for i = 1:length(receivedSignal)
[mindiff,minIndex] = min(receivedSignal(i) - mappingTable);
symbolIndex = minIndex - 1;
bitString = dec2bin(symbolIndex, 4);
receivedBits((i-1)*4 + 1) = str2double(bitString(1));
receivedBits((i-1)*4 + 2) = str2double(bitString(2));
receivedBits((i-1)*4 + 3) = str2double(bitString(3));
receivedBits((i-1)*4 + 4) = str2double(bitString(4));
end
Error = nnz( x - receivedBits );
BER_sim=Error / numberOfBits; % bit error rate
figure(1);
plot( real(receivedSignal), imag(receivedSignal), '.'); hold on;
plot( real(mappedSymbols), imag(mappedSymbols), '.r'); hold off;
xlabel('real part');
ylabel('imaginary part');
legend('received', 'transmitted');
grid on;

답변 (1개)

Kiran Kintali
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')

카테고리

Help CenterFile Exchange에서 HDL Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by