Clear Filters
Clear Filters

How to resolve this error: Unable to perform assignment because the size of the left side is 1000-by-1 and the size of the right side is 1000-by-1000

2 views (last 30 days)
Howe to resolve this error:
Unable to perform assignment because the size of the left side is 1000-by-1 and the size of the right
side is 1000-by-1000.
Error in servssnr (line 43)
ynoisy(:,ii) = awgn(real(y),snr(ii),'measured'); % Add AWGN
This is my full code:
PRF = 500e3; % Pulse Repetition Frequency (Hz)
sampling_freq = 60e6; % Sampling Frequency (Hz)
carrier_freq = 2.4e9;
rng('default') % Set random number seed for repeatability
M = 4;
EbNo = 0:13;
[ber,ser] = berawgn(EbNo,'pam',M);
n = 1000; % Number of symbols to process
k = log2(M); % Number of bits per symbol
snr = EbNo+3+10*log10(k); % In dB
ynoisy = zeros(n,length(snr));
z = zeros(n,length(snr));
errVec = zeros(3,length(EbNo));
grid on;
errcalc = comm.ErrorRate;
%x1 = randi([0 M-1],n,1); % Create message signal
% Generate Gold code
code1 = comm.GoldSequence('FirstPolynomial','x^6+x^5+1', 'FirstInitialConditions',[ 0 0 0 0 0 1], 'SecondPolynomial','x^6+x^5+x^4+x+1', 'SecondInitialConditions',[0 0 0 0 0 1], 'Index',1, 'SamplesPerFrame',1000);
gold_code = code1();
% Generate Kasami code
kasamiseq = comm.KasamiSequence('Polynomial',[6 5 4 1 0], 'InitialConditions',[ 0 0 0 0 0 1],'SamplesPerFrame',1000);
kasami_code = kasamiseq()
y1 = pammod(gold_code,M); % Modulate
for ii = 1:length(snr)
reset(errcalc)
ynoisy(:,ii) = awgn(real(y1),snr(ii),'measured'); % Add AWGN
z(:,ii) = pamdemod(complex(ynoisy(:,ii)),M); % Demodulate
errVec(:,ii) = errcalc(gold_code,z(:,ii)); % Compute SER from simulation
end
semilogy(EbNo,errVec(1,:),'r');
hold on;
% Modulate kasami code with barker code
x5 = cos(2*pi*carrier_freq*(0:numel(gold_code)-1)/sampling_freq) .* (gold_code .* kasami_code.');
y = pammod(x5,M); % Modulate
for ii = 1:length(snr)
reset(errcalc)
ynoisy(:,ii) = awgn(real(y),snr(ii),'measured'); % Add AWGN
z(:,ii) = pamdemod(complex(ynoisy(:,ii)),M); % Demodulate
errVec(:,ii) = errcalc(x5,z(:,ii)); % Compute SER from simulation
end
semilogy(EbNo,errVec(1,:),'b');
hold on;
y2 = pammod(kasami_code,M);
for ii = 1:length(snr)
reset(errcalc)
ynoisy(:,ii) = awgn(real(y2),snr(ii),'measured'); % Add AWGN
z(:,ii) = pamdemod(complex(ynoisy(:,ii)),M); % Demodulate
errVec(:,ii) = errcalc(kasami_code,z(:,ii)); % Compute SER from simulation
end
semilogy(EbNo,errVec(1,:),'g');
legend('Gold code','Gold-Kasami', 'Kasami');
title('Comparison of SER ');
xlabel('E_b/N_0 (dB)');
ylabel('Symbol Error Rate');
grid on;
hold off;

Answers (1)

Rishi
Rishi on 20 Apr 2024
Hi Muskan,
I understand from your question that you want to know why you are getting the given error.
In line 40 of the given code, the value returned by the 'pammod' function, which is assigned to the variable 'y' is of the size 1000x1000. Inside the following loop, the 'awgn' function returns an array of size 1000x1000, which you try to assign to some column of the 'ynoisy' variable. This results in an error as 'ynoisy' has been defined as an array of size 1000x14 and you try to assign an array of size 1000x1000 where it expects a 1000x1 sized array.
You can overcome this issue by the following methods:
1. Declaring 'ynoisy' as an array of size 1000x1000x14.
2. Modifying the output of 'awgn' function and reducing it to size 1000x1 before assigning it to 'ynoisy'.
Hope this helps!

Community Treasure Hunt

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

Start Hunting!