%% init
clear all;
close all;
clc;
%% settings
file = "20200508_embedded_element_referenced.txt";
resample = 1; % take every xth value, 1 for no resampling
%% read data
data = dlmread(file, "", 2, 0);
theta = data(1:resample:end, 1); % values in degree
phi = data(1:resample:end, 2); % values in degree
ffdata = data(1:resample:end, 3); % directivity in dBi
%% transform spherical to cartesian coordinates
x = ffdata .* sind(theta) .* cosd(phi);
y = ffdata .* sind(theta) .* sind(phi);
z = ffdata .* cosd(theta);
%% plot farfield
figure;
plot3(x, y, z, 'x');