Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (120 points)

When I try to run my code:

import matplotlib.pyplot as plt
import numpy as np
import math
import cmath
import os

# Create target Directory if don't exist

if not os.path.exists('Sparameters images'):
    os.mkdir('Sparameters images')

## UPLOAD DATA ##############################
#############################################

HB1 = np.loadtxt('S11_Magnitude\S11_Magnitude.txt',skiprows=7)
HB2 = np.loadtxt('S11_Phase\S11_Phase.txt',skiprows=7)
HB3 = np.loadtxt('S21_Magnitude\S12_Magnitude.txt',skiprows=7)
HB4 = np.loadtxt('S21_Phase\S12_Phase.txt',skiprows=7)

## CONVERT DATA TO LINEAR MAGNITUDE AND RADS
###############################################################

W1=HB1[:,0]
A_mag=np.power(10,HB1[:,1]/10)*100
W2=HB2[:,0]
A_Phase=HB2[:,1]
W3=HB3[:,0]
B_mag=np.power(10,HB3[:,1]/10)*100
W4=HB4[:,0]
B_Phase=HB4[:,1] 

## CONVERTING INTO COMPLEX NUMBERS ##############################

S11 = np.vectorize(complex)(A_mag * math.cos(A_Phase), A_mag * math.sin(A_Phase))
S21 = np.vectorize(complex)(B_mag * math.cos(B_Phase), B_mag * math.sin(B_Phase))

 I have errors like : 

TypeError: only size-1 arrays can be converted to Python scalars

I have also tried to express S11 and S21 in a different way:

S11 = (A_mag * math.cos(A_Phase)) + 1j * (A_mag * math.sin(A_Phase))

S21 = (B_mag * math.cos(B_Phase) + 1j * (B_mag * math.sin(B_Phase))

But still It doesn't work. Can I do something else to solve this problem? 

Please log in or register to answer this question.

Browse Categories

...