diff options
-rw-r--r-- | Project/RTDSP/.launches/RTDSP.launch | 6 | ||||
-rw-r--r-- | Project/RTDSP/enhance.c | 46 |
2 files changed, 33 insertions, 19 deletions
diff --git a/Project/RTDSP/.launches/RTDSP.launch b/Project/RTDSP/.launches/RTDSP.launch index a54495a..4e7c341 100644 --- a/Project/RTDSP/.launches/RTDSP.launch +++ b/Project/RTDSP/.launches/RTDSP.launch @@ -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:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Mon Mar 05 11:30:19 GMT 2018" time_long="1520249419272"/> <module name="C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Thu Mar 08 12:40:39 GMT 2018" time_long="1520512839256"/> </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 12:40:39 GMT 2018" time_long="1520512839256"/> <module name="C:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out" time="Thu Mar 08 14:26:22 GMT 2018" time_long="1520519182099"/> </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 5f2e1ad..5422bcd 100644 --- a/Project/RTDSP/enhance.c +++ b/Project/RTDSP/enhance.c @@ -97,24 +97,26 @@ complex *fft_out; /* FFT output */ float *noise; float *power_in; float *mag_in; - +float* lpf; 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 = 20; +float alpha = 100; double avg = 0; MVal M[NUM_M]; float K; -float time_constant = 50E-6; /* Time constant in ms */ +static 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(void); /********************************** Main routine ************************************/ void main() { @@ -131,8 +133,8 @@ void main() 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 */ - mag_in = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ - + mag_in = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ + lpf = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */ /* initialize board and the audio port */ init_hardware(); @@ -148,7 +150,7 @@ void main() } ingain=INGAIN; outgain=OUTGAIN; - + for (k = 0; k < NUM_M; ++k) { int i; M[k].pow = (float *) calloc(FFTLEN, sizeof(float)); @@ -157,11 +159,8 @@ void main() } M[k].sum = MAX_FLOAT; } - - // initializing the value to estimate the low pass filter - K = exp(- TFRAME / time_constant); - + K = exp(-TFRAME/time_constant); /* main loop, wait for interrupt */ while(1) process_frame(); } @@ -216,6 +215,7 @@ void write_spectrum(void) { } } +// Noise estimataion void get_noise(void) { float min_sum = M[0].sum; int min_index = 0, k; @@ -229,6 +229,18 @@ void get_noise(void) { noise = M[min_index].pow; } + + +// Low pass filter X(w) +void low_pass_filter(void) { + 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; + } +} /******************************** process_frame() ***********************************/ void process_frame(void) @@ -259,7 +271,7 @@ void process_frame(void) } /************************* 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); @@ -269,9 +281,11 @@ void process_frame(void) fft(FFTLEN, fft_out); // calculate the power spectrum - for (k = 0; i < FFTLEN; ++l) { + for (k = 0; k < FFTLEN; ++k) { power_in[k] = pow(fft_out[k].r, 2) + pow(fft_out[k].i, 2); } + + //low_pass_filter(); // Get average of fft_out and write to Spectrum write_spectrum(); @@ -285,15 +299,15 @@ void process_frame(void) if(++m_ptr == NUM_M) m_ptr = 0; M[m_ptr].sum = 0; for(i = 0; i < FFTLEN; ++i) { - M[m_ptr].pow[i] = power_in[k]; - M[m_ptr].sum += power_in[k]; + M[m_ptr].pow[i] = power_in[i]; + M[m_ptr].sum += power_in[i]; } } // max(lambda, |N(w)/g(w)| for (k = 0; k < FFTLEN; ++k) { float g; - mag_N_X = 1 - alpha * noise[k]/power_in[k]; + mag_N_X = sqrt(1 - alpha * noise[k]/power_in[k]); g = mag_N_X > lambda ? mag_N_X : lambda; fft_out[k] = rmul(g, fft_out[k]); } |