image thumbnail

morse code hearing trainer

by

 

Convert characters in the text file to morse code

morse.m
function varargout = morse(varargin)
% MORSE MATLAB code for morse.fig
%      MORSE, by itself, creates a new MORSE or raises the existing
%      singleton*.
%
%      H = MORSE returns the handle to a new MORSE or the handle to
%      the existing singleton*.
%
%      MORSE('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MORSE.M with the given input arguments.
%
%      MORSE('Property','Value',...) creates a new MORSE or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before morse_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to morse_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help morse

% Last Modified by GUIDE v2.5 05-Nov-2013 14:36:50

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @morse_OpeningFcn, ...
                   'gui_OutputFcn',  @morse_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before morse is made visible.
function morse_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to morse (see VARARGIN)

% Choose default command line output for morse
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes morse wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = morse_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.output;


% --- Executes on selection change in popupmenu1.
function popupmenu1_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% qg: contents = cellstr(get(hObject,'String')) ̓ZzƂ popupmenu1 ̓eԂ܂B
%        contents{get(hObject,'Value')}  popupmenu1 IڂԂ܂B


% --- Executes during object creation, after setting all properties.
function popupmenu1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in popupmenu2.
function popupmenu2_Callback(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% qg: contents = cellstr(get(hObject,'String')) ̓ZzƂ popupmenu2 ̓eԂ܂B
%        contents{get(hObject,'Value')}  popupmenu2 IڂԂ܂B


% --- Executes during object creation, after setting all properties.
function popupmenu2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to popupmenu2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
popup_sel_index = get(handles.popupmenu1, 'Value');
popup_sel_index2 = get(handles.popupmenu2, 'Value');
switch popup_sel_index
    case 1
        speed=30;
    case 2
        speed=60;
    case 3
        speed=90;
    case 4
        speed=120;


end

switch popup_sel_index2
    case 1
        tone=600;
    case 2
        tone=800;
    case 3
        tone=1000;
    case 4
        tone=1200;
    case 5
        tone=1400;


end

morse_exe(tone,speed);

function morse_exe(tone,speed)
%     morse=100;
%     disp(tone)
%     disp(speed)

[FileName,PathName] = uigetfile('*.txt','Select the TXT code file');


fid = fopen(FileName);

tline = fgets(fid);
sss=[];
while ischar(tline)
  
   
    sss =strcat(sss, char(32),tline);
     tline = fgets(fid);
end

fclose(fid);
sss= upper(regexprep(sss,{char(13),char(10)},''));
A='103030';
B='30101010';
C='30103010';
D='301010';
E='10';
F='10103010';
G='303010';
H='10101010';
I='1010';
J='10303030';
K='301030';
L='10301010';
M='3030';
N='3010';
O='303030';
P='10303010';
Q='30301030';
R='103010';
S='101010';
T='30';
U='101030';
V='10101030';
W='103030';
X='30101030';
Y='30103030';
Z='30301010';

n1='1030303030';
n2='1010303030';
n3='1010103030';
n4='1010101030';
n5='1010101010';
n6='3010101010';
n7='3030101010';
n8='3030301010';
n9='3030303010';
n0='3030303030';

mp='103010301030';
mc='303010103030';
mq='101030301010';
mb='301030103030';
mh='301010101030';
ms='3010103010';
ma='103030103010';
mlc='3010303010';
mrc='301030301030';


bun=sss;
bunzz=[];
bbb=[];
aaa=[];
for i=1:length(bun)
    switch bun(i)
        case 'A'
            aaa=A;
        case 'B'
            aaa=B;
        case 'C'
            aaa=C;
        case 'D'
            aaa=D;
        case 'E'
            aaa=E;
        case 'F'
            aaa=F;
        case 'G'
            aaa=G;
        case 'H'
            aaa=H;
        case 'I'
            aaa=I;
        case 'J'
            aaa=J;
        case 'K'
            aaa=K;
        case 'L'
            aaa=L;
        case 'M'
            aaa=M;
        case 'N'
            aaa=N;
        case 'O'
            aaa=O;
        case 'P'
            aaa=P;
        case 'Q'
            aaa=Q;
        case 'R'
            aaa=R;
        case 'S'
            aaa=S;
        case 'T'
            aaa=T;
        case 'U'
            aaa=U;
        case 'V'
            aaa=V;
        case 'W'
            aaa=W;
        case 'X'
            aaa=X;
        case 'Y'
            aaa=Y;
        case 'Z'
            aaa=Z;
        case '1'
            aaa=n1;
        case '2'
            aaa=n2;
        case '3'
            aaa=n3;
        case '4'
            aaa=n4;
        case '5'
            aaa=n5;
        case '6'
            aaa=n6;
        case '7'
            aaa=n7;
        case '8'
            aaa=n8;
        case '9'
            aaa=n9;
        case '0'
            aaa=n0;
        case '.'
            aaa=mp;
        case ','
            aaa=mc;
        case '?'
            aaa=mq;
        case '!'
            aaa=mb;
        case '-'
            aaa=mh;
        case '/'
            aaa=ms;
        case '@'
            aaa=ma;
        case '('
            aaa=mlc;
        case ')'
            aaa=mrc;
        case 32
            aaa='00';
        otherwise
            aaa='';
    end
    bbb=strcat(bbb,aaa,'00');
end

% bunlen=length(bbb)+length(strfind(bbb,'3'));
bbbNew=strrep(bbb,'3','111');
bunlen=length(bbbNew)+length(strfind(bbbNew,'3'));

fs=20000;
% lmn=2000;
keisu=60/speed*0.1;
t=0:1/fs:bunlen*keisu;
zzz=strfind(bbbNew,'0');
gg=ones(1,length(t));

jjj=strfind(bbbNew,'0');
for i=1:length(jjj)
    gg((jjj(i)-1)*fs*keisu+1:1:jjj(i)*fs*keisu)=0;
end
gg(length(t))=0;


sound(gg.*sin(2*pi*tone*t),fs);



   

Contact us