Hi There,
I previously asked a question about this piece of code with QPSK however, when using 64-QAM i get an error with the reshape value. The code is as follows:
N = 10e6;
M = 64;
k = log2(M);
bit_stream = randi([0,1],[1,N]);
tx_bits = reshape(bit_stream,k,[]);
tx_symbols = sum(tx_bits.*pow2(k-1:-1:0).',1);
qammod_sig = qammod(tx_symbols,M);
snr = -10:10;
Nsnr = numel(snr);
error_rate = zeros(1,Nsnr);
n_symb = N/k;
for ii = 1:Nsnr
rx_sig = awgn(qammod_sig,snr(ii));
qamdemod_symb = qamdemod(rx_sig,M);
error_rate(ii) = nnz(tx_symbols ~= qamdemod_symb) / n_symb;
end
scatterplot(qammod_sig)
figure()
semilogy(snr,error_rate(1,:),'.-')
xlabel ('SNR [dB]')
ylabel('BER')
The error which I am receiving is this:
Error using reshape
Product of known dimensions, 6, not divisible into total
number of elements, 10000000.
Error in coursework_task_1_qam (line 5)
tx_bits = reshape(bit_stream,k,[]);

댓글 수: 2

Dyuman Joshi
Dyuman Joshi 2024년 3월 27일
bit_stream is 1x10e6. You are trying to reshape it into an array with 6 rows and 10e6/6 columns, which is not possible as number of columns must be natural numbers.
What is the idea behind reshaping bit_stream? What is the operation you are trying to perform?
Liam
Liam 2024년 3월 27일
The main aim that I am trying to achieve to observe the bit error rate of a system using QPSK, 16-QAM and 64-QAM. I have had success with QPSK and 16-QAM but not with 64-QAM and I am unsure as to how to get it to work

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

 채택된 답변

Voss
Voss 2024년 3월 27일
편집: Voss 2024년 3월 27일

0 개 추천

Pick an N that's a multiple of k, or adjust N to be a multiple of k in the code, or append enough bits onto the end of the bit stream to make it a multiple of k in length before reshaping.
N = 1e6; % pick an N that's a multiple of k
M = 64;
k = log2(M);
N = ceil(N/k)*k; % or make N the first multiple of k >= N
bit_stream = randi([0,1],[1,N]);
m = mod(N,k);
if m
bit_stream(end+1:end+k-m) = 0; % or append some zeros to the bit stream as necessary
end
tx_bits = reshape(bit_stream,k,[]);
tx_symbols = sum(tx_bits.*pow2(k-1:-1:0).',1);
qammod_sig = qammod(tx_symbols,M);
snr = -10:10;
Nsnr = numel(snr);
error_rate = zeros(1,Nsnr);
n_symb = N/k;
for ii = 1:Nsnr
rx_sig = awgn(qammod_sig,snr(ii));
qamdemod_symb = qamdemod(rx_sig,M);
error_rate(ii) = nnz(tx_symbols ~= qamdemod_symb) / n_symb;
end
scatterplot(qammod_sig)
figure()
semilogy(snr,error_rate(1,:),'.-')
xlabel ('SNR [dB]')
ylabel('BER')

댓글 수: 5

Liam
Liam 2024년 3월 27일
The main issue with this is that the brief that I have been given states that the bitstream needs to be 10^6
Voss
Voss 2024년 3월 27일
편집: Voss 2024년 3월 27일
Let me know how you plan to make a sequence of symbols that are each 6 bits in length and end up with a million bits in total, and I'll adjust my code.
I've edited my answer to show how to make the number of bits generated the next multiple of k at or above the specified N, and to show how to append bits to the end of the bit stream so that its length is a multiplr of k. You do not need to use more than one of those methods (but it doesn't hurt anything if you do).
Liam
Liam 2024년 3월 28일
Would padding it with zeros assist with this? or does this complicate things?
Voss
Voss 2024년 3월 28일
편집: Voss 2024년 3월 28일
Padding with zeros works. See my answer for how to do that. Specifically, this part:
m = mod(N,k);
if m
bit_stream(end+1:end+k-m) = 0; % or append some zeros to the bit stream as necessary
end
Dyuman Joshi
Dyuman Joshi 2024년 4월 2일
If OP had R2023b, resize would have been useful.

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

추가 답변 (0개)

카테고리

제품

릴리스

R2022a

태그

질문:

2024년 3월 27일

댓글:

2024년 4월 2일

Community Treasure Hunt

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

Start Hunting!

Translated by