Calculate the RMS Value of signal, Iam getting an error:

2 visualizaciones (últimos 30 días)
%Generate bit sequence
bit_seq=[1 0 0 1 1 0 1 1];
%Consider bit period. This also defines the bit frequency/data rate
%Data rate=1MHz
bit_period=0.000001;
%There are 8 bits in the sequence. The period for each bit is 0.000001
%Hence the time scale will be in the range of 0 to 8*10^-6 for 8 bits
t1=bit_period/1000:(bit_period/1000)*1:1000*length(bit_seq)*(bit_period/1000);
bit=[];
for n=1:1:length(bit_seq)
if bit_seq(n)==1;
se=ones(1,1000);
else bit_seq(n)==0;
se=zeros(1,1000);;
end
bit=[bit se];
end
subplot(3,1,1)
plot(t1,bit,'g','linewidth',1)
xlabel('Time')
ylabel('Amplitude')
title('Bit Sequence')
t2=0:0.001:1-(0.001);
sigma=.1;
mean=0.5;
b=2*(sigma)^2;
g=exp((-(t2-mean).^2)/b);
%Generation of gaussian signal for the bits
bit1=[];
for n=1:1:length(bit_seq)
if bit_seq(n)==1;
se=exp((-(t2-mean).^2)/b);
else bit_seq(n)==0;
se=0*exp((-(t2-mean).^2)/b);
end
bit1=[bit1 se];
end
subplot(3,1,2)
plot(t1,bit1,'r','linewidth',1)
xlabel('Time')
ylabel('Amplitude')
title('Gaussian signal')
%Finding the RMS Value of the gaussian signal
RMS1=sqrt(mean(bit1.^2));
disp(RMS1)
Iam getting an error:
Array indices must be positive integers or logical values.
Error in ask_gaussian_rms (line 53)
RMS1=sqrt(mean(bit1.^2));
>>

Respuesta aceptada

Eric
Eric el 3 de Jun. de 2020
You are trying to use the MATLAB function mean(), but you have a variable of the same name, which it why it thinks bit1.^2 is an index rather than an input argument for the mean() function. Try to avoid using variable names that are also MATLAB function names (e.g. use mymean instead).

Más respuestas (0)

Categorías

Más información sobre Electrophysiology en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by