%Produce file of values to run wavemaker for Bretchneider spectrum out of
%labview
clc, clear all
%first need to define inputs into Bretschneider function

wm=2*pi; %Modal or peak frequency in rad/s

H_sig=1.25; %signficant wave height

f_range=0.75:0.025:2.0; %frequency range [hz]
w_range=f_range*2*pi;  %frequency range [rad/s]

for n=1:length(w_range)-1
    we=w_range(n:n+1);
    [BS_we,M0,M1,M2,M3,M4]=BS(wm,we,H_sig);
    A(n)=sqrt(2)*sqrt(M0);
    w(n)=mean(we);
    phi(n)=rand(1)*2*pi;
end

t=0:0.1:30;

for k=1:length(t)
    for n=1:length(w_range)-1
        if k==1 || k==length(t)
            f(k,n)=A(n)*sin(w(n)*t(k));
        else
            f(k,n)=A(n)*sin(w(n)*t(k)+phi(n));
        end
    end
end
wave=[t',sum(f,2)];

dlmwrite('Bretschneider.lvm',wave,'delimiter','\t')
%need to figure out how to add extra empty column on left