Assume that I have a vector:

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14]

What I need to do is split this vector into block sizes of blocksize with an overlap

blocksize = 4

overlap = 2

The result, would be a 2D vector with size 4 containing 6 values.

x[0] = [1, 3, 5, 7, 9, 11]

x[1] = [ 2 4 6 8 10 12]

....

I have tried to implement this with the following functions:

std::vector<std::vector<double> > stride_windows(std::vector<double> &data, std::size_t 
NFFT, std::size_t overlap)
{
    std::vector<std::vector<double> > blocks(NFFT);   

    for(unsigned i=0; (i < data.size()); i++)
    {
        blocks[i].resize(NFFT+overlap);
        for(unsigned j=0; (j < blocks[i].size()); j++)
        {
            std::cout << data[i*overlap+j] << std::endl;
        }
    }
}

This is wrong, and, segments.

std::vector<std::vector<double> > frame(std::vector<double> &signal, int N, int M)
{
         unsigned int n = signal.size();
         unsigned int num_blocks = n / N;


         unsigned int maxblockstart = n - N;
         unsigned int lastblockstart = maxblockstart - (maxblockstart % M);
         unsigned int numbblocks = (lastblockstart)/M + 1;

         std::vector<std::vector<double> > blocked(numbblocks);

         for(unsigned i=0; (i < numbblocks); i++)
         {
                 blocked[i].resize(N);

             for(int j=0; (j < N); j++)
            {
                blocked[i][j] = signal[i*M+j];
            }
        }

         return blocked;
}

I wrote this function, thinking that it did the above, however, it will just store:

X[0] = 1, 2, 3, 4

x[1] = 3, 4, 5, 6

.....

Could anyone please explain how I would go about modifying the above function to allow for skips by overlap to take place?

I think it would help us to understand the problem if you showed what x[2] and [x3] should look like. From your sample, I don't see the pattern the problem is supposed to create.

This article has been dead for over six months. Start a new discussion instead.