To find the rms value
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Mrinmoyee Mukherjee
le 4 Juin 2020
Modifié(e) : Adam Danz
le 5 Juin 2020
%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;
mymean=0.5;
b=2*(sigma)^2;
g=exp((-(t2-mymean).^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-mymean).^2)/b);
else bit_seq(n)==0;
se=0*exp((-(t2-mymean).^2)/b);
end
bit1=[bit1 se];
end
subplot(3,1,2)
plot(t1,bit1,'r','linewidth',1)
xlabel('Time')
ylabel('Amplitude')
title('Gaussian signal')
y1=(bit1.^2)
b=length(y1)
sum1=0; for i=1:b
sum1= sum1+i;
end
disp(sum1)
mean1=sum1/b;
rms=sqrt(mean1)
%y2=mean(y1,'all')
%Finding the RMS Value of the gaussian signal
RMS1=sqrt(mean(bit1.^2));
disp(RMS1)
%Addition of noise. We need to add the noise to the gaussian
%signal. Consider the vector of the gaussian signal=bit1
L=length(bit1);
disp(L)
SNR_dB=13.6;
SNR = 10^(SNR_dB/10); %SNR to linear scale
disp(SNR)
Esym=sum(abs(bit1).^2)/(L)%Calculate actual symbol energy
disp(Esym)
N0=Esym/SNR; %Find the noise spectral density
disp(N0)
if(isreal(bit1)),
noiseSigma = sqrt(N0);%Standard deviation for AWGN Noise when x is real
n = noiseSigma*randn(1,L);%computed noise
else
noiseSigma=sqrt(N0/2);%Standard deviation for AWGN Noise when x is complex
n = noiseSigma*(randn(1,L)+1i*randn(1,L));%computed noise
end
y = bit1 + n; %received signal
subplot(3,1,3)
plot(t1,y,'o','linewidth',1)
xlabel('Time')
ylabel('Amplitude')
title('Gaussian signal with noise')
Iam getting an error at line 73 saying,
Array indices must be positive integers or logical values.
Error in ask_gaussian_rms (line 73)
Esym=sum(abs(bit1).^2)/(L)%Calculate actual symbol energy
1 commentaire
KSSV
le 4 Juin 2020
It should no tthrow any error actually. Check did you define any variable with the name sum?
What does which sum show?
Réponse acceptée
Adam Danz
le 4 Juin 2020
Modifié(e) : Adam Danz
le 5 Juin 2020
My bet is that you have a variable in the worksapace named "abs" which overrides Matlab's abs() function.
When you run the line below, abs(bit1) is not taking the absolute value of bit1. Instead, it's treating bit1 like a vector of indices and indicies must be positive integers or logical values as the error indicates. Instead, bit1 contains floating point decimals.
Esym=sum(abs(bit1).^2)/(L)
Solution: remove the variable 'abs' using clear('abs') or rename the variable.
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Marine and Underwater Vehicles dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!