Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

error in ASK-4 Matlab code

Status
Not open for further replies.

Shruti01

Member level 3
Joined
Apr 14, 2010
Messages
67
Helped
3
Reputation
6
Reaction score
3
Trophy points
1,288
Location
Mumbai, India
Activity points
1,941
Hello All,

The code for ASK-4 is as follows:

N = 8; % The number of bits to send - Frame Length
bit_stream = round(rand(1,N)) % Random bit stream
A1 = 3; % Amplitude for 0 bit
A2 = 5; % Amplitude for 1 bit
f = 3; % Frequency of Modulating Signal
fs = 100; % Sampling rate
t = 0:1/fs:1; % Time for 1 bit
% This time variable is just for plot
time = [];
ASK4_signal = [];
for ii = 1: 1: length(bit_stream)
ASK4_signal = [ASK4_signal (bit_stream(ii)==0)&&(bit_stream(ii)==0)*A1*sin(2*pi*f*t)+(bit_stream(ii)==0)&&(bit_stream(ii)==1)*A2*sin(2*pi*f*t)+(bit_stream(ii)==1)&&(bit_stream(ii)==0)*-A2*sin(2*pi*f*t)+(bit_stream(ii)==1)&&(bit_stream(ii)==1)*-A1*sin(2*pi*f*t)];
time = [time t];
t = t + 1;
end
subplot(2,1,1);
plot(time,ASK4_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('ASK4');
%axis([0 time(end) 1.5 1.5]);
grid on;

When I run the above code, it gives me following error as
Operands to the || and && operators must be convertible to logical scalar
values.

Error in Untitled3 (line 12)
ASK4_signal = [ASK4_signal
(bit_stream(ii)==0)&&(bit_stream(ii)==0)*A1*sin(2*pi*f*t)+(bit_stream(ii)==0)&&(bit_stream(ii)==1)*A2*sin(2*pi*f*t)+(bit_stream(ii)==1)&&(bit_stream(ii)==0)*-A2*sin(2*p

I am not able to understand what is wrong in the code. Kindly help me.

Regards,
Shruti
 

it seems that a comma is missing in: (bit_stream(i i)

Try the following:

N = 8; % The number of bits to send - Frame Length
bit_stream = round(rand(1,N)) % Random bit stream
A1 = 3; % Amplitude for 0 bit
A2 = 5; % Amplitude for 1 bit
f = 3; % Frequency of Modulating Signal
fs = 100; % Sampling rate
t = 0:1/fs:1; % Time for 1 bit
% This time variable is just for plot
time = [];
ASK4_signal = [];
for ii = 1: 1: length(bit_stream)
ASK4_signal = [ASK4_signal (bit_stream(ii)==0)&&(bit_stream(ii)==0)*A1*sin(2* pi*f*t)+(bit_stream(ii)==0)&&(bit_stream(ii)==1)*A 2*sin(2*pi*f*t)+(bit_stream(ii)==1)&&(bit_stream(i,i)==0)*-A2*sin(2*pi*f*t)+(bit_stream(ii)==1)&&(bit_stream( ii)==1)*-A1*sin(2*pi*f*t)];
time = [time t];
t = t + 1;
end
subplot(2,1,1);
plot(time,ASK4_signal,'LineWidth',2);
xlabel('Time (bit period)');
ylabel('Amplitude');
title('ASK4');
%axis([0 time(end) 1.5 1.5]);
grid on;
 

send you my code:
close all
clear all
clc
%ASK..............
SNR=linspace(10,30,10);%dB
N=10^6;% number of bit
a1=3;a2=8; %amplitude for 0 bit & 1 bit.
A=[3 8];
f=3; % carrier frequency.
n=30;% number sample of bit.
bit_stream= round(rand(1,N));
fres=A(bit_stream+1);
bit_stream_sig= rectpulse(bit_stream,n);
t=linspace(0,1,30);carrier0=3*sin(2*pi*f*t);carrier1=a2*sin(2*pi*f*t);
% ask signal
for i=1:length(bit_stream)
if bit_stream(i)==0
ask_signal((i-1)*30+1:i*30)=carrier0;
else
ask_signal((i-1)*30+1:i*30)=carrier1;
end
end
plot(bit_stream_sig(1:8*30));hold on;plot(ask_signal(1:8*30),'r');
for ii=1:length(SNR)
ask_receive=awgn(ask_signal,SNR(ii),'measured');
%recover ask signal
ask_receive=ask_receive';
ask_receive = reshape(ask_receive,n,N);
[a b]= size(ask_receive);
for i=1:b
ask_receive:),i)=ask_receive:),i).*sin(2*pi*f*t)';
end;
ask_receive=round(mean(ask_receive,1)*2);
%bit error
N_err=biterr(ask_receive,fres);
BER(ii)=N_err/N;
end
figure(2)
semilogy(SNR,BER)
grid on
I would like this code can help you!have fun
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top