%  Make a Matlab demonstration of the non-linear
%  build-up for harmonic wave
%
%  Version 1.0, 22/4-2003, JAJ
%   Version 1.2, October 1, 2018, JAJ
%      Adapted for newer versions of Matlab


%  Set default text font and line size

set(0,'defaultaxesfontsize',18);
set(0,'defaulttextfontsize',18);

clf
hp=axes('position',[0.25 0.6 0.65 0.3]);
set(hp,'NextPlot','replace');
hdft=axes('position',[0.25 0.125 0.65 0.3]);
set(hdft,'NextPlot','replace');

%  Define the basic pulse

fs=100e6;            %  Sampling frequency [Hz]
f0=3.05e6;              %  Center frequency   [Hz]
N=6;                 %  Number of periods in pulse
P0=1e6;              %  Pressure amplitude [Pa]

%  Generate the ultrasound pulse

P=P0*sin(2*pi*f0*(0:1/fs:N/f0));
P=[P.*hanning(length(P))' 0];

%  Show the first pulse

z_max=0.05; 
display_pulse (hp, hdft, P, z_max, fs);

%  Place push buttons on the display

depth_slider=uicontrol('Style','slider','Units','normalized','Position',[0.02 0.9 0.15 0.08],...
        'Value',0.005,'Max',0.15,'Min',0.005,...
        'Callback','z_max=get(depth_slider,''value''); display_pulse (hp, hdft, P, z_max, fs);');

t4=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.8 0.15 0.08],...
             'Callback','z_max=0.05; display_pulse (hp, hdft, P, z_max, fs);',...
             'String','Depth', 'fontsize',18);

         
t5=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.65 0.15 0.08],...
             'Callback','P=P/2; display_pulse (hp, hdft, P, z_max, fs);',...
             'String','Lower pressure', 'fontsize',18);

t6=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.55 0.15 0.08],...
             'Callback','P=P*2; display_pulse (hp, hdft, P, z_max, fs);',...
             'String','Higher pressure', 'fontsize',18);

         
t7=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.4 0.15 0.08],...
             'Callback','display_pulse_inversion (hp, hdft, P, z_max, fs);',...
             'String','Pulse inversion', 'fontsize',18);

t8=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.25 0.15 0.08],...
             'Callback','N=2.5; P=P0*sin(2*pi*f0*(0:1/fs:N/f0)); P=P.*hanning(length(P))''; P(round(6*fs/f0))=0; display_pulse (hp, hdft, P, z_max, fs);',...
             'String','Short pulse', 'fontsize',18);

t9=uicontrol('Style','Pushbutton','Units','normalized','Position',[0.02 0.15 0.15 0.08],...
             'Callback','N=6; P=P0*sin(2*pi*f0*(0:1/fs:N/f0)); P=[P.*hanning(length(P))'' 0]; display_pulse (hp, hdft, P, z_max, fs);',...
             'String','Long pulse', 'fontsize',18);

