Subscript indices must either be real positive integers or logicals. where I have to change or update the code
2 views (last 30 days)
Show older comments
Shnigdha Sharup
on 3 Aug 2021
Answered: Shnigdha Sharup
on 4 Aug 2021
clc;
clear all;
close all;
Transmitted_Message = 'SP22';
dec = double(Transmitted_Message); % text to ASCII (decimal)
p2 = 2.^(0:-1:-7); % 2^0,2^-1,.......,2^-7
B = mod(floor(p2'*dec),2); % decimal to binary conversion
% columns of B are bits of characters
x = reshape(B,1,numel(B));
disp('Transmitted message is:')
disp(Transmitted_Message)
disp('Binary information at Transmitter:');
disp(x);
F=1;
G=9;
%my id is 19-39319-1
br=(F+G+2)*200;
bp = 1/br;% bit period
%% representation of transmitting binary information as digital % signal
bit = [];
a0 = 12; % amplitude for binary bit 00
a1 = 16; % amplitude for binary bit 01
a2=20; % amplitude for binary bit 10
a3=24;% amplitude for binary bit 11
nt = 1000; % number of samples in a single bit period
for n =linspace(1,2,length(x))
if x(n) == 0 && x(n+1)== 0 ;
se = a0*ones(1,nt);
elseif x(n) == 0 && x(n+1)== 1;
se = a1*ones(1,nt);
elseif x(n) == 1 && x(n+1)== 0;
se = a2*ones(1,nt);
else x(n) == 1 && x(n+1)== 1;
se = a3*ones(1,nt);
end
bit = [bit se];
end
t = linspace(0, bp/nt, length(x)*bp-bp/nt));
plot (t,bit,'lineWidth',2);
ylabel('amplitude(volt)');
xlabel(' time(sec)');
title('Transmitting information as digital signal');
0 Comments
Accepted Answer
More Answers (1)
Asaad Abboud Alkhalaf
on 3 Aug 2021
instead of for n =linspace(1,2,length(x))
use for n= 1:2:length(x) if you want vector with elements spaced by 2
or for n=1:length(x) if you want vector with ellemnts spaced by1
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!