-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathprocess_data.c
98 lines (81 loc) · 2.74 KB
/
process_data.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*-------------------------------------------------------------------------------------------------------
--ECSE 494 Electrical Engineering Design Project
--
--Project Name: Acoustic Echo Cancellation
--
--Authors: Mr Kunal Jathal - kunal.jathal@mail.mcgill.ca,
-- Mr Asrar Rangwala - asrar.rangwala@mail.mcgill.ca
--
--Copyright (C) 2006 Deep Thought
--Version 1.0
--Date Modified: May 9th, 2006
--
--File name: Process_data.c
--
--Software: VisualDSP++3.5
--Hardware: ADSP-BF533 EZ-KIT Board
--
--Purpose: Process the input samples and produce the echo generator and the adaptive lms output.
------------------------------------------------------------------------------------------------------*/
#include "Talkthrough.h"
void echo_generator(void)
{
echo_output = in_fir;
// Produce First echo
echo_output = add_fr1x16(echo_output, multr_fr1x16(0x1000, echo_delayed_input[echo_reader_first]));
// Produce Second echo
echo_output = add_fr1x16(echo_output, multr_fr1x16(0x2000, echo_delayed_input[echo_reader_second]));
// Produce Third echo
echo_output = add_fr1x16(echo_output, multr_fr1x16(0x4000, echo_delayed_input[echo_reader_third]));
echo_delayed_input[echo_writer] = in_fir; //Store the current input in the echo delay buffer
//Increment the echo buffer readers
echo_writer++;
echo_reader_first++;
echo_reader_second++;
echo_reader_third++;
if(echo_writer == echo_TAP_NUM)
{
echo_writer = 0;
}
if(echo_reader_first == echo_TAP_NUM)
{
echo_reader_first = 0;
}
if(echo_reader_second == echo_TAP_NUM)
{
echo_reader_second = 0;
}
if(echo_reader_third == echo_TAP_NUM)
{
echo_reader_third = 0;
}
}
void adaptive_lms(void)
{
// First, produce y_lms.
fir_fr16(pointer, pointer_out, 1, &state); //Call the in-built efficient FIR filter.
// Find the error signal
adder_unit();
// Calculate the step size------------------------------------
// If you do not want to update the step size automatically,
// comment this section of step size calculation between the
// top and bottom comments.
_NLMS_step_updater_sum(sum_int_p, sum_fract_p, &state);
sum = sum_int + fr16_to_float(sum_fract);
meu = 1 / (0.5 + sum); //alpha = 1 and gamma = 0.5.
if(meu>=1)
{
step_size=0x7fff;
}
else
{
step_size = float_to_fr16(meu);
}
//Step size calculation ends----------------------------------
// Lastly, update the filter coefficients
_coeff_updater(error_sig, step_size, &state);
}
void adder_unit(void)
{
error_sig = sub_fr1x16(echo_output, out_fir);
}