Added morse.m and addnoise.m - these are Octave scripts to generate noisy morse code

master
Mauri Niininen 2014-08-29 17:20:46 -04:00
rodzic f1873ce0fb
commit 3ea8052a4b
5 zmienionych plików z 276 dodań i 26 usunięć

Wyświetl plik

@ -131,12 +131,12 @@ distuninstallcheck_listfiles = find . -type f -print
am__distuninstallcheck_listfiles = $(distuninstallcheck_listfiles) \
| sed 's|^\./|$(prefix)/|' | grep -v '$(infodir)/dir$$'
distcleancheck_listfiles = find . -type f -print
ACLOCAL = ${SHELL} /home/mauri/Projects/morse-wip/missing --run aclocal-1.11
ACLOCAL = aclocal-1.11
AMTAR = $${TAR-tar}
AM_DEFAULT_VERBOSITY = 0
AUTOCONF = ${SHELL} /home/mauri/Projects/morse-wip/missing --run autoconf
AUTOHEADER = ${SHELL} /home/mauri/Projects/morse-wip/missing --run autoheader
AUTOMAKE = ${SHELL} /home/mauri/Projects/morse-wip/missing --run automake-1.11
AUTOCONF = autoconf
AUTOHEADER = autoheader
AUTOMAKE = automake-1.11
AWK = gawk
BMORSE_AUTHORS =
CC = gcc
@ -177,7 +177,7 @@ LIBOBJS =
LIBS = -lm -lsndfile -lfftw3
LTLIBOBJS =
MAINT = #
MAKEINFO = ${SHELL} /home/mauri/Projects/morse-wip/missing --run makeinfo
MAKEINFO = makeinfo
MKDIR_P = /bin/mkdir -p
OBJEXT = o
PACKAGE = bmorse

Wyświetl plik

@ -4,5 +4,17 @@ This software is a Morse decoder orinally created by Dr. E. L. Bell in 1977.
The software was manually entered from Fortran program listings and later converted to C++
by AG1LE Mauri Niininen.
DEPENDENCIES:
- libsndfile1-dev -- used to open WAV sound files
- fftw3-dev -- used for FFT calculation
- tcl -- used for running cer vs snr testing
- sqlite3 -- used to store test results in SQL database
- libsqlite3-tcl -- used by tcl to call sqlite3
install dependencies by
sudo apt-get install libsndfile1-dev fftw3-dev
sudo apt-get install tcl
sudo apt-get install sqlite3
sudo apt-get install libsqlite3-tcl

Wyświetl plik

@ -11,10 +11,10 @@ generated by GNU Autoconf 2.69. Invocation command line was
## --------- ##
hostname = X301
uname -m = i686
uname -r = 3.8.0-26-generic
uname -m = x86_64
uname -r = 3.13.0-24-generic
uname -s = Linux
uname -v = #38-Ubuntu SMP Mon Jun 17 21:46:08 UTC 2013
uname -v = #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014
/usr/bin/uname -p = unknown
/bin/uname -X = unknown
@ -27,7 +27,6 @@ uname -v = #38-Ubuntu SMP Mon Jun 17 21:46:08 UTC 2013
/usr/bin/oslevel = unknown
/bin/universe = unknown
PATH: /usr/lib/i386-linux-gnu/qt4/bin
PATH: /usr/local/sbin
PATH: /usr/local/bin
PATH: /usr/sbin
@ -46,6 +45,7 @@ configure:2143: checking for a BSD-compatible install
configure:2211: result: /usr/bin/install -c
configure:2222: checking whether build environment is sane
configure:2272: result: yes
configure:2300: WARNING: `missing' script is too old or missing
configure:2413: checking for a thread-safe mkdir -p
configure:2452: result: /bin/mkdir -p
configure:2465: checking for gawk
@ -62,8 +62,8 @@ configure:2864: found /usr/bin/g++
configure:2875: result: g++
configure:2902: checking for C++ compiler version
configure:2911: g++ --version >&5
g++ (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
g++ (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -71,11 +71,11 @@ configure:2922: $? = 0
configure:2911: g++ -v >&5
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --enable-targets=all --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
configure:2922: $? = 0
configure:2911: g++ -V >&5
g++: error: unrecognized command line option '-V'
@ -126,8 +126,8 @@ configure:3680: found /usr/bin/gcc
configure:3691: result: gcc
configure:3920: checking for C compiler version
configure:3929: gcc --version >&5
gcc (Ubuntu/Linaro 4.7.3-1ubuntu1) 4.7.3
Copyright (C) 2012 Free Software Foundation, Inc.
gcc (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Copyright (C) 2013 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -135,11 +135,11 @@ configure:3940: $? = 0
configure:3929: gcc -v >&5
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i686-linux-gnu/4.7/lto-wrapper
Target: i686-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.7.3-1ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs --enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.7 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --enable-objc-gc --enable-targets=all --with-cloog --enable-cloog-backend=ppl --disable-cloog-version-check --disable-ppl-version-check --enable-multiarch --disable-werror --with-arch-32=i686 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=i686-linux-gnu --host=i686-linux-gnu --target=i686-linux-gnu
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu 4.8.2-19ubuntu1' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --disable-libmudflap --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.7.3 (Ubuntu/Linaro 4.7.3-1ubuntu1)
gcc version 4.8.2 (Ubuntu 4.8.2-19ubuntu1)
configure:3940: $? = 0
configure:3929: gcc -V >&5
gcc: error: unrecognized command line option '-V'
@ -172,6 +172,8 @@ configure:4448: gcc -E conftest.c
configure:4448: $? = 0
configure:4462: gcc -E conftest.c
conftest.c:19:28: fatal error: ac_nonexistent.h: No such file or directory
#include <ac_nonexistent.h>
^
compilation terminated.
configure:4462: $? = 1
configure: failed program was:
@ -199,6 +201,8 @@ configure:4507: gcc -E conftest.c
configure:4507: $? = 0
configure:4521: gcc -E conftest.c
conftest.c:19:28: fatal error: ac_nonexistent.h: No such file or directory
#include <ac_nonexistent.h>
^
compilation terminated.
configure:4521: $? = 1
configure: failed program was:
@ -272,6 +276,8 @@ configure:4797: result: yes
configure:4810: checking minix/config.h usability
configure:4810: gcc -c -g -O2 conftest.c >&5
conftest.c:62:26: fatal error: minix/config.h: No such file or directory
#include <minix/config.h>
^
compilation terminated.
configure:4810: $? = 1
configure: failed program was:
@ -341,6 +347,8 @@ configure:4810: result: no
configure:4810: checking minix/config.h presence
configure:4810: gcc -E conftest.c
conftest.c:29:26: fatal error: minix/config.h: No such file or directory
#include <minix/config.h>
^
compilation terminated.
configure:4810: $? = 1
configure: failed program was:
@ -466,7 +474,7 @@ am_cv_make_support_nested_variables=yes
## Output variables. ##
## ----------------- ##
ACLOCAL='${SHELL} /home/mauri/Projects/morse-wip/missing --run aclocal-1.11'
ACLOCAL='aclocal-1.11'
AMDEPBACKSLASH='\'
AMDEP_FALSE='#'
AMDEP_TRUE=''
@ -475,9 +483,9 @@ AM_BACKSLASH='\'
AM_DEFAULT_V='$(AM_DEFAULT_VERBOSITY)'
AM_DEFAULT_VERBOSITY='0'
AM_V='$(V)'
AUTOCONF='${SHELL} /home/mauri/Projects/morse-wip/missing --run autoconf'
AUTOHEADER='${SHELL} /home/mauri/Projects/morse-wip/missing --run autoheader'
AUTOMAKE='${SHELL} /home/mauri/Projects/morse-wip/missing --run automake-1.11'
AUTOCONF='autoconf'
AUTOHEADER='autoheader'
AUTOMAKE='automake-1.11'
AWK='gawk'
BMORSE_AUTHORS=''
CC='gcc'
@ -508,7 +516,7 @@ LTLIBOBJS=''
MAINT='#'
MAINTAINER_MODE_FALSE=''
MAINTAINER_MODE_TRUE='#'
MAKEINFO='${SHELL} /home/mauri/Projects/morse-wip/missing --run makeinfo'
MAKEINFO='makeinfo'
MKDIR_P='/bin/mkdir -p'
OBJEXT='o'
PACKAGE='bmorse'

76
test/addnoise.m 100644
Wyświetl plik

@ -0,0 +1,76 @@
function [ noisy, noise ] = addnoise( signal, noise, snr )
% ADDNOISE Add noise to signal at a prescribed SNR level.
%
% [NOISY,NOISE]=ADDNOISE(SIGNAL,NOISE,SNR) adds NOISE to SIGNAL
% at a prescribed SNR level. Returns the mixture signal as well
% as scaled noise such that NOISY=SIGNAL+NOISE.
%
% Inputs
% SIGNAL is a target signal as vector.
%
% NOISE is a masker signal as vector, such that
% length(NOISE)>=length(SIGNAL). Note that
% in the case that length(NOISE)>length(SIGNAL),
% a vector of length length(SIGNAL) is selected
% from NOISE starting at a random sample number.
%
% SNR is the desired signal-to-noise ratio level (dB).
%
% Outputs
% NOISY is a mixture signal of SIGNAL and NOISE at given SNR.
%
% NOISE is a scaled masker signal, such that the mixture
% NOISY=SIGNAL+NOISE has the desired SNR.
%
% Example
% % inline function for SNR calculation
% SNR = @(signal,noisy)( 20*log10(norm(signal)/norm(signal-noisy)) );
%
% fs = 16000; % sampling frequency (Hz)
% freq = 1000; % sinusoid frequency (Hz)
% time = [ 0:1/fs:2 ]; % time vector (s)
% signal = sin( 2*pi*freq*time ); % signal vector (s)
% noise = randn( size(signal) ); % noise vector (s)
% snr = -5; % desired SNR level (dB)
%
% % generate mixture signal: noisy = signal + noise
% [ noisy, noise ] = addnoise( signal, noise, snr );
%
% % check the resulting signal-to-noise ratio
% fprintf( 'SNR: %0.2f dB\n', SNR(signal,noisy) );
%
% See also TEST_ADDNOISE_SINUSOID, TEST_ADDNOISE_SPEECH.
% Author: Kamil Wojcicki, UTD, July 2011
% inline function for SNR calculation
SNR = @(signal,noisy)( 20*log10(norm(signal)/norm(signal-noisy)) );
% needed for older realases of MATLAB
randi = @(n)( round(1+(n-1)*rand) );
% ensure masker is at least as long as the target
S = length( signal );
N = length( noise );
if( S>N ), error( 'Error: length(signal)>length(noise)' ); end;
% generate a random start location in the masker signal
R = randi(1+N-S);
% extract random section of the masker signal
noise = noise(R:R+S-1);
% scale the masker w.r.t. to target at a desired SNR level
noise = noise / norm(noise) * norm(signal) / 10.0^(0.05*snr);
% generate the mixture signal
noisy = signal + noise;
% plot(signal,noisy,noise);
% sanity check
%assert( abs(SNR(signal,noisy)-snr) < 1E10*eps(snr) );
%%% EOF

154
test/morse.m 100644
Wyświetl plik

@ -0,0 +1,154 @@
function code=morse(varargin)
% MORSE converts text to playable morse code in wav format
%
% SYNTAX
% morse(text)
% morse(text,file_name);
% morse(text,file_name,snr);
% morse(text, file_name,snr,code_frequency);
% morse(text, file_name,snr,code_frequency,sample_rate);
% morse(text, file_name,snr,code_frequency,sample_rate, code_speed_wpm, zero_fill_to_N);
% morse(text, file_name,snr,code_frequency,sample_rate, code_speed_wpm, zero_fill_to_N, play_sound);
%
% Description:
%
% If the wave file name is specified, then the funtion will output a wav
% file with that file name. If only text is specified, then the function
% will only play the morse code wav file without saving it to a wav file.
% If a snr is specified, zero mean addative white Gaussian
% noise is added
%
% Examples:
%
% morse('Hello');
% morse('How are you doing my friend?','morsecode.wav');
% morse('How are you doing my friend?','morsecode.wav', 20);
% morse('How are you doing my friend?','morsecode.wav', 10, 440,Fs,20);
% x = morse('How are you doing my friend?','morsecode.wav', 3, 440,Fs, 20, 2^20,1); %(to play the file, and make the length 2^20)
%
% Copyright 2005 Fahad Al Mahmood
% Version: 1.1 $ $Date: 08-Jul-2010
% Modifications: Rob Frohne, KL7NA
% Modofications: Mauri Niininen, AG1LE
%Defualt values
Fs=48000;
snr = 20;
f_code = 375;
code_speed = 20;
text = varargin{1}
if nargin>=2
file = varargin{2}
end
if nargin>=3
snr = varargin{3};
end
if nargin>=4
f_code = varargin{4};
end
if nargin>=5
Fs = varargin{5};
end
if nargin>=6
code_speed = varargin{6};
end
if nargin>=7
length_N = varargin{7};
end
if nargin>=8
playsound = varargin{8};
end
t=0:1/Fs:1.2/code_speed; %One dit of time at w wpm is 1.2/w.
t=t';
Dit = sin(2*pi*f_code*t);
ssp = zeros(size(Dit));
#Dah fixed by Zach Swena
t2=0:1/Fs:3*1.2/code_speed; # one Dah of time is 3 times dit time
t2=t2';
Dah = sin(2*pi*f_code*t2);
lsp = zeros(size(Dah)); # changed size argument to function of Dah
#Dah = [Dit;Dit;Dit];
#lsp = zeros(size([Dit;Dit;Dit]));
% Defining Characters & Numbers
A = [Dit;ssp;Dah];
B = [Dah;ssp;Dit;ssp;Dit;ssp;Dit];
C = [Dah;ssp;Dit;ssp;Dah;ssp;Dit];
D = [Dah;ssp;Dit;ssp;Dit];
E = [Dit];
F = [Dit;ssp;Dit;ssp;Dah;ssp;Dit];
G = [Dah;ssp;Dah;ssp;Dit];
H = [Dit;ssp;Dit;ssp;Dit;ssp;Dit];
I = [Dit;ssp;Dit];
J = [Dit;ssp;Dah;ssp;Dah;ssp;Dah];
K = [Dah;ssp;Dit;ssp;Dah];
L = [Dit;ssp;Dah;ssp;Dit;ssp;Dit];
M = [Dah;ssp;Dah];
N = [Dah;ssp;Dit];
O = [Dah;ssp;Dah;ssp;Dah];
P = [Dit;ssp;Dah;ssp;Dah;ssp;Dit];
Q = [Dah;ssp;Dah;ssp;Dit;ssp;Dah];
R = [Dit;ssp;Dah;ssp;Dit];
S = [Dit;ssp;Dit;ssp;Dit];
T = [Dah];
U = [Dit;ssp;Dit;ssp;Dah];
V = [Dit;ssp;Dit;ssp;Dit;ssp;Dah];
W = [Dit;ssp;Dah;ssp;Dah];
X = [Dah;ssp;Dit;ssp;Dit;ssp;Dah];
Y = [Dah;ssp;Dit;ssp;Dah;ssp;Dah];
Z = [Dah;ssp;Dah;ssp;Dit;ssp;Dit];
period = [Dit;ssp;Dah;ssp;Dit;ssp;Dah;ssp;Dit;ssp;Dah];
comma = [Dah;ssp;Dah;ssp;Dit;ssp;Dit;ssp;Dah;ssp;Dah];
question = [Dit;ssp;Dit;ssp;Dah;ssp;Dah;ssp;Dit;ssp;Dit];
slash_ = [Dah;ssp;Dit;ssp;Dit;ssp;Dah;ssp;Dit];
n1 = [Dit;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dah];
n2 = [Dit;ssp;Dit;ssp;Dah;ssp;Dah;ssp;Dah];
n3 = [Dit;ssp;Dit;ssp;Dit;ssp;Dah;ssp;Dah];
n4 = [Dit;ssp;Dit;ssp;Dit;ssp;Dit;ssp;Dah];
n5 = [Dit;ssp;Dit;ssp;Dit;ssp;Dit;ssp;Dit];
n6 = [Dah;ssp;Dit;ssp;Dit;ssp;Dit;ssp;Dit];
n7 = [Dah;ssp;Dah;ssp;Dit;ssp;Dit;ssp;Dit];
n8 = [Dah;ssp;Dah;ssp;Dah;ssp;Dit;ssp;Dit];
n9 = [Dah;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dit];
n0 = [Dah;ssp;Dah;ssp;Dah;ssp;Dah;ssp;Dah];
text = upper(text);
vars ={'period','comma','question','slash_'};
morsecode=[];
for i=1:length(text)
if isvarname(text(i))
morsecode = [morsecode;eval(text(i))];
elseif ismember(text(i),'.,?/')
x = findstr(text(i),'.,?/');
morsecode = [morsecode;eval(vars{x})];
elseif ~isempty(str2num(text(i)))
morsecode = [morsecode;eval(['n' text(i)])];
elseif text(i)==' '
morsecode = [morsecode;ssp;ssp;ssp;ssp];
end
morsecode = [morsecode;lsp];
end
if exist('length_N','var')
append_length = length_N - length(morsecode);
if (append_length < 0)
printf("Length %d isn't large enough for your message; it must be > %d.\n",length_N,length(morsecode));
return;
else
morsecode = [morsecode; zeros(append_length,1)];
end
end
noise = randn(size(morsecode) );
[noisy,noise] = addnoise(morsecode,noise,snr);
SNR =20*log10(norm(morsecode)/norm(noise)) %(morsecode-noisy));
printf('SNR =%f dB\n',SNR);
if exist('file','var')
wavwrite(noisy,Fs,16,file);
if exist('playsound')
system(['aplay ',file]);
end
else
soundsc(noisy,Fs);
% wavplay(morsecode);
end
code = noisy;
endfunction