how can i solve this problem ?
3 views (last 30 days)
Show older comments
I want to process a video by using F_OFDM method , I tried it in a random signal
bitIn= randi([0 1], bitsPerSubCarrier*numDataCarriers, 1);
and I got what I want .
But when I tried to change the input to the video stream (that is converted into a binary stream) ,I got this error :
Error using RectangularQAMModulator
When the BitInput property is set to true, the length of
the input (1) must be an integer multiple of the number
of bits per symbol (6).
- Can s.one help me to solve this ?
clear; close all
%read video
vid = VideoReader('test.mp4');
numberFrames = vid.NumberOfFrames;
n= numberFrames ;
totBit=0;
for i=1:1:n
image = read(vid,i);
B = image(:);
%Conversion frames to binary sequence.
binary_sequence = reshape(dec2bin(typecast(B,'uint8'), 8) - '0', 1, []);
totBit=[totBit,binary_sequence];
end
s = rng(211); % Set RNG state for repeatability
numFFT = 2048; % Number of FFT points
numRBs = 100; % Number of resource blocks
rbSize = 12; % Number of subcarriers per resource block
cpLen = 72; % Cyclic prefix length in samples
bitsPerSubCarrier = 6; % 2: QPSK, 4: 16QAM, 6: 64QAM, 8: 256QAM
snrdB = 15; % SNR in dB
toneOffset = 2.5; % Tone offset or excess bandwidth (in subcarriers)
L = 513; % Filter length (=filterOrder+1), odd
numDataCarriers = numRBs*rbSize; % number of data subcarriers in sub-band
halfFilt = floor(L/2);
n = -halfFilt:halfFilt;
% Sinc function prototype filter
pb = sinc((numDataCarriers+2*toneOffset).*n./numFFT);
% Sinc truncation window
w = (0.5*(1+cos(2*pi.*n/(L-1)))).^0.6;
% Normalized lowpass filter coefficients
fnum = (pb.*w)/sum(pb.*w);
% Filter impulse response
h = fvtool(fnum, 'Analysis', 'impulse', ...
'NormalizedFrequency', 'off', 'Fs', 400e6);
h.CurrentAxes.XLabel.String = 'Time (\mus)';
h.FigureToolbar = 'on';
% Use dsp filter objects for filtering
filtTx = dsp.FIRFilter('Structure', 'Direct form symmetric', ...
'Numerator', fnum);
filtRx = clone(filtTx); % Matched filter for the Rx
% QAM Symbol mapper
qamMapper = comm.RectangularQAMModulator( ...
'ModulationOrder', 2^bitsPerSubCarrier, 'BitInput', true, ...
'NormalizationMethod', 'Average power');
% Generate data symbols
bitsIn = length(totBit)
symbolsIn = qamMapper(bitsIn);
% Pack data into an OFDM symbol
offset = (numFFT-numDataCarriers)/2; % for band center
symbolsInOFDM = [zeros(offset,1); symbolsIn; ...
zeros(numFFT-offset-numDataCarriers,1)];
ifftOut = ifft(ifftshift(symbolsInOFDM));
% Prepend cyclic prefix
txSigOFDM = [ifftOut(end-cpLen+1:end); ifftOut];
% Filter, with zero-padding to flush tail. Get the transmit signal
txSigFOFDM = filtTx([txSigOFDM; zeros(L-1,1)]);
% Plot power spectral density (PSD)
[psd,f] = periodogram(txSigFOFDM, rectwin(length(txSigFOFDM)), ...
numFFT*2, 1, 'centered');
hFig = figure('Position', figposition([46 50 30 30]), 'MenuBar', 'figure');
plot(f,10*log10(psd));
% Set up a figure for spectrum plot
axis([-0.5 0.5 -100 -20]);
hold on;
xlabel('Normalized frequency');
ylabel('PSD (dBW/Hz)')
title(['F-OFDM, ' num2str(numRBs) ' Resource blocks, ' ...
num2str(rbSize) ' Subcarriers each'])
% Compute peak-to-average-power ratio (PAPR)
PAPR = comm.CCDF('PAPROutputPort', true, 'PowerUnits', 'dBW');
[~,~,paprFOFDM] = PAPR(txSigFOFDM);
disp(['Peak-to-Average-Power-Ratio for F-OFDM = ' num2str(paprFOFDM) ' dB']);
% Plot power spectral density (PSD) for OFDM signal
[psd,f] = periodogram(txSigOFDM, rectwin(length(txSigOFDM)), numFFT*2, ...
1, 'centered');
hFig1 = figure('Position', figposition([46 15 30 30]));
plot(f,10*log10(psd));
axis([-0.5 0.5 -100 -20]);
xlabel('Normalized frequency');
ylabel('PSD (dBW/Hz)')
title(['OFDM, ' num2str(numRBs*rbSize) ' Subcarriers'])
% Compute peak-to-average-power ratio (PAPR)
PAPR2 = comm.CCDF('PAPROutputPort', true, 'PowerUnits', 'dBW');
[~,~,paprOFDM] = PAPR2(txSigOFDM);
disp(['Peak-to-Average-Power-Ratio for OFDM = ' num2str(paprOFDM) ' dB']);
% Add AWGN
rxSig = awgn(txSigFOFDM, snrdB, 'measured');
% Receive matched filter
rxSigFilt = filtRx(rxSig);
% Account for filter delay
rxSigFiltSync = rxSigFilt(L:end);
% Remove cyclic prefix
rxSymbol = rxSigFiltSync(cpLen+1:end);
% Perform FFT
RxSymbols = fftshift(fft(rxSymbol));
% Select data subcarriers
dataRxSymbols = RxSymbols(offset+(1:numDataCarriers));
% Plot received symbols constellation
switch bitsPerSubCarrier
case 2 % QPSK
refConst = qammod((0:3).', 4, 'UnitAveragePower', true);
case 4 % 16QAM
refConst = qammod((0:15).', 16,'UnitAveragePower', true);
case 6 % 64QAM
refConst = qammod((0:63).', 64,'UnitAveragePower', true);
case 8 % 256QAM
refConst = qammod((0:255).', 256,'UnitAveragePower', true);
end
constDiagRx = comm.ConstellationDiagram( ...
'ShowReferenceConstellation', true, ...
'ReferenceConstellation', refConst, ...
'Position', figposition([20 15 30 40]), ...
'EnableMeasurements', true, ...
'MeasurementInterval', length(dataRxSymbols), ...
'Title', 'F-OFDM Demodulated Symbols', ...
'Name', 'F-OFDM Reception', ...
'XLimits', [-1.5 1.5], 'YLimits', [-1.5 1.5]);
constDiagRx(dataRxSymbols);
% Channel equalization is not necessary here as no channel is modeled
% Demapping and BER computation
qamDemod = comm.RectangularQAMDemodulator('ModulationOrder', ...
2^bitsPerSubCarrier, 'BitOutput', true, ...
'NormalizationMethod', 'Average power');
BER = comm.ErrorRate;
% Perform hard decision and measure errors
rxBits = qamDemod(dataRxSymbols);
ber = BER(bitsIn, rxBits);
disp(['F-OFDM Reception, BER = ' num2str(ber(1)) ' at SNR = ' ...
num2str(snrdB) ' dB']);
0 Comments
Answers (0)
See Also
Categories
Find more on Modulation 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!