I am trying to implement this code in python. It works fine in MATLAB
But when I use same logic the python interpreter gives a different answer.
I am having problem in finding the correct function or method in python
. Need help regarding this.
Code is given below
Code:
Sensors = 10; %number of receivers
samples = 10000; %number of set of signals
p = 10; %number of signals
theta1 = [10 20 40 60 100 120 140 80 90 110];
angles = theta1*(pi/180);
X = zeros(Sensors,samples);
for k=1:p-1
Array_factor = exp(j*pi*cos(angles(1,k))*(0:Sensors-1 ));
br =ones(1,samples); %creating real values between 1-10000
temp = rand(1,samples); %generate random numbers b/w 1 and 10000
br(find(temp<.5))=-1; %find real numbers
bi =ones(1,samples); %creating imaginary values between 1-10000
temp = rand(1,samples); %generate c omplex random numbers b/w 1 and 10000
bi(find(temp<.5))=-1; %find imaginary numbers
b = br+j*bi;
X = X +Array_factor'*b; %complete Input signal combined with array factor
end
The above is a MATLAB
code Now I have converted it in Python
import numpy as np
#number of receivers
num_sensors = 10
#Total samples to scan
samples = 10
#number of signals
p = 10
theta1 = [10,20,40,60,100,120,140,80,90,110]
#angles in degrees
angles = [i*(np.pi/180) for i in theta1]
#Input Signal
X = np.zeros((num_sensors,samples), dtype = complex)
for k in range(1,p-1):
array_factor = np.exp(1j*np.pi*np.cos(angles[k])*np.arange(sensors))
#creating real values
br = np.ones(samples)
temp = np.random.rand(samples)
br[temp < 0.5] = -1
# br[temp<0.5] = -1
bi = np.ones(samples)
temp = np.random.rand(samples)
bi[temp<0.5] = -1
b = br + 1j*bi
X += np.dot(array_factor,b)
print(X)
Output expected in Python
X = 10 x 10000
double
b = 1 x 10000
double