aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorymherklotz <ymherklotz@gmail.com>2018-03-08 15:32:54 +0000
committerymherklotz <ymherklotz@gmail.com>2018-03-08 15:32:54 +0000
commitf511b9c433e0ff7bf71b0213473555818bacc85e (patch)
tree38868f8debe4101e587a05cd1eda760d00ab9f98
parent90683eeefb0386d07c57faa0d9ce5b416acc0d62 (diff)
downloadNoiseSilencer-f511b9c433e0ff7bf71b0213473555818bacc85e.tar.gz
NoiseSilencer-f511b9c433e0ff7bf71b0213473555818bacc85e.zip
Fixed noise
-rw-r--r--Project/RTDSP/.launches/RTDSP.launch2
-rw-r--r--Project/RTDSP/enhance.c61
2 files changed, 24 insertions, 39 deletions
diff --git a/Project/RTDSP/.launches/RTDSP.launch b/Project/RTDSP/.launches/RTDSP.launch
index fe8b6e4..490010d 100644
--- a/Project/RTDSP/.launches/RTDSP.launch
+++ b/Project/RTDSP/.launches/RTDSP.launch
@@ -13,7 +13,7 @@
<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:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Mon Mar 05 11:30:19 GMT 2018&quot; time_long=&quot;1520249419272&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\github\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Mar 08 15:05:35 GMT 2018&quot; time_long=&quot;1520521535037&quot;/&gt;&#13;&#10;&lt;/modules&gt;&#13;&#10;"/>
+<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:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Mon Mar 05 11:30:19 GMT 2018&quot; time_long=&quot;1520249419272&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;/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;"/>
diff --git a/Project/RTDSP/enhance.c b/Project/RTDSP/enhance.c
index 728194c..e77a82c 100644
--- a/Project/RTDSP/enhance.c
+++ b/Project/RTDSP/enhance.c
@@ -80,11 +80,6 @@ DSK6713_AIC23_Config Config = { \
/**********************************************************************/
};
-typedef struct {
- float *pow;
- float sum;
-} MVal;
-
// Codec handle:- a variable used to identify audio interface
DSK6713_AIC23_CodecHandle H_Codec;
@@ -103,9 +98,9 @@ volatile int frame_ptr=0; /* Frame pointer */
volatile int frame_ctr = 0;
volatile int m_ptr = 0;
float lambda = 0.05;
-float alpha = 400;
+float alpha = 20;
double avg = 0;
-MVal M[NUM_M];
+float *M[NUM_M];
float mag_N_X;
float K;
float time_constant = 50E-6; /* Time constant in ms */
@@ -133,6 +128,7 @@ void main()
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 */
+ noise = (float *) calloc(FFTLEN, sizeof(float)); /* Output window */
/* initialize board and the audio port */
init_hardware();
@@ -149,10 +145,9 @@ void main()
}
ingain=INGAIN;
outgain=OUTGAIN;
-
+
for (k = 0; k < NUM_M; ++k) {
- M[k].pow = (float *) calloc(FFTLEN, sizeof(float));
- M[k].sum = 0;
+ M[k] = (float *) calloc(FFTLEN, sizeof(float));
}
// initializing the value to estimate the low pass filter
@@ -202,36 +197,28 @@ void init_HWI(void)
// Spectrum calculations for the new values
void write_spectrum(void) {
unsigned int k;
- if(M[m_ptr].sum == 0) {
- for(k = 0; k < FFTLEN; ++k) {
- M[m_ptr].pow[k] = power_in[k];
- M[m_ptr].sum += power_in[k];
- }
- } else {
- M[m_ptr].sum = 0;
- for(k = 0; k < FFTLEN; ++k) {
- if(power_in[k] < M[m_ptr].pow[k]) {
- M[m_ptr].pow[k] = power_in[k];
- M[m_ptr].sum += power_in[k];
- } else {
- M[m_ptr].sum += M[m_ptr].pow[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];
}
}
}
void get_noise(void) {
- float min_sum = M[0].sum;
- int min_index = 0, k;
-
- for(k = 1; k < NUM_M; ++k) {
- if (M[k].sum < min_sum && M[k].sum != 0) {
- min_sum = M[k].sum;
- min_index = k;
+ 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] = alpha * M[min_i][k];
}
-
- noise = M[min_index].pow;
}
/******************************** process_frame() ***********************************/
@@ -273,7 +260,7 @@ void process_frame(void)
// 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;
+ power_in[k] = sqrt(fft_out[k].r * fft_out[k].r + fft_out[k].i * fft_out[k].i);
}
// Get average of fft_out and write to Spectrum
@@ -286,17 +273,15 @@ void process_frame(void)
int i;
frame_ctr = 0;
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[i];
- M[m_ptr].sum += power_in[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 - alpha * noise[k]/power_in[k]);
+ mag_N_X = 1 - noise[k]/power_in[k];
g = mag_N_X > lambda ? mag_N_X : lambda;
fft_out[k] = rmul(g, fft_out[k]);
}