%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Inputs:
%   -file_name: name of the file in single quote 
%   -Fs: Frequency sample, in our measurements, it is 1.2800e+13 
%   -fmin: lower band freqquency
%   -fmax: upper band frequency
%Output:
%   -p: power in watt
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% if you don't want to calculate the power in a specific frequency band, then put Fs, fmin,
% and fmax equal to zero 
function [p] = powerCal(file_name, Fs, fmin, fmax)
   

    %Read the .picotd file
    [t, x] = readPicotd(file_name); 

    %Filter time domain plot to get rid of excess oscillations 
    x_filtered = filterTimeDomain(x);
 
    if Fs == 0 && fmin==0 && fmax==0
       p = bandpower(x_filtered);
    else
        % calculate the average of power in the frequency band of [fmin
        % fmax]
       p = bandpower(x_filtered, Fs,[fmin fmax]); 
    end

end