aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYann Herklotz <ymherklotz@gmail.com>2018-03-18 20:46:13 +0000
committerGitHub <noreply@github.com>2018-03-18 20:46:13 +0000
commitf860d0c5bb890b4e73c2d2dc76bbb0d4258e0007 (patch)
tree4177cf0c50d898856dd106ed88ab6f9fd01d3502
parent8cdda67f13ccf90e60033a630dcd8f5b4079d7b9 (diff)
parent8cafd3deee9e424857c361362352f563367489eb (diff)
downloadNoiseSilencer-f860d0c5bb890b4e73c2d2dc76bbb0d4258e0007.tar.gz
NoiseSilencer-f860d0c5bb890b4e73c2d2dc76bbb0d4258e0007.zip
Merge pull request #2 from dan12n/project
Merging working project into master
-rw-r--r--Project/RTDSP/.launches/RTDSP.launch8
-rw-r--r--Project/RTDSP/Images/car.jpgbin0 -> 34424 bytes
-rw-r--r--Project/RTDSP/Images/car_best_case.jpgbin0 -> 37068 bytes
-rw-r--r--Project/RTDSP/Images/clean_spec.jpgbin0 -> 38874 bytes
-rw-r--r--Project/RTDSP/Images/intermediate.PNGbin0 -> 34246 bytes
-rw-r--r--Project/RTDSP/Images/mag.PNGbin0 -> 13991 bytes
-rw-r--r--Project/RTDSP/Matlab/create_spectrogram.m19
-rw-r--r--Project/RTDSP/audio/best_case/car.wavbin0 -> 3145806 bytes
-rw-r--r--Project/RTDSP/audio/best_case/car.wmabin0 -> 229479 bytes
-rw-r--r--Project/RTDSP/audio/best_case/lynx2.wavbin0 -> 4251726 bytes
-rw-r--r--Project/RTDSP/audio/best_case/lynx2.wmabin0 -> 310299 bytes
-rw-r--r--Project/RTDSP/audio/best_case/phantom2.wavbin0 -> 4251726 bytes
-rw-r--r--Project/RTDSP/audio/best_case/phantom2.wmabin0 -> 305809 bytes
-rw-r--r--Project/RTDSP/audio/best_case/phantom4.wavbin0 -> 3629134 bytes
-rw-r--r--Project/RTDSP/audio/best_case/phantom4.wmabin0 -> 265399 bytes
-rw-r--r--Project/RTDSP/audio/original/car1.wavbin0 -> 888028 bytes
-rw-r--r--Project/RTDSP/audio/original/clean.wavbin0 -> 882116 bytes
-rw-r--r--Project/RTDSP/audio/original/factory1.wavbin0 -> 888184 bytes
-rw-r--r--Project/RTDSP/audio/original/factory2.wavbin0 -> 888184 bytes
-rw-r--r--Project/RTDSP/audio/original/lynx1.wavbin0 -> 890254 bytes
-rw-r--r--Project/RTDSP/audio/original/lynx2.wavbin0 -> 890254 bytes
-rw-r--r--Project/RTDSP/audio/original/phantom1.wavbin0 -> 886504 bytes
-rw-r--r--Project/RTDSP/audio/original/phantom2.wavbin0 -> 886504 bytes
-rw-r--r--Project/RTDSP/audio/original/phantom4.wavbin0 -> 886504 bytes
-rw-r--r--Project/RTDSP/audio/original/signals.txt17
-rw-r--r--Project/RTDSP/audio/without_optimisations/car.wmabin0 -> 265399 bytes
-rw-r--r--Project/RTDSP/audio/without_optimisations/factory2.wmabin0 -> 265399 bytes
-rw-r--r--Project/RTDSP/audio/without_optimisations/lynx2.wmabin0 -> 260909 bytes
-rw-r--r--Project/RTDSP/audio/without_optimisations/phantom4.wmabin0 -> 265399 bytes
-rw-r--r--Project/RTDSP/enhance.c389
-rw-r--r--Project/RTDSP/frame.c207
-rw-r--r--Project/TestCode/dft.c64
32 files changed, 493 insertions, 211 deletions
diff --git a/Project/RTDSP/.launches/RTDSP.launch b/Project/RTDSP/.launches/RTDSP.launch
index 4e69bfc..8830bf8 100644
--- a/Project/RTDSP/.launches/RTDSP.launch
+++ b/Project/RTDSP/.launches/RTDSP.launch
@@ -1,8 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<launchConfiguration type="com.ti.ccstudio.debug.core.CCELaunchType">
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;sourceLookupDirector&gt;&#13;&#10;&lt;sourceContainers duplicates=&quot;false&quot;&gt;&#13;&#10;&lt;container memento=&quot;&amp;lt;?xml version=&amp;quot;1.0&amp;quot; encoding=&amp;quot;UTF-8&amp;quot;?&amp;gt;&amp;#13;&amp;#10;&amp;lt;default/&amp;gt;&amp;#13;&amp;#10;&quot; typeId=&quot;org.eclipse.debug.core.containerType.default&quot;/&gt;&#13;&#10;&lt;/sourceContainers&gt;&#13;&#10;&lt;/sourceLookupDirector&gt;&#13;&#10;"/>
-<booleanAttribute key="com.ti.ccstudio.debug.core.MRU_PROGRAM_S_ONLY" value="false"/>
<booleanAttribute key="org.eclipse.debug.ui.ATTR_LAUNCH_IN_BACKGROUND" value="false"/>
+<booleanAttribute key="com.ti.ccstudio.debug.core.MRU_PROGRAM_S_ONLY" value="false"/>
<stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_ID" value="com.ti.ccstudio.debug.core.CCEDebugger"/>
<stringAttribute key="CCEDebugOptions.CPU_RESOLVE_OPTION" value="exact"/>
<stringAttribute key="org.eclipse.debug.ui.DISPLAY_NAME" value="RTDSP [Debug] - Spectrum Digital DSK-EVM-eZdsp onboard USB Emulator_0/TMS320C671X"/>
@@ -12,8 +12,8 @@
<stringAttribute key="com.ti.ccstudio.debug.core.DISPLAY_NAME_FORMAT" value="RTDSP [Debug] - {0}"/>
<stringAttribute key="CCEDebugOptions.TARGET_CONFIGURATION_OPTION" value="full"/>
<stringAttribute key="org.eclipse.cdt.launch.MEMORY_BLOCKS" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;memoryBlockExpressionList/&gt;&#13;&#10;"/>
-<stringAttribute key="com.ti.ccstudio.debug.core.MRU_PROGRAM_NAME" value="C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out"/>
-<stringAttribute key="com.ti.ccstudio.debug.core.MRU_MODULES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;modules&gt;&#13;&#10;&lt;module name=&quot;C:\GIT\RTDSP\lab3\RTDSP\Debug\RTDSP.out&quot; time=&quot;Fri Jan 19 14:07:28 GMT 2018&quot; time_long=&quot;1516370848357&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\Github\RTDSP\lab3\RTDSP\Debug\RTDSP.out&quot; time=&quot;Tue Jan 23 11:15:11 GMT 2018&quot; time_long=&quot;1516706111426&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\GIT\RTDSP\lab4\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Feb 01 11:44:21 GMT 2018&quot; time_long=&quot;1517485461898&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\lab4\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Feb 15 13:55:55 GMT 2018&quot; time_long=&quot;1518702955359&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\Github\RTDSP\lab5\RTDSP\Debug\RTDSP.out&quot; time=&quot;Tue Feb 27 12:18:55 GMT 2018&quot; time_long=&quot;1519733935329&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\lab5\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Mar 01 13:36:20 GMT 2018&quot; time_long=&quot;1519911380476&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Mon Mar 05 10:28:49 GMT 2018&quot; time_long=&quot;1520245729915&quot;/&gt;&#13;&#10;&lt;/modules&gt;&#13;&#10;"/>
+<stringAttribute key="com.ti.ccstudio.debug.core.MRU_PROGRAM_NAME" value="C:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out"/>
+<stringAttribute key="com.ti.ccstudio.debug.core.MRU_MODULES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;modules&gt;&#13;&#10;&lt;module name=&quot;C:\GIT\RTDSP\lab3\RTDSP\Debug\RTDSP.out&quot; time=&quot;Fri Jan 19 14:07:28 GMT 2018&quot; time_long=&quot;1516370848357&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\Github\RTDSP\lab3\RTDSP\Debug\RTDSP.out&quot; time=&quot;Tue Jan 23 11:15:11 GMT 2018&quot; time_long=&quot;1516706111426&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\GIT\RTDSP\lab4\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Feb 01 11:44:21 GMT 2018&quot; time_long=&quot;1517485461898&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\lab4\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Feb 15 13:55:55 GMT 2018&quot; time_long=&quot;1518702955359&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\Github\RTDSP\lab5\RTDSP\Debug\RTDSP.out&quot; time=&quot;Tue Feb 27 12:18:55 GMT 2018&quot; time_long=&quot;1519733935329&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\lab5\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Mar 01 13:36:20 GMT 2018&quot; time_long=&quot;1519911380476&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Mar 08 15:31:06 GMT 2018&quot; time_long=&quot;1520523066763&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Mar 15 16:05:05 GMT 2018&quot; time_long=&quot;1521129905593&quot;/&gt;&#13;&#10;&lt;/modules&gt;&#13;&#10;"/>
<stringAttribute key="CCEDebugOptions.CPU_NAME" value="Spectrum Digital DSK-EVM-eZdsp onboard USB Emulator_0/TMS320C671X"/>
<stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="RTDSP"/>
<stringAttribute key="org.eclipse.cdt.launch.GLOBAL_VARIABLES" value="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;globalVariableList/&gt;&#13;&#10;"/>
@@ -21,6 +21,6 @@
<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="Debug/RTDSP.out"/>
<stringAttribute key="CCEDebugOptions.CPU_ISA" value="TMS320C671X"/>
<stringAttribute key="com.ti.ccstudio.debug.core.BUILD_CONFIGURATION" value="Debug"/>
-<stringAttribute key="CCEDebugOptions.TARGET_CONFIGURATION_FILE" value="C:\github\RTDSP\Project\RTDSP\NewTargetConfiguration.ccxml"/>
+<stringAttribute key="CCEDebugOptions.TARGET_CONFIGURATION_FILE" value="C:\GIT\RTDSP\Project\RTDSP\NewTargetConfiguration.ccxml"/>
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="com.ti.ccstudio.debug.core.sourceLocator"/>
</launchConfiguration>
diff --git a/Project/RTDSP/Images/car.jpg b/Project/RTDSP/Images/car.jpg
new file mode 100644
index 0000000..a07535d
--- /dev/null
+++ b/Project/RTDSP/Images/car.jpg
Binary files differ
diff --git a/Project/RTDSP/Images/car_best_case.jpg b/Project/RTDSP/Images/car_best_case.jpg
new file mode 100644
index 0000000..2b6ccb3
--- /dev/null
+++ b/Project/RTDSP/Images/car_best_case.jpg
Binary files differ
diff --git a/Project/RTDSP/Images/clean_spec.jpg b/Project/RTDSP/Images/clean_spec.jpg
new file mode 100644
index 0000000..feb54db
--- /dev/null
+++ b/Project/RTDSP/Images/clean_spec.jpg
Binary files differ
diff --git a/Project/RTDSP/Images/intermediate.PNG b/Project/RTDSP/Images/intermediate.PNG
new file mode 100644
index 0000000..67610eb
--- /dev/null
+++ b/Project/RTDSP/Images/intermediate.PNG
Binary files differ
diff --git a/Project/RTDSP/Images/mag.PNG b/Project/RTDSP/Images/mag.PNG
new file mode 100644
index 0000000..36e8d28
--- /dev/null
+++ b/Project/RTDSP/Images/mag.PNG
Binary files differ
diff --git a/Project/RTDSP/Matlab/create_spectrogram.m b/Project/RTDSP/Matlab/create_spectrogram.m
new file mode 100644
index 0000000..5bf2661
--- /dev/null
+++ b/Project/RTDSP/Matlab/create_spectrogram.m
@@ -0,0 +1,19 @@
+%%
+% Creates the spectrogram for the audio files
+
+[song, fs] = audioread('../audio/best_case/car.wav');
+song = song(1:fs*10);
+figure
+spectrogram(song, 256, [], [], fs, 'yaxis');
+
+%%
+[song, fs] = audioread('../audio/original/car1.wav');
+song = song(1:fs*10);
+figure
+spectrogram(song, 256, [], [], fs, 'yaxis');
+
+%%
+[song, fs] = audioread('../audio/original/clean.wav');
+song = song(1:fs*10);
+figure
+spectrogram(song, 256, [], [], fs, 'yaxis');
diff --git a/Project/RTDSP/audio/best_case/car.wav b/Project/RTDSP/audio/best_case/car.wav
new file mode 100644
index 0000000..7b3a194
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/car.wav
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/car.wma b/Project/RTDSP/audio/best_case/car.wma
new file mode 100644
index 0000000..30c3302
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/car.wma
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/lynx2.wav b/Project/RTDSP/audio/best_case/lynx2.wav
new file mode 100644
index 0000000..3cb2341
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/lynx2.wav
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/lynx2.wma b/Project/RTDSP/audio/best_case/lynx2.wma
new file mode 100644
index 0000000..1966d2d
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/lynx2.wma
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/phantom2.wav b/Project/RTDSP/audio/best_case/phantom2.wav
new file mode 100644
index 0000000..048155c
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/phantom2.wav
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/phantom2.wma b/Project/RTDSP/audio/best_case/phantom2.wma
new file mode 100644
index 0000000..733c5e2
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/phantom2.wma
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/phantom4.wav b/Project/RTDSP/audio/best_case/phantom4.wav
new file mode 100644
index 0000000..ab52539
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/phantom4.wav
Binary files differ
diff --git a/Project/RTDSP/audio/best_case/phantom4.wma b/Project/RTDSP/audio/best_case/phantom4.wma
new file mode 100644
index 0000000..5a7aa75
--- /dev/null
+++ b/Project/RTDSP/audio/best_case/phantom4.wma
Binary files differ
diff --git a/Project/RTDSP/audio/original/car1.wav b/Project/RTDSP/audio/original/car1.wav
new file mode 100644
index 0000000..4d64c03
--- /dev/null
+++ b/Project/RTDSP/audio/original/car1.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/clean.wav b/Project/RTDSP/audio/original/clean.wav
new file mode 100644
index 0000000..0a76159
--- /dev/null
+++ b/Project/RTDSP/audio/original/clean.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/factory1.wav b/Project/RTDSP/audio/original/factory1.wav
new file mode 100644
index 0000000..6486e33
--- /dev/null
+++ b/Project/RTDSP/audio/original/factory1.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/factory2.wav b/Project/RTDSP/audio/original/factory2.wav
new file mode 100644
index 0000000..e563084
--- /dev/null
+++ b/Project/RTDSP/audio/original/factory2.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/lynx1.wav b/Project/RTDSP/audio/original/lynx1.wav
new file mode 100644
index 0000000..cb59ce9
--- /dev/null
+++ b/Project/RTDSP/audio/original/lynx1.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/lynx2.wav b/Project/RTDSP/audio/original/lynx2.wav
new file mode 100644
index 0000000..e25915b
--- /dev/null
+++ b/Project/RTDSP/audio/original/lynx2.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/phantom1.wav b/Project/RTDSP/audio/original/phantom1.wav
new file mode 100644
index 0000000..4a0637e
--- /dev/null
+++ b/Project/RTDSP/audio/original/phantom1.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/phantom2.wav b/Project/RTDSP/audio/original/phantom2.wav
new file mode 100644
index 0000000..5ebf511
--- /dev/null
+++ b/Project/RTDSP/audio/original/phantom2.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/phantom4.wav b/Project/RTDSP/audio/original/phantom4.wav
new file mode 100644
index 0000000..893615b
--- /dev/null
+++ b/Project/RTDSP/audio/original/phantom4.wav
Binary files differ
diff --git a/Project/RTDSP/audio/original/signals.txt b/Project/RTDSP/audio/original/signals.txt
new file mode 100644
index 0000000..fc1f488
--- /dev/null
+++ b/Project/RTDSP/audio/original/signals.txt
@@ -0,0 +1,17 @@
+Speech files for testing noise cancellation
+
+clean.wav A 40-second passage concerning sailors. All other files
+ have noise added to this passage. The final digit of the
+ file names indicates the noise amplitude.
+
+car1.wav Car noise
+
+factory1.wav Factory Noise at two sound levels
+factory2.wav
+
+lynx1.wav A lynx helicopter
+lynx2.wav
+
+phantom1.wav An F15 fighter aircraft
+phantom2.wav
+phantom4.wav
diff --git a/Project/RTDSP/audio/without_optimisations/car.wma b/Project/RTDSP/audio/without_optimisations/car.wma
new file mode 100644
index 0000000..9412a9a
--- /dev/null
+++ b/Project/RTDSP/audio/without_optimisations/car.wma
Binary files differ
diff --git a/Project/RTDSP/audio/without_optimisations/factory2.wma b/Project/RTDSP/audio/without_optimisations/factory2.wma
new file mode 100644
index 0000000..ddfa200
--- /dev/null
+++ b/Project/RTDSP/audio/without_optimisations/factory2.wma
Binary files differ
diff --git a/Project/RTDSP/audio/without_optimisations/lynx2.wma b/Project/RTDSP/audio/without_optimisations/lynx2.wma
new file mode 100644
index 0000000..9d8bf0e
--- /dev/null
+++ b/Project/RTDSP/audio/without_optimisations/lynx2.wma
Binary files differ
diff --git a/Project/RTDSP/audio/without_optimisations/phantom4.wma b/Project/RTDSP/audio/without_optimisations/phantom4.wma
new file mode 100644
index 0000000..5e22805
--- /dev/null
+++ b/Project/RTDSP/audio/without_optimisations/phantom4.wma
Binary files differ
diff --git a/Project/RTDSP/enhance.c b/Project/RTDSP/enhance.c
new file mode 100644
index 0000000..09b78d6
--- /dev/null
+++ b/Project/RTDSP/enhance.c
@@ -0,0 +1,389 @@
+/*************************************************************************************
+ DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING
+ IMPERIAL COLLEGE LONDON
+
+ EE 3.19: Real Time Digital Signal Processing
+ Dr Paul Mitcheson and Daniel Harvey
+
+ PROJECT: Frame Processing
+
+ ********* ENHANCE. C **********
+ Shell for speech enhancement
+
+ Demonstrates overlap-add frame processing (interrupt driven) on the DSK.
+
+ *************************************************************************************
+ By Danny Harvey: 21 July 2006
+ Updated for use on CCS v4 Sept 2010
+ ************************************************************************************/
+/*
+ * You should modify the code so that a speech enhancement project is built
+ * on top of this template.
+ */
+/**************************** Pre-processor statements ******************************/
+// library required when using calloc
+#include <stdlib.h>
+// Included so program can make use of DSP/BIOS configuration tool.
+#include "dsp_bios_cfg.h"
+
+/* The file dsk6713.h must be included in every program that uses the BSL. This
+ example also includes dsk6713_aic23.h because it uses the
+ AIC23 codec module (audio interface). */
+#include "dsk6713.h"
+#include "dsk6713_aic23.h"
+
+// math library (trig functions)
+#include <math.h>
+
+/* Some functions to help with Complex algebra and FFT. */
+#include "cmplx.h"
+#include "fft_functions.h"
+
+// Some functions to help with writing/reading the audio ports when using interrupts.
+#include <helper_functions_ISR.h>
+
+#define WINCONST 0.85185 /* 0.46/0.54 for Hamming window */
+#define FSAMP 8000.0 /* sample frequency, ensure this matches Config for AIC */
+#define FFTLEN 256 /* fft length = frame length 256/8000 = 32 ms*/
+#define NFREQ (1+FFTLEN/2) /* number of frequency bins from a real FFT */
+#define OVERSAMP 4 /* oversampling ratio (2 or 4) */
+#define FRAMEINC (FFTLEN/OVERSAMP) /* Frame increment */
+#define CIRCBUF (FFTLEN+FRAMEINC) /* length of I/O buffers */
+#define FRAME_TIME 2.5
+#define MAX_COUNT 20000
+#define MAX_FLOAT 3.4E+38
+#define OUTGAIN 16000.0 /* Output gain for DAC */
+#define INGAIN (1.0/16000.0) /* Input gain for ADC */
+#define NUM_M 4
+#define NUM_ALPHA 4
+// PI defined here for use in your code
+#define PI 3.141592653589793
+#define TFRAME FRAMEINC/FSAMP /* time between calculation of each frame */
+
+/******************************* Global declarations ********************************/
+
+/* Audio port configuration settings: these values set registers in the AIC23 audio
+ interface to configure it. See TI doc SLWS106D 3-3 to 3-10 for more info. */
+DSK6713_AIC23_Config Config = { \
+ /**********************************************************************/
+ /* REGISTER FUNCTION SETTINGS */
+ /**********************************************************************/\
+ 0x0017, /* 0 LEFTINVOL Left line input channel volume 0dB */\
+ 0x0017, /* 1 RIGHTINVOL Right line input channel volume 0dB */\
+ 0x01f9, /* 2 LEFTHPVOL Left channel headphone volume 0dB */\
+ 0x01f9, /* 3 RIGHTHPVOL Right channel headphone volume 0dB */\
+ 0x0011, /* 4 ANAPATH Analog audio path control DAC on, Mic boost 20dB*/\
+ 0x0000, /* 5 DIGPATH Digital audio path control All Filters off */\
+ 0x0000, /* 6 DPOWERDOWN Power down control All Hardware on */\
+ 0x0043, /* 7 DIGIF Digital audio interface format 16 bit */\
+ 0x008d, /* 8 SAMPLERATE Sample rate control 8 KHZ-ensure matches FSAMP */\
+ 0x0001 /* 9 DIGACT Digital interface activation On */\
+ /**********************************************************************/
+};
+
+// Codec handle:- a variable used to identify audio interface
+DSK6713_AIC23_CodecHandle H_Codec;
+
+float *inbuffer, *outbuffer; /* Input/output circular buffers */
+float *inframe, *outframe; /* Input and output frames */
+float *inwin, *outwin; /* Input and output windows */
+float ingain, outgain; /* ADC and DAC gains */
+float cpufrac; /* Fraction of CPU time used */
+complex *fft_out; /* FFT output */
+float *noise;
+float *power_in;
+float *mag_in;
+float* p_w;
+float* prev_noise;
+float* SNR;
+volatile int io_ptr=0; /* Input/ouput pointer for circular buffers */
+volatile int frame_ptr=0; /* Frame pointer */
+volatile int frame_ctr = 0;
+volatile int m_ptr = 0;
+float snr_val = 0;
+float total_snr = 0;
+float lambda = 0.05;
+float alpha[NUM_ALPHA] = {300, 400, 600, 1000};
+float avg = 0;
+float sum = 0;
+float *M[NUM_M];
+float mag_N_X;
+float K;
+float time_constant = 40e-3; /* Time constant in ms */
+int started = 0;
+ /******************************* Function prototypes *******************************/
+void init_hardware(void); /* Initialize codec */
+void init_HWI(void); /* Initialize hardware interrupts */
+void ISR_AIC(void); /* Interrupt service routine for codec */
+void process_frame(void); /* Frame processing routine */
+void write_spectrum(void);
+void get_noise(void);
+void low_pass_filter(float* current, float* next);
+void overestimation(void);
+/********************************** Main routine ************************************/
+void main()
+{
+
+ int k; // used in various for loops
+ int counter = 1;
+/* Initialize and zero fill arrays */
+
+ inbuffer = (float *) calloc(CIRCBUF, sizeof(float)); /* Input array */
+ outbuffer = (float *) calloc(CIRCBUF, sizeof(float)); /* Output array */
+ inframe = (float *) calloc(FFTLEN, sizeof(float)); /* Array for processing*/
+ outframe = (float *) calloc(FFTLEN, sizeof(float)); /* Array for processing*/
+ inwin = (float *) calloc(FFTLEN, sizeof(float)); /* Input window */
+ outwin = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ fft_out = (complex *) calloc(FFTLEN, sizeof(complex)); /* FFT Output */
+ power_in = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ p_w = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ mag_in = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ noise = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ prev_noise = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ SNR = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
+ for(k = 0; k < FFTLEN; ++k) {
+ SNR[k] = 0;
+ }
+ /* initialize board and the audio port */
+ init_hardware();
+
+ /* initialize hardware interrupts */
+ init_HWI();
+
+/* initialize algorithm constants */
+
+ for (k=0; k<FFTLEN; ++k)
+ {
+ inwin[k] = sqrt((1.0-WINCONST*cos(PI*(2*k+1)/FFTLEN))/OVERSAMP);
+ outwin[k] = inwin[k];
+ }
+ ingain=INGAIN;
+ outgain=OUTGAIN;
+
+ for (k = 0; k < NUM_M; ++k) {
+ M[k] = (float *) calloc(FFTLEN, sizeof(float));
+ }
+
+ K = exp(-TFRAME/time_constant);
+ /* main loop, wait for interrupt */
+ while(1) {
+ process_frame();
+ counter++;
+ snr_val = total_snr / counter;
+ }
+}
+
+/********************************** init_hardware() *********************************/
+void init_hardware()
+{
+ // Initialize the board support library, must be called first
+ DSK6713_init();
+
+ // Start the AIC23 codec using the settings defined above in config
+ H_Codec = DSK6713_AIC23_openCodec(0, &Config);
+
+ /* Function below sets the number of bits in word used by MSBSP (serial port) for
+ receives from AIC23 (audio port). We are using a 32 bit packet containing two
+ 16 bit numbers hence 32BIT is set for receive */
+ MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
+
+ /* Configures interrupt to activate on each consecutive available 32 bits
+ from Audio port hence an interrupt is generated for each L & R sample pair */
+ MCBSP_FSETS(SPCR1, RINTM, FRM);
+
+ /* These commands do the same thing as above but applied to data transfers to the
+ audio port */
+ MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);
+ MCBSP_FSETS(SPCR1, XINTM, FRM);
+
+
+}
+/********************************** init_HWI() **************************************/
+void init_HWI(void)
+{
+ IRQ_globalDisable(); // Globally disables interrupts
+ IRQ_nmiEnable(); // Enables the NMI interrupt (used by the debugger)
+ IRQ_map(IRQ_EVT_RINT1,4); // Maps an event to a physical interrupt
+ IRQ_enable(IRQ_EVT_RINT1); // Enables the event
+ IRQ_globalEnable(); // Globally enables interrupts
+
+}
+
+// Spectrum calculations for the new values
+void write_spectrum(void) {
+ unsigned int k;
+ for(k = 0; k < FFTLEN; ++k) {
+ if(power_in[k] < M[m_ptr][k] || M[m_ptr][k] == 0) {
+ M[m_ptr][k] = power_in[k];
+ }
+ }
+}
+
+// Noise estimataion
+void get_noise(void) {
+ int k, i, min_i;
+ float min_val;
+
+ for(k = 0; k < FFTLEN; ++k) {
+ min_i = 0;
+ min_val = M[0][k];
+ for(i = 1; i < NUM_M; ++i) {
+ if (M[i][k] < min_val && M[i][k]!= 0) {
+ min_val = M[i][k];
+ min_i = i;
+ }
+ }
+ noise[k] = M[min_i][k];
+ }
+
+ overestimation();
+}
+
+
+
+void overestimation(void) {
+ int i;
+ sum = 0;
+ // Calcualte |signal^2/noise^2| for all k
+ for (i = 0; i < FFTLEN; ++i) {
+ if(noise[i] != 0) {
+ SNR[i] = power_in[i] / noise[i];
+ sum += SNR[i];
+ }
+ }
+
+ // Calculate average
+ sum /= FFTLEN;
+ total_snr += sum;
+ // Use SNRs to divide
+ for (i = 0; i < FFTLEN; ++i) {
+ // Normalising
+ SNR[i] /= 2*sum;
+ SNR[i] = SNR[i] > 1 ? 1 : SNR[i];
+ noise[i] *= alpha[(int)(SNR[i] * (NUM_ALPHA-1))];
+ }
+}
+
+// Low pass filter X(w)
+void low_pass_filter(float* current, float* next) {
+ int w;
+ float temp;
+ for (w = 0; w < FFTLEN; ++w) {
+ current[w] = (1-K)*current[w] + K*next[w];
+ next[w] = current[w];
+ }
+}
+
+/******************************** process_frame() ***********************************/
+void process_frame(void)
+{
+ int k, m;
+ int io_ptr0;
+ /* work out fraction of available CPU time used by algorithm */
+ cpufrac = ((float) (io_ptr & (FRAMEINC - 1)))/FRAMEINC;
+
+ /* wait until io_ptr is at the start of the current frame */
+ while((io_ptr/FRAMEINC) != frame_ptr);
+
+ /* then increment the framecount (wrapping if required) */
+ if (++frame_ptr >= (CIRCBUF/FRAMEINC)) frame_ptr=0;
+
+ /* save a pointer to the position in the I/O buffers (inbuffer/outbuffer) where the
+ data should be read (inbuffer) and saved (outbuffer) for the purpose of processing */
+ io_ptr0=frame_ptr * FRAMEINC;
+
+ /* copy input data from inbuffer into inframe (starting from the pointer position) */
+
+ m=io_ptr0;
+ for (k=0;k<FFTLEN;k++)
+ {
+ inframe[k] = inbuffer[m] * inwin[k];
+ if (++m >= CIRCBUF) m=0; /* wrap if required */
+ }
+
+ /************************* DO PROCESSING OF FRAME HERE **************************/
+
+ // Initialise the array fft_out for FFT
+ for (k = 0; k < FFTLEN; ++k) {
+ fft_out[k] = cmplx(inframe[k], 0.0);
+ }
+
+ // Perform the FFT
+ fft(FFTLEN, fft_out);
+
+ // calculate the power spectrum
+ for (k = 0; k < FFTLEN; ++k) {
+ power_in[k] = fft_out[k].r * fft_out[k].r + fft_out[k].i * fft_out[k].i;
+ }
+
+ low_pass_filter(power_in, p_w);
+ low_pass_filter(noise, prev_noise);
+
+ // Get average of fft_out and write to Spectrum
+ write_spectrum();
+
+ // Set the noise
+ get_noise();
+
+ if(frame_ctr > MAX_COUNT-1) {
+ int i;
+ frame_ctr = 0;
+ if(++m_ptr == NUM_M) m_ptr = 0;
+ for(i = 0; i < FFTLEN; ++i) {
+ M[m_ptr][i] = power_in[i];
+ }
+ }
+
+ // max(lambda, |N(w)/g(w)|
+ for (k = 0; k < FFTLEN; ++k) {
+ float g;
+ mag_N_X = sqrt(1 - noise[k]/power_in[k]);
+ g = mag_N_X > lambda ? mag_N_X : lambda;
+ fft_out[k] = rmul(g, fft_out[k]);
+ }
+
+ // Back into time domain
+ ifft(FFTLEN, fft_out);
+
+ for (k = 0; k < FFTLEN; ++k) {
+ outframe[k] = fft_out[k].r;
+ }
+ /********************************************************************************/
+
+ /* multiply outframe by output window and overlap-add into output buffer */
+
+ m=io_ptr0;
+
+ for (k=0;k<(FFTLEN-FRAMEINC);k++)
+ { /* this loop adds into outbuffer */
+ outbuffer[m] = outbuffer[m]+outframe[k]*outwin[k];
+ if (++m >= CIRCBUF) m=0; /* wrap if required */
+ }
+
+ for (;k<FFTLEN;k++)
+ {
+ outbuffer[m] = outframe[k]*outwin[k]; /* this loop over-writes outbuffer */
+ m++;
+ }
+}
+/*************************** INTERRUPT SERVICE ROUTINE *****************************/
+
+// Map this to the appropriate interrupt in the CDB file
+
+void ISR_AIC(void)
+{
+ short sample;
+ /* Read and write the ADC and DAC using inbuffer and outbuffer */
+ sample = mono_read_16Bit();
+ inbuffer[io_ptr] = ((float)sample)*ingain;
+ /* write new output data */
+ mono_write_16Bit((int)(outbuffer[io_ptr]*outgain));
+
+ /* update io_ptr and check for buffer wraparound */
+
+ if (++io_ptr >= CIRCBUF) io_ptr=0;
+ frame_ctr++;
+ started = 1;
+}
+
+/************************************************************************************/
diff --git a/Project/RTDSP/frame.c b/Project/RTDSP/frame.c
deleted file mode 100644
index a8fd350..0000000
--- a/Project/RTDSP/frame.c
+++ /dev/null
@@ -1,207 +0,0 @@
-/*************************************************************************************
- DEPARTMENT OF ELECTRICAL AND ELECTRONIC ENGINEERING
- IMPERIAL COLLEGE LONDON
-
- EE 3.19: Real Time Digital Signal Processing
- Dr Paul Mitcheson and Daniel Harvey
-
- LAB 6: Frame Processing
-
- ********* F R A M E. C **********
-
- Demonstrates Frame Processing (Interrupt driven) on the DSK.
-
- *************************************************************************************
- Updated for use on 6713 DSK by Danny Harvey: May-Aug 2006
- Updated for ccsV4 Sept 2010
- ************************************************************************************/
-/*
- * You should modify the code so that an FFT is applied to an input frame
- * which is then IFFT'd and sent to the audio port.
- */
-/**************************** Pre-processor statements ******************************/
-
-// Included so program can make use of DSP/BIOS configuration tool.
-#include <stdlib.h>
-#include "dsp_bios_cfg.h"
-
-/* The file dsk6713.h must be included in every program that uses the BSL. This
- example also includes dsk6713_aic23.h because it uses the
- AIC23 codec module (audio interface). */
-#include "dsk6713.h"
-#include "dsk6713_aic23.h"
-
-// math library (trig functions)
-#include <math.h>
-
-/* Some functions to help with Complex algebra and FFT. */
-#include "cmplx.h"
-#include "fft_functions.h"
-
-// Some functions to help with writing/reading the audio ports when using interrupts.
-#include <helper_functions_ISR.h>
-
-
-
-/******************************* Global declarations ********************************/
-
-/* Audio port configuration settings: these values set registers in the AIC23 audio
- interface to configure it. See TI doc SLWS106D 3-3 to 3-10 for more info. */
-DSK6713_AIC23_Config Config = { \
- /**********************************************************************/
- /* REGISTER FUNCTION SETTINGS */
- /**********************************************************************/\
- 0x0017, /* 0 LEFTINVOL Left line input channel volume 0dB */\
- 0x0017, /* 1 RIGHTINVOL Right line input channel volume 0dB */\
- 0x01f9, /* 2 LEFTHPVOL Left channel headphone volume 0dB */\
- 0x01f9, /* 3 RIGHTHPVOL Right channel headphone volume 0dB */\
- 0x0011, /* 4 ANAPATH Analog audio path control DAC on, Mic boost 20dB*/\
- 0x0000, /* 5 DIGPATH Digital audio path control All Filters off */\
- 0x0000, /* 6 DPOWERDOWN Power down control All Hardware on */\
- 0x0043, /* 7 DIGIF Digital audio interface format 16 bit */\
- 0x008d, /* 8 SAMPLERATE Sample rate control 8 KHZ */\
- 0x0001 /* 9 DIGACT Digital interface activation On */\
- /**********************************************************************/
-};
-
-// Codec handle:- a variable used to identify audio interface
-DSK6713_AIC23_CodecHandle H_Codec;
-
-// PI defined here for use in your code
-#define PI 3.141592653589793
-
-#define BUFLEN 128 /* Frame buffer length must be even for real fft */
-
-
-/* Pointers to data buffers */
-float *input;
-float *intermediate;
-float *output;
-volatile int index = 0;
-
-
- /******************************* Function prototypes *******************************/
-void init_hardware(void);
-void init_HWI(void);
-void ISR_AIC(void);
-void init_arrays(void);
-void wait_buffer(void);
-
-/********************************** Main routine ************************************/
-void main()
-{
-
- /* setup arrays */
- init_arrays();
-
- /* initialize board and the audio port */
- init_hardware();
-
- /* initialize hardware interrupts */
- init_HWI();
-
-
- /* loop indefinitely, waiting for interrupts */
- while(1)
- {
- wait_buffer();
- };
-
-}
-
-
-
-/********************************** init_hardware() *********************************/
-void init_hardware()
-{
- // Initialize the board support library, must be called first
- DSK6713_init();
-
- // Start the AIC23 codec using the settings defined above in config
- H_Codec = DSK6713_AIC23_openCodec(0, &Config);
-
- /* Function below sets the number of bits in word used by MSBSP (serial port) for
- receives from AIC23 (audio port). We are using a 32 bit packet containing two
- 16 bit numbers hence 32BIT is set for receive */
- MCBSP_FSETS(RCR1, RWDLEN1, 32BIT);
-
- /* Configures interrupt to activate on each consecutive available 32 bits
- from Audio port hence an interrupt is generated for each L & R sample pair */
- MCBSP_FSETS(SPCR1, RINTM, FRM);
-
- /* These commands do the same thing as above but applied to data transfers to
- the audio port */
- MCBSP_FSETS(XCR1, XWDLEN1, 32BIT);
- MCBSP_FSETS(SPCR1, XINTM, FRM);
-
-
-}
-/********************************** init_HWI() **************************************/
-void init_HWI(void)
-{
- IRQ_globalDisable(); // Globally disables interrupts
- IRQ_nmiEnable(); // Enables the NMI interrupt (used by the debugger)
- IRQ_map(IRQ_EVT_RINT1,4); // Maps an event to a physical interrupt
- IRQ_enable(IRQ_EVT_RINT1); // Enables the event
- IRQ_globalEnable(); // Globally enables interrupts
-
-}
-/************************** Allocate memory for arrays *******************************/
-void init_arrays(void)
-{
- input = (float *) calloc(BUFLEN, sizeof(float)); /* Input array */
- output = (float *) calloc(BUFLEN, sizeof(float)); /* Output array */
- intermediate = (float *) calloc(BUFLEN, sizeof(float)); /* Array for processing*/
-}
-
-/*************************** INTERRUPT SERVICE ROUTINE ******************************/
-
-// Map this to the appropriate interrupt in the DSP BIOS
-
-void ISR_AIC(void)
-{
- short sample;
- float scale = 11585;
-
- sample = mono_read_16Bit();
-
- /* add new data to input buffer
- and scale so that 1v ~= 1.0 */
- input[index] = ((float)sample)/scale;
-
- /* write new output data */
- mono_write_16Bit((short)(output[index]*scale));
-
- /* update index and check for full buffer */
- if (++index == BUFLEN)
- index=0;
-}
-
-/******************* Wait for buffer of data to be input/output **********************/
-void wait_buffer(void)
-{
- float *p;
-
- /* wait for array index to be set to zero by ISR */
- while(index);
-
- /* rotate data arrays */
- p = input;
- input = output;
- output = intermediate;
- intermediate = p;
-
- /************************* DO PROCESSING OF FRAME HERE **************************/
-
-
- /*please add your code */
-
-
- /**********************************************************************************/
-
- /* wait here in case next sample has not yet been read in */
- while(!index);
-}
-
-
-
diff --git a/Project/TestCode/dft.c b/Project/TestCode/dft.c
new file mode 100644
index 0000000..e82cb3e
--- /dev/null
+++ b/Project/TestCode/dft.c
@@ -0,0 +1,64 @@
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#define E_PI 3.1415926535897932384626433832795028841971693993751058209749445923078164062
+#define N_DEF 8
+
+typedef struct {
+ float r;
+ float i;
+} Complex;
+
+float x[] = {0, 0, 2, 3, 4, 0, 0, 0};
+
+void dft(int N, Complex *X) {
+ int i, n, k;
+ Complex *x = malloc(N * sizeof(X[0]));
+ for(i = 0; i < N; ++i) {
+ x[i] = X[i];
+ }
+ for(k = 0; k < N; ++k) {
+ X[k].r = 0.f;
+ X[k].i = 0.f;
+ for(n = 0; n < N; ++n) {
+ X[k].r += x[n].r * cos(2 * E_PI * k * n / N);
+ X[k].i -= x[n].r * sin(2 * E_PI * k * n / N);
+ }
+ }
+ free(x);
+}
+
+void idft(int N, Complex *X) {
+ int i, n, k;
+ Complex *x = malloc(N * sizeof(X[0]));
+ for(i = 0; i < N; ++i) {
+ x[i] = X[i];
+ }
+ for(n = 0; n < N; ++n) {
+ X[n].i = 0.f;
+ X[n].r = 0.f;
+ for(k = 0; k < N; ++k) {
+ X[n].r += x[k].r * cos(2 * E_PI * k * n / N) - x[k].i * sin(2 * E_PI * k * n / N);
+ }
+ X[n].r /= N;
+ }
+ free(x);
+}
+
+int main() {
+ int k;
+ Complex X_C[8];
+ for(k = 0; k < N_DEF; ++k) {
+ X_C[k].r = x[k];
+ X_C[k].i = 0;
+ }
+ dft(N_DEF, X_C);
+ for(k = 0; k < N_DEF; ++k) {
+ printf("x[%d] = %.2f, X[%d] = %.2f + %.2fi\n", k, x[k], k, X_C[k].r, X_C[k].i);
+ }
+ idft(N_DEF, X_C);
+ for(k = 0; k < N_DEF; ++k) {
+ printf("x[%d] = %.2f, X[%d] = %.2f + %.2fi\n", k, x[k], k, X_C[k].r, X_C[k].i);
+ }
+}