error in axis! help me

9 views (last 30 days)
Mahra Albadi
Mahra Albadi on 14 Sep 2021
Edited: Steven Lord on 14 Sep 2021
clc; clear all ;close all;
close all;
data_size=8;
data=randi([0 1],data_size,1);data=data';
bp=0.000001;
disp('Binary information at transmitter :');
Binary information at transmitter :
disp(data);
0 0 1 0 0 0 1 0
% rep of trans binary info as digital
expand=100;
baseband=zeros(1,length(data)*expand);
for n=1:1:length(data)
if data(n)==1
se=ones(expand,1);
else
data(n)==0;
se=zeros(expand,1);
end
baseband((n-1)*expand+1:n*expand)=se;
end
figure
t_bits=bp/expand:bp/expand:expand*length(data)*(bp/expand);
subplot(2,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 ) transmitting information as digital signal');
hold on
%binary PSK MODULATION
A=1; %Amplitude carrier
br=1/bp;%bit rate 1 mbps
f=br*2; % carrier freq 2Mz
t_bit=bp/expand:bp/expand:bp;
ss=length(t_bit);
modulated_signal=zeros(1,length(data)*expand);
subplot(2,1,2);
plot(t_bits,A*sin(2*pi*f*t_bits)); grid on;
ylabel('amplitude(volt)');
xlabel('time(sec)');
title('( Aaesha Mahra) carrier signal');
modulated_signal=zeros(1,length(data)*expand);
for(i=1:1:length(data))
if (data(i)==1)
carrier=A*sin(2*pi*f*t_bit);
else
carrier=1*A*sin(2*pi*f*t_bit+pi);
end
modulated_signal((i-1)*expand+1:i*expand)=carrier;
end
%modulated signal
figure
subplot(2,1,1);
plot(t_bits,modulated_signal);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('(Aaesha,Mahra) Wave form for binary PSK modulation coresponding binary information')
% binary demodulation
demodulated_data=[];
carrier_receiver=sin(2*pi*f*t_bit);
for n=ss:ss:length(modulated_signal)
demodulated_signal=carrier_receiver.*modulated_signal((n-(ss-1)):n);
z=trapz(t_bit,demodulated_signal);
zz=round((2*z/bp));
if(zz>0)
a=1;
else
a=0;
end
demodulated_data=[demodulated_data a];
end
disp('Binary information at reciver');
Binary information at reciver
disp(demodulated_data);
0 0 1 0 0 0 1 0
% rep of binary info as digital signal after PSK demodelation
demodulation_bits_expanded=zeros(length(data)*expand,1);
for n=1:length(demodulated_data);
if demodulated_data==1;
se=ones(1,expand);
else demodulated_data(n)==0
se=zeros(1,expand);
end
demodulated_bits_expanded((n-1)*expand+1:n*expand)=se;
end
ans = logical
1
ans = logical
1
ans = logical
0
ans = logical
1
ans = logical
1
ans = logical
1
ans = logical
0
ans = logical
1
subplot(2,1,2);
plot(t_bits,demodulated_bits_expanded,'LineWidth',2.5);grid on;
axis([0 bp*length(demodulated_data) 0 -0.5 1.5])
Error using axis>LocSetLimits (line 325)
Vector must have 4, 6, or 8 elements.

Error in axis (line 113)
LocSetLimits(ax(j),cur_arg,names);
ylabel('amplitude(volt)');
title('recived information as signal after binary PSK demodulation');
%plot constallation figure PSK%
figure
scatter([-1 1],[0, 0]); axis([-1.5 1.5 -1.5 1.5])
xlabel('in-phase amplitude');
ylabel('quadrature amplitude' );
title('(Aaesha Mahra )constallation diagram for binary PSK modulation');
grid
M=2;
phOffest=0;
symMap='binary';
PSKModulator =comm.PSKModulator(M, phOffest,'SymbolMapping' ,symMap);
constellation(PSKModulator)
Can you review the code and correct the error because I am a newbie on Matlab and I was unable to solve the error?

Accepted Answer

Star Strider
Star Strider on 14 Sep 2021
Edited: Steven Lord on 14 Sep 2021
In this axis call:
axis([0 bp*length(demodulated_data) -0.5 1.5])
there was originally an extra 0 just after the length call, so there were 5 elements instead of the expected 4, and since this is a 2D plot, those are all that are required. With that correction [SL: fixed typo], it now appears to work as expected.
data_size=8;
data=randi([0 1],data_size,1);data=data';
bp=0.000001;
disp('Binary information at transmitter :');
Binary information at transmitter :
disp(data);
0 0 0 1 1 1 1 1
% rep of trans binary info as digital
expand=100;
baseband=zeros(1,length(data)*expand);
for n=1:1:length(data)
if data(n)==1
se=ones(expand,1);
else
data(n)==0;
se=zeros(expand,1);
end
baseband((n-1)*expand+1:n*expand)=se;
end
figure
t_bits=bp/expand:bp/expand:expand*length(data)*(bp/expand);
subplot(2,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 ) transmitting information as digital signal');
hold on
%binary PSK MODULATION
A=1; %Amplitude carrier
br=1/bp;%bit rate 1 mbps
f=br*2; % carrier freq 2Mz
t_bit=bp/expand:bp/expand:bp;
ss=length(t_bit);
modulated_signal=zeros(1,length(data)*expand);
subplot(2,1,2);
plot(t_bits,A*sin(2*pi*f*t_bits)); grid on;
ylabel('amplitude(volt)');
xlabel('time(sec)');
title('( Aaesha Mahra) carrier signal');
modulated_signal=zeros(1,length(data)*expand);
for(i=1:1:length(data))
if (data(i)==1)
carrier=A*sin(2*pi*f*t_bit);
else
carrier=1*A*sin(2*pi*f*t_bit+pi);
end
modulated_signal((i-1)*expand+1:i*expand)=carrier;
end
%modulated signal
figure
subplot(2,1,1);
plot(t_bits,modulated_signal);
xlabel('time(sec)');
ylabel('amplitude(volt)');
title('(Aaesha,Mahra) Wave form for binary PSK modulation coresponding binary information')
% binary demodulation
demodulated_data=[];
carrier_receiver=sin(2*pi*f*t_bit);
for n=ss:ss:length(modulated_signal)
demodulated_signal=carrier_receiver.*modulated_signal((n-(ss-1)):n);
z=trapz(t_bit,demodulated_signal);
zz=round((2*z/bp));
if(zz>0)
a=1;
else
a=0;
end
demodulated_data=[demodulated_data a];
end
disp('Binary information at reciver');
Binary information at reciver
disp(demodulated_data);
0 0 0 1 1 1 1 1
% rep of binary info as digital signal after PSK demodelation
demodulation_bits_expanded=zeros(length(data)*expand,1);
for n=1:length(demodulated_data);
if demodulated_data==1;
se=ones(1,expand);
else demodulated_data(n)==0
se=zeros(1,expand);
end
demodulated_bits_expanded((n-1)*expand+1:n*expand)=se;
end
ans = logical
1
ans = logical
1
ans = logical
1
ans = logical
0
ans = logical
0
ans = logical
0
ans = logical
0
ans = logical
0
subplot(2,1,2);
plot(t_bits,demodulated_bits_expanded,'LineWidth',2.5);grid on;
axis([0 bp*length(demodulated_data) -0.5 1.5])
ylabel('amplitude(volt)');
title('recived information as signal after binary PSK demodulation');
%plot constallation figure PSK%
figure
scatter([-1 1],[0, 0]); axis([-1.5 1.5 -1.5 1.5])
xlabel('in-phase amplitude');
ylabel('quadrature amplitude' );
title('(Aaesha Mahra )constallation diagram for binary PSK modulation');
grid
M=2;
phOffest=0;
symMap='binary';
PSKModulator =comm.PSKModulator(M, phOffest,'SymbolMapping' ,symMap);
constellation(PSKModulator)
.
  2 Comments
Mahra Albadi
Mahra Albadi on 14 Sep 2021
thank you! but why demodulation figure become straight line? it must be look like the first figure.
Star Strider
Star Strider on 14 Sep 2021
My pleasure!
I have no idea. I just ran the code to see where the problem was, and to be certain that was the only problem.
Check to be certain that the correct vectors are being plotted.

Sign in to comment.

More Answers (1)

Cris LaPierre
Cris LaPierre on 14 Sep 2021
Edited: Cris LaPierre on 14 Sep 2021
As the error states, you have an unexpected number of values in your axis command. For a 2D plot, you should have 4. Since I don't know which numbers you want to keep, I'll just point you to the relevant documenation page.
  • [xmin xmax ymin ymax] — Set the x-axis limits to range from xmin to xmax. Set the y-axis limits to range from ymin to ymax.

Tags

Community Treasure Hunt

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

Start Hunting!