If the array size is even, the median should be average of its two middlemost elements.

NADA unittests updated accordingly.

BUG=webrtc:4550
R=stefan@webrtc.org

Review URL: https://codereview.webrtc.org/1246083006 .

Cr-Commit-Position: refs/heads/master@{#9607}
This commit is contained in:
Cesar Magalhaes
2015-07-22 11:24:24 +02:00
parent 83d6b0c254
commit 496019c596
2 changed files with 12 additions and 4 deletions

View File

@ -124,12 +124,20 @@ FeedbackPacket* NadaBweReceiver::GetFeedback(int64_t now_ms) {
derivative, RecentKbps(), corrected_send_time_ms);
}
// If size is even, the median is the average of the two middlemost numbers.
int64_t NadaBweReceiver::MedianFilter(int64_t* last_delays_ms, int size) {
// Typically, size = 5.
std::vector<int64_t> array_copy(last_delays_ms, last_delays_ms + size);
std::nth_element(array_copy.begin(), array_copy.begin() + size / 2,
array_copy.end());
return array_copy.at(size / 2);
if (size % 2 == 1) {
// Typically, size = 5. For odd size values, right and left are equal.
return array_copy.at(size / 2);
}
int64_t right = array_copy.at(size / 2);
std::nth_element(array_copy.begin(), array_copy.begin() + (size - 1) / 2,
array_copy.end());
int64_t left = array_copy.at((size - 1) / 2);
return (left + right + 1) / 2;
}
int64_t NadaBweReceiver::ExponentialSmoothingFilter(int64_t new_value,

View File

@ -356,7 +356,7 @@ TEST_F(NadaReceiverSideTest, FeedbackIncreasingDelay) {
// Raw delays are = [10 20 30 40 50 60 70 80] ms.
// Baseline delay will be 50 ms.
// Delay signals should be: [0 10 20 30 40 50 60 70] ms.
const int64_t kMedianFilteredDelaysMs[] = {0, 10, 10, 20, 20, 30, 40, 50};
const int64_t kMedianFilteredDelaysMs[] = {0, 5, 10, 15, 20, 30, 40, 50};
const int kNumPackets = ARRAY_SIZE(kMedianFilteredDelaysMs);
const float kAlpha = 0.1f; // Used for exponential smoothing.
@ -425,7 +425,7 @@ TEST_F(NadaReceiverSideTest, FeedbackWarpedDelay) {
// Baseline delay will be 50 ms.
// Delay signals should be: [0 200 400 600 800 1000 1200 1400] ms.
const int64_t kMedianFilteredDelaysMs[] = {
0, 200, 200, 400, 400, 600, 800, 1000};
0, 100, 200, 300, 400, 600, 800, 1000};
const int kNumPackets = ARRAY_SIZE(kMedianFilteredDelaysMs);
const float kAlpha = 0.1f; // Used for exponential smoothing.