Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.
7039 Discussions

What is the proper way to zero-pad a 2d data and perform backward transformation?

raavi
Novice
303 Views

I am trying to understand the correct way to zero-pad the 2d-data.

This way I did not get the correct output.

 

MKL_LONG dim_child[2];

dim_child[0]                                 = 9;
dim_child[1]                                 = 17;

MKL_LONG dim_parent[2];

dim_parent[0]                                = 12;
dim_parent[1]                                = 23;

MKL_LONG                                     status;
DFTI_DESCRIPTOR_HANDLE frwd_hndl             = NULL;
DFTI_DESCRIPTOR_HANDLE bkwd_hndl             = NULL;

double forward_scale                         = sqrt(2.0 * pi) / static_cast<double>(dim_child[0] * dim_child[1]);  

status                                       = DftiCreateDescriptor(&frwd_hndl, DFTI_DOUBLE, DFTI_COMPLEX, 2, dim_child);
status                                       = DftiSetValue(frwd_hndl, DFTI_FORWARD_SCALE, forward_scale);   
status                                       = DftiCommitDescriptor(frwd_hndl);

status                                       = DftiCreateDescriptor(&bkwd_hndl, DFTI_DOUBLE, DFTI_COMPLEX, 2, dim_parent);    
status                                       = DftiCommitDescriptor(bkwd_hndl);

int size_child                               = dim_child[0]  * dim_child[1];
int size_parent                              = dim_parent[0] * dim_parent[1];

MKL_Complex16 *fourier_coeff                 = NULL;
MKL_Complex16 *filterd_coeff                 = NULL;    
fourier_coeff                                = (MKL_Complex16*)mkl_malloc(size_child  * sizeof(MKL_Complex16), 64);
filterd_coeff                                = (MKL_Complex16*)mkl_malloc(size_parent * sizeof(MKL_Complex16), 64);
            
for (int j=0; j<lg_child; j++)
{
    for (int i=0; i<lt_child; i++)
    {
        int index                            = i + (j*lt_child);

        fourier_coeff[index].real 			 = // some_value;                        
        fourier_coeff[index].imag 			 = // some_value;                                               
    }            
}   

status                                       = DftiComputeForward(frwd_hndl, fourier_coeff);
status                                       = DftiFreeDescriptor(&frwd_hndl);
   	         
for (int j_prime=0; j_prime<lg_parent; j_prime++)       
{                                                
    for (int j=0; j<lg_child; j++)
    {
        for (int i=0; i<lt_child; i++)
        {   
            int index                        = i + (j       * lt_child);            
            int index_filter                 = i + (j_prime * lt_parent);           
            
            // zero-padding at the end of each row of length (lt_parent - lt_child)
            // [x x x x x x x x x x x x x x x x x 0 0 0 0 0 0 x x x x x x x x x x x x x x x x x 0 0 0 0 0 0...]
            //  _______________17________________ _____6_____
                                    
            filterd_coeff[index_filter].real += (fourier_coeff[index].real);
            filterd_coeff[index_filter].imag += (fourier_coeff[index].imag);
        }   
    }            
}        

status                                       = DftiComputeBackward(bkwd_hndl, filterd_coeff);
status                                       = DftiFreeDescriptor(&bkwd_hndl);  
        
for (int j=0; j<lg_parent; j++)
{            
    for (int i=0; i<lt_parent; i++)
    {                                
        int index                            = i + (j*lt_parent);
        
        std::cout << filterd_coeff[index].real<<"\t"<<filterd_coeff[index].imag<<std::endl;       
    }
}

mkl_free(fourier_coeff);        
mkl_free(filterd_coeff);

 

 

 

 

0 Kudos
1 Reply
Fengrui
Moderator
134 Views

Hi,


Thank you for posting in the forum!


I'm trying to understand the issue here. It looks the code is trying to zero-pad the Fourier coefficients after the FFT. Could you please provide more information about what this zero-padding is trying to achieve and what output is expected?


Thanks,

Fengrui


0 Kudos
Reply