I have some problem here. Please look at my code and I don't know what's wrong in the code. It is simple but the results are confusing me. I attached the code below.
import numpy as np
import matplotlib.pyplot as plt
def S(xc):
N=len(xc)
r=0.0
s=0.0
# calculation quartile
for m in range(0,N-1):
for n in range(m+1,N):
if (xc[m] > xc[n]):
q=xc[m]
xc[m]=xc[n]
xc[n]=q
if (N % 4 < 2):
q=(xc[N-N/4-1] + xc[N-N/4])*0.5-(xc[N/4-1]+xc[N/4])*0.5
else:
q=xc[N-N/4-1]-xc[N/4]
#calculation standard deviation
for m in range(0,N):
r+=xc[m]
s+=xc[m]*xc[m]
r=np.sqrt(s/N-(r/N)*(r/N))
#calculation
if (q<r):
s=q
else:
s=r
hasil=0.9*(s/1.34)*pow(N,-0.2)
return hasil
fc=0.3
fm=0.02
mu=1
Nsim=10
bb=[]
for nn in range(0,Nsim):
bb.append((1+(mu*np.cos(2*np.pi*fm*nn)))*np.cos(2*np.pi*fc*nn))
print bb
print S(bb)
print bb
The code works while I just delete the function of "S" in the main function, however, after the "S" function, the data on variable "bb" was different even though I just print the same variable. I don't understand what happened.
I appreciate your help. Thanks a lot
Alvin