why do I get this error while using qammod? "Expected input number 1, X, to be an array with all of the values < 4."

31 次查看(过去 30 天)
N=256;
% Number of subcarriers or size of IFFT/FFT
N_data_symbol=128;
% Number of symbol to IFFT
GI=N/4;
% Guard interval 1/4,1/8,1/16,. . .
M=4;
% Modulation 2:BPSK, 4:QPSK, (8,16,32,64,128,256):QAM
L=16;
% Channel length
N_Iteration=500;
% Number of iteration
SNR=[0:1:15];
% Signal to Noise Ratio in dB
for i=1:length(SNR)
snr=SNR(i)
for (k=1:N_Iteration)
tx_bits=randi(N_data_symbol,1,M);
% Input Bit Streams to Transmit
% Modulation
tx_bits_Mod=qammod(tx_bits,M);
input_symbol=[zeros((N-N_data_symbol)/2,1);
tx_bits_Mod;
zeros((N-N_data_symbol)/2,1)];
% IFFT and Circular Prefix Addition
ofdm_symbol_ifft=ifft(input_symbol,N);
% Guard Interval insertion (CP)
guard_symbol=ofdm_symbol_ifft(N-GI+1:N);
% Add the cyclic prefix to the ofdm symbol
ofdm_symbol=[guard_symbol; ofdm_symbol_ifft];
%sig_pow=ofdm_symbol'.*conj(ofdm_symbol);
ofdm_spectrum=ofdm_symbol;
%ofdm_spectrum=[ofdm_spectrum; ofdm_symbol];
% h=randn(L,1)+j*randn(L,1); % Generate random channel
h(1:L,1)
%h=h./sum(abs(h)); % Normalization
h=1; %AWGN
y1=filter(h,1,ofdm_symbol);
%y=x*h
% Adding AWGN Noise
y=awgn(y1,snr,'measured');
%y=x*h+n
% Remove Cyclic prefix
rx_symbol=y(GI+1:N+GI);
% The FFT of the time domain signal after the removal of
cyclic prefix
rx_symbol_fft=fft(rx_symbol,N);
% Equalization
%H_f=fft(h,N);
%G=1./H_f;
rx_equalized_zp=rx_symbol_fft;
rx_equalized=rx_equalized_zp(((N-N_data_symbol)/2)+1:(N+N_data_symbol)/2);
% Demodulate
rx_bits_zp=qamdemod(rx_equalized,M);
rx_bits=rx_bits_zp;
% Comparison
% Bit Error Rate computation
[nErr bErr(i,k)]=symerr(tx_bits,rx_bits);
end
end
snr_theo=10.^(SNR/10);
Theory_awgn=0.5*erfc(sqrt(snr_theo));
semilogy(SNR,mean(bErr'),'b',SNR,Theory_awgn,'ro–');
The errors I'm getting are as follows:
Error using qammod
Expected input number 1, X, to be an array with all of the values < 4.
Error in qammod>validateInput (line 288)
validateattributes(x, {'numeric'}, {'real','integer','>=',0,'<',M}, mfilename, 'X', 1);
Error in qammod (line 95)
validateInput(x, M, bitInput, outputDataType);
Error in Experimental_DCOFDM_2 (line 21)
tx_bits_Mod=qammod(tx_bits,M);

采纳的回答

Chunru
Chunru 2022-9-28
A few bugs in program. The major one is generating input signa which should bel: tx_bits=randi([0 M-1], [N_data_symbol,1]);
N=256;
% Number of subcarriers or size of IFFT/FFT
N_data_symbol=128;
% Number of symbol to IFFT
GI=N/4;
% Guard interval 1/4,1/8,1/16,. . .
M=4;
% Modulation 2:BPSK, 4:QPSK, (8,16,32,64,128,256):QAM
L=16;
% Channel length
N_Iteration=500;
% Number of iteration
SNR=[0:1:15];
% Signal to Noise Ratio in dB
for i=1:length(SNR)
snr=SNR(i)
for (k=1:N_Iteration)
%tx_bits=randi(N_data_symbol,1,M);
tx_bits=randi([0 M-1], [N_data_symbol,1]);
% Input Bit Streams to Transmit
% Modulation
tx_bits_Mod=qammod(tx_bits,M);
input_symbol=[zeros((N-N_data_symbol)/2,1);
tx_bits_Mod;
zeros((N-N_data_symbol)/2,1)];
% IFFT and Circular Prefix Addition
ofdm_symbol_ifft=ifft(input_symbol,N);
% Guard Interval insertion (CP)
guard_symbol=ofdm_symbol_ifft(N-GI+1:N);
% Add the cyclic prefix to the ofdm symbol
ofdm_symbol=[guard_symbol; ofdm_symbol_ifft];
%sig_pow=ofdm_symbol'.*conj(ofdm_symbol);
ofdm_spectrum=ofdm_symbol;
%ofdm_spectrum=[ofdm_spectrum; ofdm_symbol];
% h=randn(L,1)+j*randn(L,1); % Generate random channel
%h(1:L,1)
%h=h./sum(abs(h)); % Normalization
h=1; %AWGN
y1=filter(h,1,ofdm_symbol);
%y=x*h
% Adding AWGN Noise
y=awgn(y1,snr,'measured');
%y=x*h+n
% Remove Cyclic prefix
rx_symbol=y(GI+1:N+GI);
% The FFT of the time domain signal after the removal of
% cyclic prefix
rx_symbol_fft=fft(rx_symbol,N);
% Equalization
%H_f=fft(h,N);
%G=1./H_f;
rx_equalized_zp=rx_symbol_fft;
rx_equalized=rx_equalized_zp(((N-N_data_symbol)/2)+1:(N+N_data_symbol)/2);
% Demodulate
rx_bits_zp=qamdemod(rx_equalized,M);
rx_bits=rx_bits_zp;
% Comparison
% Bit Error Rate computation
[nErr bErr(i,k)]=symerr(tx_bits,rx_bits);
end
end
snr = 0
snr = 1
snr = 2
snr = 3
snr = 4
snr = 5
snr = 6
snr = 7
snr = 8
snr = 9
snr = 10
snr = 11
snr = 12
snr = 13
snr = 14
snr = 15
snr_theo=10.^(SNR/10);
Theory_awgn=0.5*erfc(sqrt(snr_theo));
semilogy(SNR,mean(bErr'),'b', SNR,Theory_awgn, 'ro-');
  2 个评论
Hanojhan Rajahrajasingh
In the above code channel is set to 1 (h), if I try to uncomment the below line of code and generate a random channel then blue curve representing the simulated value becomes a straight line. What is causing this issue? Why can't the channel be used?
% h=randn(L,1)+j*randn(L,1); % Generate random channel

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Modulation 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by