function [freq, chirp, fm_1, fm_2, fm_3, power, phase] = Read_FM(pf);
format long e
%Read_FM
%Reads the 
%{
%Zum Testen der Funktion
pf = 'F:\Arbeit\Chirp\ref_0.4\';
bias = 60;
mod_amp = 60;
%}
%pf = [pf '\bias_' num2str(bias) '\mod_amp_' num2str(mod_amp) '\'];
d=dir(pf);
fcount=0;
for fc= 1:length(d)
    if ~d(fc).isdir
        fcount=fcount+1;
        fname{fc} = d(fc).name;
    end
end
nfiles = fcount;

% Initialisierung diverser Matrizen, die später benötigt werden
freq = [];
chirp = []; chirp_us = [];
fm_1 = []; fm_1_us = [];
fm_2 = []; fm_2_us = [];
fm_3 = []; fm_3_us = [];
power = []; power_us = [];

phase = [];

if nfiles > 3
    for fnn=3:nfiles+2
        if findstr(char(fname(fnn)), 'phase')==13;
            charfile = char(fname(fnn));
            ind=strfind(charfile,'.dat'); % Finden der Phase, da sie die letzten 2-3 Ziffern vor ".dat" ist
            ph=str2num(charfile([18:ind-1]));
            phase = [phase ph];
            a = importdata([pf '\' charfile]);
            dataend=length(a.data);
            dataend
            freq = a.data(1:dataend,1);
            chirp = [chirp length(freq)];
            if length(freq) > 40
                
            end
            %{
            chirp_us = [chirp_us a.data(1:dataend,2)];
            fm_1_us = [fm_1_us a.data(1:dataend,3)];
            fm_2_us = [fm_2_us a.data(1:dataend,4)];
            fm_3_us = [fm_3_us a.data(1:dataend,5)];
            power_us = [power_us a.data(1,6)];
            %}
        end
    end
end

% Sorting the Arrays by hand, cause "sort" stinks ;)
[sorted_phase, indices] = sort(phase);
%{
chirp = Sort_by_Row(chirp_us, phase);
fm_1 = Sort_by_Row(fm_1_us, phase);
fm_2 = Sort_by_Row(fm_2_us, phase);
fm_3 = Sort_by_Row(fm_3_us, phase);
power = Sort_by_Row(power_us, phase);
%}
% Sorting is done by function Sort_by_Row, if errors occur of function not
% available use following
%{
for n = 1:length(sorted_phase)
    chirp = [chirp chirp_us(:,indices(n))];
    fm_1 = [fm_1 fm_1_us(:,indices(n))];
    fm_2 = [fm_2 fm_2_us(:,indices(n))];
    fm_3 = [fm_3 fm_3_us(:,indices(n))];
    power = [power power_us(indices(n))];
end
%}