2016-06-28 47 views
1

我需要的大小爲N的一個維數組轉換爲尺寸A的二維陣列* B> N。讓我們採取這樣的情況下:轉換1-d陣列2-d陣列重疊

int oneDimensionalArray[6] = {7, 8, 10, 11, 12, 15}; 
//then the second array would be 
int twoDimensionalArray[2][4] = {{7, 8, 10, 11}, 
           {10, 11, 12, 15}}; 

這用於數字聲音處理中使用的所謂疊加方法。我曾嘗試這種做法賦予不當的結果:

for(unsigned long i = 0; i < amountOfWindows; i++) 
    { 
     for(unsigned long j = hopSize; j < windowLength; j++) 
     { 
      //buffer without the overlapping 
      if((i * amountOfWindows + j) >= bufferLength) 
       break; 

      windowedBuffer[i][j] = unwindowedBuffer[i * amountOfWindows + j]; 
     } 
    } 

    for(unsigned long i = 1; i < amountOfWindows; i++) 
    { 
     for(unsigned long j = 0; j < hopSize; j++) 
     { 
      // Filling the overlapping region 
      windowedBuffer[i][j] = windowedBuffer[i-1][windowLength - hopSize + i]; 
     } 
    } 

我也試着尋找使用模運算的關係,但我不能找到合適的人。這是我試過的一個:

windowedBuffer[m][n % (windowLength - hopSize)] = unwindowedBuffer[n]; 
+0

而'j + 2 * i'? – Jarod42

+0

你是什麼意思?那是什麼2? – Kokos34

+0

你的重疊是'2'。 – Jarod42

回答

1

既然你已經知道了hopSize(從您的評論),你想要的是簡單的:

for (size_t i = 0; i < amountOfWindows; ++i) { 
    for (size_t j = 0; j < windowLength; ++j) { 
     windowedBuffer[i][j] = unwindowedBuffer[i * hopSize + j]; 
    } 
} 

amountOfWindowswindowLengthhopSize你參數(在你的例子中分別是2,4和2)。