I am facing an issue while converting my OFDM code from matlab to HDL during fixed point conversion
6 ビュー (過去 30 日間)
古いコメントを表示
This is my ofdm code , which simulates ofdm reciever and transmitter , over a rayleigh channel , using 16Qam modulation, with doppler.
function [BitsRx] = OfdmDopplerBer(~)
Rs = 54.64e5;
% Symbol Duration, [s]
Ts = 1/Rs;
% Carrier Frequency, [Hz]
f = 1.5e9;
% Modulation Order of QPSK by definition
M = 16;
% Number of Bits in QPSK Symbol
k = log2(M);
% QPSK Signal Bandwidth, [Hz]
F = 1/Ts;
% Number of Subcarriers (equal to Number of FFT points)
numSC = 1024;
%NumSymbols=3;
% Guard Bands Subcarriers
GuardBandSC = [10; 10];
% Central Null Subcarrier
DCNull = true;
DCNullSC = numSC/2 + 1;
% Number of Pilot Subcarriers
numPilotSC = 10;
PilotSC =[15 125 236 346 456 567 677 787 898 1008]';
% Length of Cyclic Prefix
lenCP = numSC/4;
% OFDM Modulator Object
OFDMModulator = comm.OFDMModulator( ...
'FFTLength', numSC, ...
'NumGuardBandCarriers', GuardBandSC, ...
'Windowing',true,...
'InsertDCNull', DCNull, ...
'PilotInputPort', true, ...
'PilotCarrierIndices', PilotSC, ...
'CyclicPrefixLength', lenCP);
OFDMDemodulator = comm.OFDMDemodulator(OFDMModulator);
% Mapping of Subcarriers in Time-Frequency Space
%showResourceMapping(OFDMModulator)
% Number of Data Subcarriers
numDataSC = info(OFDMModulator).DataInputSize(1);
% Size of Data Frame
szDataFrame = [numDataSC 1];
% Size of Pilot Frame
szPilotFrame = info(OFDMModulator).PilotInputSize;
% OFDM Symbol Duration with Cyclic Prefix, [s]
Ts_OFDM = (numSC + lenCP)*Ts;
% OFDM Symbol Rate with Cyclic Prefix, [1/s]
Rs_OFDM = 1/Ts_OFDM;
% Decreasing of Symbol Rate by using OFDM
Rs/Rs_OFDM;
% Subcarrier Bandwidth, [Hz]
F_SC = F/numSC;
clear ans
% Discrete Paths Relative Delays, [s]
PathDelays = [0 3 5 6 11]*Ts ;
% Discrete Paths Max Delay, [s]
Tm = max(PathDelays);
% Channel Coherence Bandwidth [2, p. 960; 3, p. 399], [Hz]
Fc = 1/Tm;
% Discrete Paths Average Gains, [dB]
PathAvGains = [0 -8 -17 -21 -25];
% Discrete Paths K Factors
K = [0.1 0.1 0.1 0.1 0.1];
% Approximate Speed of Ionospheric Irregularities, [m/s]
v=170.14;
% Light Speed, [m/s]
c = 3e8;
% Max Doppler Frequency Shift for all Discrete Paths, [Hz]
fD = v*f/c;
% Channel Coherence Time [3, p. 400], [s]
Tc = 1/fD;
spsSync = 1;
norms = [1 sqrt(2) 0 sqrt(10) 0 sqrt(42)];
doppler1 = comm.PhaseFrequencyOffset( ...
FrequencyOffset=fD, ...
PhaseOffset=0, ...
SampleRate=Rs);
varDelay = dsp.VariableFractionalDelay;
%% Rician Channel Object
RicianFadingChannel = comm.RicianChannel( ...
'SampleRate', Rs, ...
'PathDelays', PathDelays, ...
'AveragePathGains', PathAvGains, ...
'NormalizePathGains', true, ...
'KFactor', K, ...
'MaximumDopplerShift', fD, ...
'DirectPathDopplerShift', zeros(size(K)), ...
'DirectPathInitialPhase', zeros(size(K)), ...
'DopplerSpectrum', doppler('Jakes') ...
);
% Delay in Channel Object, [sample]
ChanDelay = info(RicianFadingChannel).ChannelFilterDelay;
%% AWGN Channel Object
AWGNChannel = comm.AWGNChannel( ...
'NoiseMethod', 'Signal to noise ratio (SNR)', ...
'SNR', 0 ...
);
% table(F, F_SC, Fc, fD, 'VariableNames', {'F, [Hz]', 'F_SC, [Hz]', 'Fc, [Hz]', 'fD, [Hz]'})
% table(Ts, Ts_OFDM, Tm, Tc, 'VariableNames', {'Ts, [s]', 'Ts_OFDM, [s]', 'Tm, [s]', 'Tc, [s]'})
% Range of Eb/N0
EbNo = 0:60;
% Number of Transmitted Frames
numFrames = 500;
% BER Calculators Object
BERCalculater = comm.ErrorRate;
% BER Variable for Imitation Modeling Result
BER = zeros(3,length(EbNo));
% Loop for the Range of Eb/N0
for n = 1:length(EbNo)
% Setting the Eb/No in AWGN Channel Object
AWGNChannel.SNR = EbNo(n) + 10*log10(k) + 10*log10(numDataSC/numSC);
% BER Calculation
reset(BERCalculater);
BERn = zeros(3,1);
% Loop for the Number of Transmitted Frames
for fr = 1:numFrames
% >>> Transmitter >>>
% Generation of Data Bits
BitsTx = randi([0 M-1], [szDataFrame,1]);
constellation = qammod(0:M-1, M, 'gray');
% Normalize the constellation
constellation = constellation / norms(k);
% Apply phase offset
% constellation = constellation * exp(1i * phaseOffset);
% Define General QAM Modulator with custom constellation
QAMModulator = comm.GeneralQAMModulator('Constellation', constellation);
SignalTx1 = zeros(szDataFrame);
% Modulate the data symbols
SignalTx1 = QAMModulator(BitsTx);
% Generation of Pilot Signals
PilotSignalTx = complex(ones(szPilotFrame), zeros(szPilotFrame));
% OFDM Modulation
SignalTx2 = OFDMModulator(SignalTx1, PilotSignalTx);
% Power of Transmitted Signal
% Compute the power of the transmitted signal
SignalTxPower = sum(abs(SignalTx2).^2) / length(SignalTx2);
% Adding zero samples to the end of Transmitted Signal
% to not lose shifted samples caused by delay after Rician Channel
SignalTx2 = [SignalTx2; zeros(ChanDelay, 1)];
%SignalTx2_with_pfo = pfo(SignalTx2);
%%
% Rician Channel
SignalChan1 = RicianFadingChannel(SignalTx2);
% Removing first ChanDelay samples and
% selection of Channel's Signal related to Transmitted Signal
SignalChan1 = SignalChan1(ChanDelay + 1 : end);
%% introducing the delay in frequency and symbol time due to doppler
txDoppler = doppler1(SignalChan1);
txDelay = varDelay(txDoppler, fr/numFrames);
SignalChan3=txDelay;
%%
% AWGN Channel
AWGNChannel.SignalPower = SignalTxPower;
SignalChan2 = AWGNChannel(SignalChan3);
% >>> Receiver >>>
% OFDM Demodulation
[SignalRx1, PilotSignalRx] = OFDMDemodulator(SignalChan2);
%%
% LS Channel Estimation
% Obtaining discrete points of Channel Frequency Response
% based on dividing the Received Pilot Signals by the known ones
ChanFR_dp = PilotSignalRx ./ PilotSignalTx;
% Interpolation of Channel Frequency Response
% ChanFR_int = zeros(numSC, 1); % Preallocate the result array
ChanFR_int = fixed.interp1( ...
PilotSC, ...
ChanFR_dp, ...
GuardBandSC(1) + 1 : numSC - GuardBandSC(2), ...
'linear' ...
);
% Selection of Data Subcarriers components of Frequency Response
% by cutting out components of Pilot and DC Subcarriers
% Remove components of Pilot and DC Subcarriers
ChanFR_int([PilotSC; DCNullSC] - GuardBandSC(1)) = [];
% LS Solution
SignalRx2 = SignalRx1./ ChanFR_int.';
% 2. Denormalize the signal
SignalRx2 = SignalRx2* norms(k);
QAMDemodulator = comm.GeneralQAMDemodulator('Constellation',...
qammod(0:M-1, M, 'gray'));
% Demodulate the received signal
BitsRx = QAMDemodulator(SignalRx2);
%BitsRx = qamdemod(SignalRx2*sqrt(10),M,"gray");
% BER Calculation
BERn = BERCalculater(BitsTx, BitsRx);
end
% BER Results
BER(:,n) = BERn;
end
clear n fr BERn
disp(BitsRx);
end
I am trying to convert this code to hdl, but am facing this error in the fixed point conversion part
Expected input 1 to have fixed dimensions for System object comm.OFDMModulator.
refering to this line
SignalTx2 = OFDMModulator(SignalTx1, PilotSignalTx);
Can someone help with this ?
0 件のコメント
回答 (2 件)
Ganapathi Subramanian R
2024 年 6 月 6 日
Hi Siddhardha,
I understand that you would like to generate HDL code for your MATLAB function 'OfdmDopplerBer' which implements OFDM transmitter and receiver.
I suspect that the issue you are facing is due to the use of functions in your code which is not capable of generating HDL code.
The functions used in your code such as 'comm.OFDMModulator', 'comm.OFDMDemodulator' and 'comm.GeneralQAMModulator' are not supported for HDL Code Generation.
Please find the list of functions which has the capability to generate HDL code in Communication Toolbox below.
I hope this helps.
Thanks
Kranti Balaga
2024 年 6 月 11 日
Hi Siddhardha,
HDL code generation of OFDM modulator and demodulator, you can find below
For complete OFDM tranmitter and receiver reference design, you can find below
Thanks,
Kranti
参考
カテゴリ
Help Center および File Exchange で Propagation and Channel Models についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!