# arrays have incompatible sizes for this operation help me PLZ

41 views (last 30 days)
Mahra Albadi on 18 Oct 2021
Answered: Rik on 18 Oct 2021
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)

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