%function [AudioFile] = PrintInUltrasound(TextStr)

% addpath([pwd '\mp3readwrite'])

% Text =  fileread('C:\Local\HashTags.txt');

TextStr = 'Dolphins can hear from 40000 Hz - 100000 Hz #UoSRoadshow #ultracache   ';
tonelength = 0.08; % [s]

% TextStr = Text;

% Pick seven frequencies between 18 kHz and 20 kHz
ftones = logspace(log10(20100),log10(21000),7);
Fs = 44100;
tVec = (1:(Fs*tonelength))/Fs;

% Estimate audio file length

Characters = length(TextStr);
TotalTime = Characters*7*tonelength;
disp(['Total file time' num2str(TotalTime/60) 'minutes'])

% Generate sound file pulsing those tones

T1 = sin(2*pi*ftones(1)*tVec).*tukeywin(length(tVec),0.2).';
T2 = sin(2*pi*ftones(2)*tVec).*tukeywin(length(tVec),0.2).';
T3 = sin(2*pi*ftones(3)*tVec).*tukeywin(length(tVec),0.2).';
T4 = sin(2*pi*ftones(4)*tVec).*tukeywin(length(tVec),0.2).';
T5 = sin(2*pi*ftones(5)*tVec).*tukeywin(length(tVec),0.2).';
T6 = sin(2*pi*ftones(6)*tVec).*tukeywin(length(tVec),0.2).';
T7 = sin(2*pi*ftones(7)*tVec).*tukeywin(length(tVec),0.2).';
S1 = zeros(size(T1));


N0 = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 T5 T5]+...
    [T4 S1 T4 S1 T4]+...
    [T3 T3 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
N1 = [S1 S1 T7 S1 S1]+...
    [S1 T6 T6 S1 S1]+...
    [T5 S1 T5 S1 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 S1 T2 S1 S1]+...
    [S1 S1 T1 S1 S1];
N2 = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [S1 S1 S1 S1 T5]+...
    [S1 S1 S1 T4 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 T2 S1 S1 S1]+...
    [T1 T1 T1 T1 T1];
N3 = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [S1 S1 S1 S1 T5]+...
    [S1 S1 T4 T4 S1]+...
    [S1 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
N4 = [S1 S1 S1 T7 S1]+...
    [S1 S1 T6 T6 S1]+...
    [S1 T5 S1 T5 S1]+...
    [T4 S1 S1 T4 S1]+...
    [T3 T3 T3 T3 T3]+...
    [S1 S1 S1 T2 S1]+...
    [S1 S1 S1 T1 S1];
N5 = [S1 S1 S1 T7 S1]+...
    [S1 S1 T6 T6 S1]+...
    [S1 T5 S1 T5 S1]+...
    [T4 S1 S1 T4 S1]+...
    [T3 T3 T3 T3 T3]+...
    [S1 S1 S1 T2 S1]+...
    [S1 S1 S1 T1 S1];
N6 = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 S1]+...
    [T4 T4 T4 T4 S1]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
N7 = [T7 T7 T7 T7 T7]+...
    [S1 S1 S1 S1 T6]+...
    [S1 S1 S1 T5 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 T3 S1 S1 S1]+...
    [S1 T2 S1 S1 S1]+...
    [S1 T1 S1 S1 S1];
N8 =[S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [S1 T4 T4 T4 S1]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
HA = [S1 T7 S1 T7 S1]+...
    [S1 T6 S1 T6 S1]+...
    [T5 T5 T5 T5 T5]+...
    [S1 T4 S1 T4 S1]+...
    [T3 T3 T3 T3 T3]+...
    [S1 T2 S1 T2 S1]+...
    [S1 T1 S1 T1 S1];
A = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 T4 T4 T4 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [T1 S1 S1 S1 T1];
B = [T7 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 T4 T4 T4 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [T1 T1 T1 T1 S1];
C = [S1 T7 T7 T7 T7]+...
    [T6 S1 S1 S1 S1]+...
    [T5 S1 S1 S1 S1]+...
    [T4 S1 S1 S1 S1]+...
    [T3 S1 S1 S1 S1]+...
    [T2 S1 S1 S1 S1]+...
    [S1 T1 T1 T1 T1];
D = [T7 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 S1 S1 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [T1 T1 T1 T1 S1];
E = [T7 T7 T7 T7 T7]+...
    [T6 S1 S1 S1 S1]+...
    [T5 S1 S1 S1 S1]+...
    [T4 T4 T4 T4 S1]+...
    [T3 S1 S1 S1 S1]+...
    [T2 S1 S1 S1 S1]+...
    [T1 T1 T1 T1 T1];
F = [T7 T7 T7 T7 T7]+...
    [T6 S1 S1 S1 S1]+...
    [T5 S1 S1 S1 S1]+...
    [T4 T4 T4 T4 S1]+...
    [T3 S1 S1 S1 S1]+...
    [T2 S1 S1 S1 S1]+...
    [T1 S1 S1 S1 S1];
G = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 S1]+...
    [T5 S1 S1 S1 S1]+...
    [T4 S1 T4 T4 S1]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
H = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 T4 T4 T4 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [T1 S1 S1 S1 T1];
I = [T7 T7 T7 T7 T7]+...
    [S1 S1 T6 S1 S1]+...
    [S1 S1 T5 S1 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 S1 T2 S1 S1]+...
    [T1 T1 T1 T1 T1];
J = [S1 S1 S1 S1 T7]+...
    [S1 S1 S1 S1 T6]+...
    [S1 S1 S1 S1 T5]+...
    [S1 S1 S1 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
K = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 T6 S1]+...
    [T5 S1 T5 S1 S1]+...
    [T4 T4 S1 S1 S1]+...
    [T3 S1 T3 S1 S1]+...
    [T2 S1 S1 T2 S1]+...
    [T1 S1 S1 S1 T1];
L = [T7 S1 S1 S1 S1]+...
    [T6 S1 S1 S1 S1]+...
    [T5 S1 S1 S1 S1]+...
    [T4 S1 S1 S1 S1]+...
    [T3 S1 S1 S1 S1]+...
    [T2 S1 S1 S1 S1]+...
    [T1 T1 T1 T1 T1];
M = [T7 S1 S1 S1 T7]+...
    [T6 T6 S1 T6 T6]+...
    [T5 S1 T5 S1 T5]+...
    [T4 S1 T4 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [T1 S1 S1 S1 T1];
N = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [T5 T5 T5 S1 T5]+...
    [T4 S1 T4 S1 T4]+...
    [T3 S1 S1 T3 T3]+...
    [T2 S1 S1 S1 T2]+...
    [T1 S1 S1 S1 T1];
O = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 S1 S1 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
P = [T7 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 T4 T4 T4 S1]+...
    [T3 S1 S1 S1 S1]+...
    [T2 S1 S1 S1 S1]+...
    [T1 S1 S1 S1 S1];
Q = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 S1 S1 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [S1 T2 T2 T2 S1]+...
    [S1 S1 S1 T1 T1];
R = [T7 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 T4 T4 T4 S1]+...
    [T3 S1 T3 S1 S1]+...
    [T2 S1 S1 T2 S1]+...
    [T1 S1 S1 S1 T1];
S = [S1 T7 T7 T7 S1]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 S1]+...
    [S1 T4 T4 T4 S1]+...
    [S1 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
T = [T7 T7 T7 T7 T7]+...
    [S1 S1 T6 S1 S1]+...
    [S1 S1 T5 S1 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 S1 T2 S1 S1]+...
    [S1 S1 T1 S1 S1];
U = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 S1 S1 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [T2 S1 S1 S1 T2]+...
    [S1 T1 T1 T1 S1];
V = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 S1 S1 S1 T4]+...
    [T3 S1 S1 S1 T3]+...
    [S1 T2 S1 T2 S1]+...
    [S1 S1 T1 S1 S1];
W = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [T4 S1 T4 S1 T4]+...
    [T3 S1 T3 S1 T3]+...
    [T2 S1 T2 S1 T2]+...
    [S1 T1 S1 T1 S1];
X = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [S1 T5 S1 T5 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 T3 S1 T3 S1]+...
    [T2 S1 S1 S1 T2]+...
    [T1 S1 S1 S1 T1];
Y = [T7 S1 S1 S1 T7]+...
    [T6 S1 S1 S1 T6]+...
    [S1 T5 S1 T5 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 S1 T2 S1 S1]+...
    [S1 S1 T1 S1 S1];
Z = [T7 T7 T7 T7 T7]+...
    [S1 S1 S1 S1 T6]+...
    [S1 S1 S1 T5 S1]+...
    [S1 S1 T4 S1 S1]+...
    [S1 T3 S1 S1 S1]+...
    [T2 S1 S1 S1 S1]+...
    [T1 T1 T1 T1 T1];
Qu =[S1 T7 T7 T7 T7]+...
    [T6 S1 S1 S1 T6]+...
    [T5 S1 S1 S1 T5]+...
    [S1 S1 S1 T4 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 T1 S1 S1];
Eq =[S1 S1 S1 S1 S1]+...
    [T6 T6 T6 T6 T6]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [T2 T2 T2 T2 T2]+...
    [S1 S1 S1 S1 S1];
Gt =[T7 S1 S1 S1 S1]+...
    [S1 T6 S1 S1 S1]+...
    [S1 S1 T5 S1 S1]+...
    [S1 S1 S1 T4 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 T2 S1 S1 S1]+...
    [T1 S1 S1 S1 S1];
Lt =[S1 S1 S1 S1 T7]+...
    [S1 S1 S1 T6 S1]+...
    [S1 S1 T5 S1 S1]+...
    [S1 T4 S1 S1 S1]+...
    [S1 S1 T3 S1 S1]+...
    [S1 S1 S1 T2 S1]+...
    [S1 S1 S1 S1 T1];
Da =[S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 T4 T4 T4 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1];

Qw =[S1 T7 S1 T7 S1]+...
    [S1 T6 S1 T6 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1]+...
    [S1 S1 S1 S1 S1];

Het =[T7 T7 T7 T7 T7]+...
    [T6 T6 T6 T6 T6]+...
    [T5 T5 T5 T5 T5]+...
    [T4 T4 T4 T4 T4]+...
    [T3 T3 T3 T3 T3]+...
    [T2 T2 T2 T2 T2]+...
    [T1 T1 T1 T1 T1];

Ex = T7+...
     T6+...
     T5+...
     T4+...
     T3+...
     S1+...
     T1;
 
Pe = T1;

Sp = [S1 S1];

AudioFile = 0;
for icount = 1:Characters
    disp(['Percent complete ' num2str(icount/Characters*100)]);
    if strcmpi(TextStr(icount),'0')
        AudioFile = [AudioFile N0 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'1')
        AudioFile = [AudioFile N1 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'2')
        AudioFile = [AudioFile N2 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'3')
        AudioFile = [AudioFile N3 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'4')
        AudioFile = [AudioFile N4 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'5')
        AudioFile = [AudioFile N5 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'6')
        AudioFile = [AudioFile N6 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'7')
        AudioFile = [AudioFile N7 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'8')
        AudioFile = [AudioFile N8 Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'#')
        AudioFile = [AudioFile HA Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'a')
        AudioFile = [AudioFile A Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'b')
        AudioFile = [AudioFile B Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'c')
        AudioFile = [AudioFile C Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'d')
        AudioFile = [AudioFile D Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'e')
        AudioFile = [AudioFile E Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'f')
        AudioFile = [AudioFile F Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'g')
        AudioFile = [AudioFile G Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'h')
        AudioFile = [AudioFile H Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'i')
        AudioFile = [AudioFile I Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'j')
        AudioFile = [AudioFile J Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'k')
        AudioFile = [AudioFile K Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'l')
        AudioFile = [AudioFile L Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'m')
        AudioFile = [AudioFile M Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'n')
        AudioFile = [AudioFile N Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'o')
        AudioFile = [AudioFile O Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'p')
        AudioFile = [AudioFile P Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'q')
        AudioFile = [AudioFile Q Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'r')
        AudioFile = [AudioFile R Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'s')
        AudioFile = [AudioFile S Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'t')
        AudioFile = [AudioFile T Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'u')
        AudioFile = [AudioFile U Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'v')
        AudioFile = [AudioFile V Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'w')
        AudioFile = [AudioFile W Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'x')
        AudioFile = [AudioFile X Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'y')
        AudioFile = [AudioFile Y Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'z')
        AudioFile = [AudioFile Z Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),' ')
        AudioFile = [AudioFile Sp Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'.')
        AudioFile = [AudioFile Pe Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'!')
        AudioFile = [AudioFile Ex Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'?')
        AudioFile = [AudioFile Qu Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'"')
        AudioFile = [AudioFile Qw Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'=')
        AudioFile = [AudioFile Eq Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'>')
        AudioFile = [AudioFile Gt Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'<')
        AudioFile = [AudioFile Lt Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'-')
        AudioFile = [AudioFile Da Sp]; %#ok<AGROW>
    elseif strcmpi(TextStr(icount),'^')
        AudioFile = [AudioFile Het Sp]; %#ok<AGROW>
    end
end
% AudioFile = [A Sp B Sp C Sp D Sp E Sp F Sp G Sp...
%     H Sp I Sp J Sp K Sp L Sp M Sp N];

% tVec2 =(1:(Fs*tonelength*4))/Fs;
% T8 = 20*sin(2*pi*500*tVec2).*tukeywin(length(tVec2),0.2).';

AudioFile = (AudioFile)/max(AudioFile)*.8;

% sound(AudioFile,Fs)

audiowrite('001.wav',AudioFile,Fs)
% mp3write(AudioFile,Fs,'001.mp3');

return
%% Spectrogram

[S,F,T] = spectrogram(AudioFile,512,256,512,Fs);
%%
figure(1)
cmap = colormap('gray');
colormap(flipud(cmap));
imagesc(T,F,abs(S))
set(gca,'TickLabelInterpreter','latex','FontSize',16)
set(gca,'ydir','normal','fontsize',16)
axis([-0.1 0.4 19900 21200])
xlabel('Time [s]','Interpreter','Latex')
ylabel('Frequency [Hz]','Interpreter','Latex')
set(gca,'ytick',[20000 20500 21000],'yticklabel',[20000 20500 21000])
export_fig('Spectrogram','-png','-m3','-transparent','-nocrop')
%% Create image of same size

figure(2)
axis([min(T) max(T) min(F) max(F)])
HT = text(0,20000,'Your are bold and loud. Should as life will sound!');
set(HT,'FontSize',14,'VerticalAlignment','Bottom')
axis off
set(gca,'position',[0 0 1 1])
% export_fig('Poem1','-bmp','-m2','-transparent','-nocrop')