%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Inputs:
%   -myfolder: address of the files: like: 'myfolder\*.picotd'
%   -num_samples: number of samples for each measurements 
%   -Fs: Frequency sample, in our measurements, it is 1.2800e+13 
%   -fmin: lower band freqquency
%   -fmax: upper band frequency 
%   -x_axis: an array for the x axis 
%   -x_str: title for the x axis, should be in single quote
%   -y_str: title for the y axis, should be in single quote
%   -title_str: title of the graph, should be in single quote
%Outputs:
%   -power(w) plot with 95% confidence interval 
%   -[mean_power]: an array of powers for the plot. it gives the y-axis values  
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if you don't want to calculate the power in a specific frequency band, then put Fs, fmin,
% and fmax equal to zero 
function [mean_power]= powerDiagram(myfolder, num_samples, Fs, fmin, fmax, x_axis, x_str, y_str, title_str)

[fileNameArrays] = readDir(myfolder, num_samples); 
% size of the array,; m is number of rows, and n is the number of columns
[m,n] = size(fileNameArrays);

% remove the .picotd part from the address
folder = strrep(myfolder, '*.picotd', '');

for i = 1 : m
    for j = 1 : n
        file = fileNameArrays(i,j);
        %concatenate the folder with each .picotd file, then pass it to the
        % powerCal() 
        ff = fullfile(folder, char(file));
        
        power(j) = powerCal(ff, Fs, fmin, fmax);
    end
    error(i) = ConfInterval(power); 
   
    mean_power(i) = powAverages(fileNameArrays(i,:), folder, Fs, fmin, fmax);
end

hold on; grid on;
errorbar(x_axis, mean_power, error); 

title(title_str);
xlabel(x_str);
ylabel(y_str);

end

    
    