aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorunknown <dm2515@eews303a-003.ic.ac.uk>2018-03-08 15:13:45 +0000
committerunknown <dm2515@eews303a-003.ic.ac.uk>2018-03-08 15:13:45 +0000
commitcfbb5c75a314b78bd45ca87506d8513f26ff09e9 (patch)
tree5aa69a429d5738250bad11881c0ab00b7ad988ce
parent35573b7bd425362001e21d020000c8331f3238e7 (diff)
parente0643a05b822bc2b24b2b863df6a2eed3aa97291 (diff)
downloadNoiseSilencer-cfbb5c75a314b78bd45ca87506d8513f26ff09e9.tar.gz
NoiseSilencer-cfbb5c75a314b78bd45ca87506d8513f26ff09e9.zip
[merging]
-rw-r--r--Project/RTDSP/.launches/RTDSP.launch6
-rw-r--r--Project/RTDSP/enhance.c58
2 files changed, 38 insertions, 26 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="&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 12:40:39 GMT 2018&quot; time_long=&quot;1520512839256&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 12:40:39 GMT 2018&quot; time_long=&quot;1520512839256&quot;/&gt;&#13;&#10;&lt;module name=&quot;C:\GIT\RTDSP\Project\RTDSP\Debug\RTDSP.out&quot; time=&quot;Thu Mar 08 14:26:22 GMT 2018&quot; time_long=&quot;1520519182099&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/enhance.c b/Project/RTDSP/enhance.c
index 28bb186..5422bcd 100644
--- a/Project/RTDSP/enhance.c
+++ b/Project/RTDSP/enhance.c
@@ -81,7 +81,7 @@ DSK6713_AIC23_Config Config = { \
};
typedef struct {
- float *mag_spec;
+ float *pow;
float sum;
} MVal;
@@ -94,14 +94,16 @@ 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* P_;
+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;
@@ -130,7 +132,9 @@ void main()
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 */
+ 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();
@@ -139,7 +143,7 @@ void main()
/* initialize algorithm constants */
- for (k=0;k<FFTLEN;++k)
+ for (k=0; k<FFTLEN; ++k)
{
inwin[k] = sqrt((1.0-WINCONST*cos(PI*(2*k+1)/FFTLEN))/OVERSAMP);
outwin[k] = inwin[k];
@@ -149,9 +153,9 @@ void main()
for (k = 0; k < NUM_M; ++k) {
int i;
- M[k].mag_spec = (float *) calloc(FFTLEN, sizeof(float));
+ M[k].pow = (float *) calloc(FFTLEN, sizeof(float));
for(i = 0; i < FFTLEN; ++i) {
- M[k].mag_spec[i] = MAX_FLOAT;
+ M[k].pow[i] = MAX_FLOAT;
}
M[k].sum = MAX_FLOAT;
}
@@ -200,15 +204,13 @@ void init_HWI(void)
// Spectrum calculations for the new values
void write_spectrum(void) {
unsigned int k;
- float x_val;
M[m_ptr].sum = 0;
for(k = 0; k < FFTLEN; ++k) {
- x_val = cabs(fft_out[k]);
- if(x_val < M[m_ptr].mag_spec[k] && x_val != 0) {
- M[m_ptr].mag_spec[k] = x_val;
- M[m_ptr].sum += x_val;
+ if(power_in[k] < M[m_ptr].pow[k] && power_in[k] != 0) {
+ M[m_ptr].pow[k] = power_in[k];
+ M[m_ptr].sum += power_in[k];
} else {
- M[m_ptr].sum += M[m_ptr].mag_spec[k];
+ M[m_ptr].sum += M[m_ptr].pow[k];
}
}
}
@@ -225,13 +227,19 @@ void get_noise(void) {
}
}
- noise = M[min_index].mag_spec;
+ 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() ***********************************/
@@ -272,30 +280,34 @@ void process_frame(void)
// Perform the FFT
fft(FFTLEN, fft_out);
+ // calculate the power spectrum
+ 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();
-
+
// Set the noise
get_noise();
- // alpha*...
if(frame_ctr > MAX_COUNT-1) {
int i;
- float x_val;
frame_ctr = 0;
if(++m_ptr == NUM_M) m_ptr = 0;
M[m_ptr].sum = 0;
for(i = 0; i < FFTLEN; ++i) {
- x_val = cabs(fft_out[i]);
- M[m_ptr].mag_spec[i] = x_val;
- M[m_ptr].sum += x_val;
+ 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]/cabs(fft_out[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]);
}