diff options
author | unknown <dm2515@eews303a-003.ic.ac.uk> | 2018-03-08 17:10:28 +0000 |
---|---|---|
committer | unknown <dm2515@eews303a-003.ic.ac.uk> | 2018-03-08 17:10:28 +0000 |
commit | 2248538707dea4437db32497a518a3a606386a75 (patch) | |
tree | 6697fb88cfa77c0156c16c1db4abbe7c41b3ba73 /Project/RTDSP | |
parent | f6589be8581dfc9b967777bca05c60d478feb796 (diff) | |
download | NoiseSilencer-2248538707dea4437db32497a518a3a606386a75.tar.gz NoiseSilencer-2248538707dea4437db32497a518a3a606386a75.zip |
Optimal variables
Diffstat (limited to 'Project/RTDSP')
-rw-r--r-- | Project/RTDSP/.launches/RTDSP.launch | 8 | ||||
-rw-r--r-- | Project/RTDSP/enhance.c | 57 |
2 files changed, 48 insertions, 17 deletions
diff --git a/Project/RTDSP/.launches/RTDSP.launch b/Project/RTDSP/.launches/RTDSP.launch index 5a533d8..486fa5b 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="<?xml version="1.0" encoding="UTF-8"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;&#13;&#10;&lt;default/&gt;&#13;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/> -<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="<?xml version="1.0" encoding="UTF-8"?> <memoryBlockExpressionList/> "/> -<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="<?xml version="1.0" encoding="UTF-8"?> <modules> <module name="C:\GIT\RTDSP\lab3\RTDSP\Debug\RTDSP.out" time="Fri Jan 19 14:07:28 GMT 2018" time_long="1516370848357"/> <module name="C:\Github\RTDSP\lab3\RTDSP\Debug\RTDSP.out" time="Tue Jan 23 11:15:11 GMT 2018" time_long="1516706111426"/> <module name="C:\GIT\RTDSP\lab4\RTDSP\Debug\RTDSP.out" time="Thu Feb 01 11:44:21 GMT 2018" time_long="1517485461898"/> <module name="C:\github\RTDSP\lab4\RTDSP\Debug\RTDSP.out" time="Thu Feb 15 13:55:55 GMT 2018" time_long="1518702955359"/> <module name="C:\Github\RTDSP\lab5\RTDSP\Debug\RTDSP.out" time="Tue Feb 27 12:18:55 GMT 2018" time_long="1519733935329"/> <module name="C:\github\RTDSP\lab5\RTDSP\Debug\RTDSP.out" time="Thu Mar 01 13:36:20 GMT 2018" time_long="1519911380476"/> <module name="C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Thu Mar 08 15:31:06 GMT 2018" time_long="1520523066763"/> <module name="C:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Thu Mar 08 15:45:03 GMT 2018" time_long="1520523903840"/> </modules> "/> +<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="<?xml version="1.0" encoding="UTF-8"?> <modules> <module name="C:\GIT\RTDSP\lab3\RTDSP\Debug\RTDSP.out" time="Fri Jan 19 14:07:28 GMT 2018" time_long="1516370848357"/> <module name="C:\Github\RTDSP\lab3\RTDSP\Debug\RTDSP.out" time="Tue Jan 23 11:15:11 GMT 2018" time_long="1516706111426"/> <module name="C:\GIT\RTDSP\lab4\RTDSP\Debug\RTDSP.out" time="Thu Feb 01 11:44:21 GMT 2018" time_long="1517485461898"/> <module name="C:\github\RTDSP\lab4\RTDSP\Debug\RTDSP.out" time="Thu Feb 15 13:55:55 GMT 2018" time_long="1518702955359"/> <module name="C:\Github\RTDSP\lab5\RTDSP\Debug\RTDSP.out" time="Tue Feb 27 12:18:55 GMT 2018" time_long="1519733935329"/> <module name="C:\github\RTDSP\lab5\RTDSP\Debug\RTDSP.out" time="Thu Mar 01 13:36:20 GMT 2018" time_long="1519911380476"/> <module name="C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Thu Mar 08 15:31:06 GMT 2018" time_long="1520523066763"/> <module name="C:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Thu Mar 08 17:03:11 GMT 2018" time_long="1520528591515"/> </modules> "/> <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="<?xml version="1.0" encoding="UTF-8"?> <globalVariableList/> "/> @@ -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/enhance.c b/Project/RTDSP/enhance.c index 45a0060..771f873 100644 --- a/Project/RTDSP/enhance.c +++ b/Project/RTDSP/enhance.c @@ -55,6 +55,7 @@ #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 */ @@ -93,17 +94,19 @@ float *noise; float *power_in; float *mag_in; float* lpf; +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 lambda = 0.05; -float alpha = 100; +float alpha[NUM_ALPHA] = {1000, 600, 400, 400}; double avg = 0; float *M[NUM_M]; float mag_N_X; float K; -static float time_constant = 40e-3; /* Time constant in ms */ +float time_constant = 40e-3; /* Time constant in ms */ int started = 0; /******************************* Function prototypes *******************************/ void init_hardware(void); /* Initialize codec */ @@ -112,7 +115,8 @@ 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(void); +void low_pass_filter(float* current, float* next); +void overestimation(void); /********************************** Main routine ************************************/ void main() { @@ -130,9 +134,10 @@ void main() fft_out = (complex *) calloc(FFTLEN, sizeof(complex)); /* FFT Output */ power_in = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ lpf = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ - mag_in = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ - noise = (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 */ /* initialize board and the audio port */ init_hardware(); @@ -218,19 +223,44 @@ void get_noise(void) { min_i = i; } } - noise[k] = alpha * M[min_i][k]; + noise[k] = M[min_i][k]; } + + overestimation(); } + +void overestimation(void) { + int i; + float sum; + + // Calcualte |signal^2/noise^2| for all k + for (i = 0; i < FFTLEN; ++i) { + SNR[i] = power_in[i] / noise[i]; + sum += SNR[i]; + } + + // Calculate average + sum /= FFTLEN; + + // 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(void) { +void low_pass_filter(float* current, float* next) { int w; float temp; for (w = 0; w < FFTLEN; ++w) { - temp = power_in[w]; - power_in[w] = (1-K)*power_in[w] + K*lpf[w]; - lpf[w] = temp; + temp = current[w]; + current[w] = (1-K)*current[w] + K*next[w]; + next[w] = temp; } } @@ -273,10 +303,11 @@ void process_frame(void) // calculate the power spectrum for (k = 0; k < FFTLEN; ++k) { - power_in[k] = sqrt(fft_out[k].r * fft_out[k].r + fft_out[k].i * fft_out[k].i); + power_in[k] = fft_out[k].r * fft_out[k].r + fft_out[k].i * fft_out[k].i; } - //low_pass_filter(); + low_pass_filter(power_in, lpf); + low_pass_filter(noise, prev_noise); // Get average of fft_out and write to Spectrum write_spectrum(); |