arrays have incompatible sizes for this operation help me PLZ

51 views (last 30 days)
clc; clear all ;close all;
close all;
data_size=8;
if rem(data_size,2)==1
data_size=data_size+1;
end
data=randi([0 1],data_size,1);data=data';
bp=0.000001;
disp('Binary information at transmitter :');
disp(data);
% repr of trans binary info as digital
bp=0.000001;
expand_bit=100;
baseband=zeros(1,length(data)*expand_bit);
for n=1:1:length(data)
if data(n)==1
se=ones(expand_bit,1);
else
data(n)=0;
se=zeros(expand_bit,1);
end
baseband((n-1)*expand_bit+1:n*expand_bit)=se;
end
figure
t_bits=bp/expand_bit:bp/expand_bit:expand_bit*length(data)*(bp/expand_bit);
subplot(3,1,1);
plot(t_bits,baseband,'LineWidth',2.5);grid on;
axis([ 0 bp*length(data) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title(['(Aaesha Mahra A, Mahra M) transmitting information ' ...
'as digital signal']);
hold on
% seperate data in two channel Im & Q
% I channel
counter=1;
for n=1:2:length(data)
data(counter)=data(n);
dataQ(counter)=data(n+1);
counter=counter+1;
end
expand_symbol=200;
basebandl=zeros(1,length(data)*expand_symbol);
for n=1:1: length(data)
if data(n)==1;
se=ones(expand_symbol,1);
else data(n)==0;
se=-ones(expand_symbol,1);
end
basebandl((n-1)*expand_symbol+1:n*expand_symbol)=se;
end
subplot(3,1,2);
plot(t_bits,baseband,'LineWidth',2.5);grid on;
axis([ 0 bp*length(data) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title(['(Aaesha Mahra A, Mahra M) data l']);
% Q channel
basebandQ=zeros(1,length(dataQ)*expand_symbol);
for n=1:1:length(dataQ)
if dataQ(n)==1
se=ones(expand_symbol,1);
else dataQ(n)==0;
se=-ones(expand_symbol,1);
end
basebandQ((n-1)*expand_symbol+1:n*expand_symbol)=se;
end
subplot(3,1,3);
plot(t_bits,basebandQ,'LineWidth',2.5);grid on;
axis([ 0 bp*length(data) -.5 1.5]);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title(['(Aaesha Mahra A, Mahra M) data Q']);
%binary FSK carrier
A=1; %Amplitude carrier
br=1/bp;%bit rate 1 mbps
f=br*2; % carrier freq 2Mz
figure
subplot(3,1,1);
transmitterCarrier=A*sin(2*pi*f*t_bits);
plot(t_bits,transmitterCarrier); grid on;
ylabel('amplitude(volt)');
xlabel('time(sec)');
title('(Aaesha Mahra A, Mahra M) carrier signal');
%show modulated signal%
modulated_signal=A.*basebandl.*cos(2*pi*f*t_bits)+A.basebandQ.*sin(2*pi*f*t_bits);
subplot(3,1,2);
plot(t_bits,modulated_signal);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title(['(Aaesha Mahra A, Mahra M) QPSK modulation'])
% FSK demodulation
sp=2*bp;
t_symbol=bp/expand_bit:bp/expand_bit:sp;
ss=length(t_symbol);
counter=1;
carrier0=cos(2*pi*f*t_symbol);
carrier90=sin(2*pi*f*t_symbol);
demodulated_data=[];
for n=ss:ss:length(modulated_signal)
demodulated_signal0=carrier0.*modulated_signal((n-(ss-1)):n);
demodulated_signal90=carrier90.*modulated_signal((n-(ss-1)):n);
z0=trapz(t_symbol,demodulated_signal0);
zz0=round((2*z0/sp))
if(zz0>0)
else
a=0;
end
if(zz90>0)
b=0;
end
demodulated_data=[demodulated_data,a,b]
counter=counter+1;
end
disp('Binary information at transimtter');
disp(data);
disp('Binary information at reciver');
disp(demodulated_data);
%plot constallation figure FSK%
M=4;
phOffset=0;
symMap='binary';
pskModulator=comm.PSKModulator(M,phOffset,'symbolMapping',symMap);
constellation(pskModulator)

Accepted Answer

Rik
Rik on 18 Oct 2021
I have removed all the plotting code and included calls to size to determine the sizes of all the variables involved.
data_size=8;
if rem(data_size,2)==1
data_size=data_size+1;
end
data=randi([0 1],data_size,1);data=data';
bp=0.000001;
% repr of trans binary info as digital
bp=0.000001;
expand_bit=100;
baseband=zeros(1,length(data)*expand_bit);
for n=1:1:length(data)
if data(n)==1
se=ones(expand_bit,1);
else
data(n)=0;
se=zeros(expand_bit,1);
end
baseband((n-1)*expand_bit+1:n*expand_bit)=se;
end
t_bits=bp/expand_bit:bp/expand_bit:expand_bit*length(data)*(bp/expand_bit);
% seperate data in two channel Im & Q
% I channel
counter=1;
for n=1:2:length(data)
data(counter)=data(n);
dataQ(counter)=data(n+1);
counter=counter+1;
end
expand_symbol=200;
basebandl=zeros(1,length(data)*expand_symbol);
for n=1:1: length(data)
if data(n)==1;
se=ones(expand_symbol,1);
else data(n)==0;
se=-ones(expand_symbol,1);
end
basebandl((n-1)*expand_symbol+1:n*expand_symbol)=se;
end
% Q channel
basebandQ=zeros(1,length(dataQ)*expand_symbol);
for n=1:1:length(dataQ)
if dataQ(n)==1
se=ones(expand_symbol,1);
else dataQ(n)==0;
se=-ones(expand_symbol,1);
end
basebandQ((n-1)*expand_symbol+1:n*expand_symbol)=se;
end
%binary FSK carrier
A=1; %Amplitude carrier
br=1/bp;%bit rate 1 mbps
f=br*2; % carrier freq 2Mz
transmitterCarrier=A*sin(2*pi*f*t_bits);
size(A)
ans = 1×2
1 1
size(basebandl)
ans = 1×2
1 1600
size(f)
ans = 1×2
1 1
size(t_bits)
ans = 1×2
1 800
size(basebandQ)
ans = 1×2
1 800
%show modulated signal%
basebandl.*cos(2*pi*f*t_bits);
Arrays have incompatible sizes for this operation.
Here you see the reason: one variable is 1-by-800 and another is 1-by-1600. How should Matlab expand this to a multiplication?
Also, a bit later in this line you're treating A as a struct or a class. Didn't you miss a * symbol?
modulated_signal=A.*basebandl.*cos(2*pi*f*t_bits)+A.basebandQ.*sin(2*pi*f*t_bits);
% ^
% that will cause problems

More Answers (1)

girma
girma on 13 Aug 2022
Edited: Walter Roberson on 15 Aug 2022
clc
clear all
close all
%Setting the message signal for modulation
M = 8; % Modulation order 11
bps = log2(M); % Bits per symbol
N = 7; % BCH codeword length
K = 4; % BCH message length
%Since it's 8-PSK, we are going to use the PSK Modulator and De-modulator
%from the toolbox along with the AWGN channel
pskModulator = comm.PSKModulator('ModulationOrder',M,'BitInput',true);
pskDemodulator = comm.PSKDemodulator('ModulationOrder',M,'BitOutput',true);
awgnChannel = comm.AWGNChannel('BitsPerSymbol',bps);
%We are dedicating a variable for error rate calculation and calling the BCH
%encoder and decoder for encoding and decoding the message signal
errorRate = comm.ErrorRate;
BCHencoder = comm.BCHEncoder; %creates a BCH encoder System object that performs BCH encoding.
BCHdecoder = comm.BCHDecoder; %creates a BCH decoder System object that performs BCH decoding.
%Declaring a variable with snr/ebno of a particular range and initializing
%errorStats variable with a zero vector
ebnoVec = (3:0.5:8)';
errorStats = zeros(length(ebnoVec),3);
%Modulation and Demodulation along with BER calculation
for i = 1:length(ebnoVec) %Looping through the range of snr
awgnChannel.EbNo = ebnoVec(i); %Initializing AWGN channel with thevalue of i
reset(errorRate) %Resetting the value of error Rate for precise calculation
while errorStats(i,2) < 100 && errorStats(i,3) < 1e7 %Condition check
data = randi([0 1],1500,1); %Generate binary data
encData = step(BCHencoder,data); %Returns estimated message based on encoder and data
modData = pskModulator(encData); %Modulate using PSK modulator
rxSig = awgnChannel(modData); %Pass signal through AWGN
rxData = pskDemodulator(rxSig); %Demodulate using PSK demodulator
decData = step(BCHdecoder,rxData); %Returns the estimated message after decoding based on decoder and data
errorStats(i,:) = errorRate(data,decData); %Collect error statistics
end
end
berCurveFit = berfit(ebnoVec,errorStats(:,1)) %Best fit curve is obtained
berNoCoding = berawgn(ebnoVec,'psk',8,'nondiff')
semilogy(ebnoVec,errorStats(:,1),'b*', ...
ebnoVec,berCurveFit,'c-',ebnoVec,berNoCoding,'r') %Semilog graph is drawn title('BCH Coding for 8 PSK')
ylabel('BER') %Relevant titles for x and y axis are given
xlabel('Eb/No (dB)')
legend('Data','Curve Fit','No Coding')
grid
just have
Array formation and parentheses-style indexing with objects of class 'comm.PSKModulator' is not allowed. Use objects of class 'comm.PSKModulator' only as scalars or use a cell array.
how can i correct it any one help me
  2 Comments
Walter Roberson
Walter Roberson on 15 Aug 2022
A few years ago, it became possible to use some system objects as if they were functions. It appears that your version of MATLAB is too old for that, so you will need to rewrite
modData = pskModulator(encData);
as
modData = step(pskModulator, encData);

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!