# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

import numpy as np
import matplotlib.pyplot as plt
import csv

# # Parse the data file to obtain the raw data

# +
path = '/Users/ziegler/Desktop/'
file='return_loss_HW_dipole.csv'

raw_data={'f':[],'s11':{'mag':[],'phi':[]}}
#frequency_of_interest=26e9
with open(path+file) as infile:
    read=csv.reader(infile,delimiter=',')
    for row in read:
        print(row)
        try:
            if len(row)>0:
                raw_data['f'].append(float(row[0]))
                raw_data['s11']['mag'].append(float(row[1]))
                raw_data['s11']['phi'].append(float(row[2]))
                #raw_data['s31']['mag'].append(float(row[17]))
                #raw_data['s31']['phi'].append(float(row[18]))
                #raw_data['s41']['mag'].append(float(row[25]))
                #raw_data['s41']['phi'].append(float(row[26]))
                #if int(row[0])==int(frequency_of_interest):
                    
                #    raw_data.update({'s':[]})
                #    for n in row[1:]:
                #        raw_data['s'].append(float(n))
        except ValueError:
            continue
# -

# # Plot of the unwrapped phases of S21, S31, and S41

# +
plt.figure(figsize=(12,9))
plt.plot(raw_data['f'],np.unwrap(np.radians(raw_data['s11']['phi'])))
#plt.plot(raw_data['f'],np.unwrap(np.radians(raw_data['s31']['phi'])))
#plt.plot(raw_data['f'],np.unwrap(np.radians(raw_data['s41']['phi'])))

plt.figure(figsize=(12,9))
plt.plot(raw_data['f'],np.gradient(np.unwrap(np.radians(raw_data['s11']['phi'])),raw_data['f']),'.')
#plt.plot(raw_data['f'],np.gradient(np.unwrap(np.radians(raw_data['s31']['phi'])),raw_data['f']),'.')
#plt.plot(raw_data['f'],np.gradient(np.unwrap(np.radians(raw_data['s41']['phi'])),raw_data['f']),'.')

length=-np.gradient(np.unwrap(np.radians(raw_data['s11']['phi'])),raw_data['f'])*3e10/(2*np.pi*2) # in cm
#r3=np.mean(np.gradient(np.unwrap(np.radians(raw_data['s31']['phi'])),raw_data['f']))*3e10/(2*np.pi)
#r4=np.mean(np.gradient(np.unwrap(np.radians(raw_data['s41']['phi'])),raw_data['f']))*3e10/(2*np.pi)

#print(r2,r3,r4)
plt.figure(figsize=(12,9))
plt.plot(raw_data['f'],length,'.')
# -

# # Zero pad frequencies before the starting frequency in the raw data

# +
pad_data={'f':[],'s21':{'mag':[],'phi':[]},'s31':{'mag':[],'phi':[]},'s41':{'mag':[],'phi':[]}}
for i,k in enumerate(raw_data):
    if i==0:
        pad_data['f']=np.append(np.arange(0,raw_data['f'][0],raw_data['f'][1]-raw_data['f'][0]),raw_data['f'])
        print(k)
    else:
        for j,l in enumerate(raw_data[k]):
            print(k,l)
            pad_data[k][l]=np.append(np.zeros(len(np.arange(0,raw_data['f'][0],raw_data['f'][1]-raw_data['f'][0])))
                                     ,raw_data[k][l])



# +
#plt.figure(figsize=(12,9))
#plt.plot(pad_data['f'],np.unwrap(np.radians(pad_data['s21']['phi'])))
#plt.plot(pad_data['f'],np.unwrap(np.radians(pad_data['s31']['phi'])))
#plt.plot(pad_data['f'],np.unwrap(np.radians(pad_data['s41']['phi'])))

plt.figure(figsize=(12,9))
plt.plot(np.fft.irfft(np.unwrap(np.radians(pad_data['s21']['phi']))))
# -

raw_data['f'][0]



StarcoderdataJupyterScriptsDedupFiltered