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
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