<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Help with convolving data sets in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-convolving-data-sets/m-p/878437#M9263</link>
    <description>Hi guys, &lt;BR /&gt;&lt;BR /&gt;I've been banging my head against the wall trying to convolve two data sets. They are of equal length. One is a gaussian, and the other is a Lorentzian. I haven't been able to get it to work using a regular convolution. &lt;BR /&gt;&lt;BR /&gt;i.e.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;for (j = 0; j &amp;lt; 64; j += 1)&lt;BR /&gt;{ &lt;BR /&gt; y&lt;J&gt;= 0.0; &lt;BR /&gt; for (i = 0; i &amp;lt;= j; i++)&lt;BR /&gt; {&lt;BR /&gt; y&lt;J&gt; += x&lt;I&gt; * h[j - i];&lt;BR /&gt; }&lt;BR /&gt;}&lt;/I&gt;&lt;/J&gt;&lt;/J&gt;&lt;/PRE&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;and I haven't been able to get it to work using a Fourier Transform (see below). My convolution is orders of magnitude larger than the input functions and a completely wrong shape.&lt;BR /&gt;&lt;BR /&gt;Now, I have been getting all of my information about this from Google, so I must be missing something pretty obvious. Especially since both ways of doing it are failing for me. I know this isn't completely related to the MKL, but I plan on using the MKL wrappers for fftw after i get my test case working. If anyone could give me a hand with either the FT or regular convolution, I would really appreciate it. You can download the project from here&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://diehard2.googlepages.com/fftw" target="_blank" title="http://diehard2.googlepages.com/fftw"&gt;Convolution project&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;I know I'm using the FFTW correctly, as I can FT and inverse FT a function without a problem. Thanks for any help.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;#include "stdafx.h"&lt;BR /&gt;#include &lt;FSTREAM&gt;&lt;BR /&gt;#include &lt;IOSTREAM&gt;&lt;BR /&gt;#include &lt;CONIO.H&gt;&lt;BR /&gt;#include "fftw3.h"&lt;BR /&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;int _tmain(int argc, _TCHAR* argv[])&lt;BR /&gt;{&lt;BR /&gt; double *x = (double*)fftw_malloc(1000*sizeof(double));&lt;BR /&gt; double *y = (double*)fftw_malloc(1000*sizeof(double));&lt;BR /&gt; double *conv3 = (double*)fftw_malloc(1000*sizeof(double));&lt;BR /&gt; int NumberofPoints = 0;&lt;BR /&gt; &lt;BR /&gt; fftw_plan p;&lt;BR /&gt; fftw_complex* out1 = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * 1000);&lt;BR /&gt; fftw_complex* out2 = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * 1000);&lt;BR /&gt; fftw_complex* final = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)* 1000);&lt;BR /&gt;&lt;BR /&gt; for(int i = 0; i &amp;lt; NumberofPoints; i++)&lt;BR /&gt; {&lt;BR /&gt;  out1&lt;I&gt;[0] = 0;&lt;BR /&gt;  out1&lt;I&gt;[1] = 0;&lt;BR /&gt;  out2&lt;I&gt;[0] = 0;&lt;BR /&gt;  out2&lt;I&gt;[1] = 0;&lt;BR /&gt;  final&lt;I&gt;[0] = 0;&lt;BR /&gt;  final&lt;I&gt;[1] = 0;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; //Read in our files&lt;BR /&gt; ifstream stream("individgraphs.dat");&lt;BR /&gt;&lt;BR /&gt; if(stream.is_open() == false)&lt;BR /&gt;  cout &amp;lt;&amp;lt; "Error" &amp;lt;&amp;lt; endl;&lt;BR /&gt;&lt;BR /&gt; while(stream &amp;gt;&amp;gt; x[NumberofPoints]&amp;gt;&amp;gt;y[NumberofPoints])&lt;BR /&gt; {&lt;BR /&gt;  NumberofPoints++;&lt;BR /&gt; }&lt;BR /&gt; stream.close();&lt;BR /&gt;&lt;BR /&gt; //FFTW&lt;BR /&gt;&lt;BR /&gt; //FT data file 1&lt;BR /&gt; p = fftw_plan_dft_r2c_1d(NumberofPoint
s, x, out1, FFTW_ESTIMATE);&lt;BR /&gt; fftw_execute(p); &lt;BR /&gt; fftw_destroy_plan(p);&lt;BR /&gt; //FT data file 2&lt;BR /&gt; p = fftw_plan_dft_r2c_1d(NumberofPoints, y, out2, FFTW_ESTIMATE);&lt;BR /&gt; fftw_execute(p);&lt;BR /&gt; fftw_destroy_plan(p);&lt;BR /&gt;&lt;BR /&gt; //Convolution - Complex multiplication and scaling&lt;BR /&gt; for(int i = 0; i &amp;lt; NumberofPoints; i++)&lt;BR /&gt; {&lt;BR /&gt;   final&lt;I&gt;[0] = (out1&lt;I&gt;[0]*out2&lt;I&gt;[0]-out1&lt;I&gt;[1]*out2&lt;I&gt;[1])*(1.0/(double)NumberofPoints);&lt;BR /&gt;   final&lt;I&gt;[1] = (out1&lt;I&gt;[0]*out2&lt;I&gt;[1]+out1&lt;I&gt;[1]*out2&lt;I&gt;[0])*(1.0/(double)NumberofPoints);&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; //Invert the product&lt;BR /&gt; p = fftw_plan_dft_c2r_1d(NumberofPoints, final, conv3,FFTW_ESTIMATE);&lt;BR /&gt; fftw_execute(p);&lt;BR /&gt; fftw_destroy_plan(p);&lt;BR /&gt;&lt;BR /&gt; //Write output file&lt;BR /&gt; ofstream test("outfile.txt");&lt;BR /&gt; for (int i = 0; i &amp;lt; NumberofPoints; i++)&lt;BR /&gt; {&lt;BR /&gt;  test &amp;lt;&amp;lt; conv3&lt;I&gt;/NumberofPoints &amp;lt;&amp;lt; endl;&lt;BR /&gt; }&lt;BR /&gt; test.close();&lt;BR /&gt;&lt;BR /&gt; //Free memory&lt;BR /&gt; fftw_free(x);&lt;BR /&gt; fftw_free(y);&lt;BR /&gt; fftw_free(out1);&lt;BR /&gt; fftw_free(out2);&lt;BR /&gt; fftw_free(conv3);&lt;BR /&gt;&lt;BR /&gt; getch();&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/CONIO.H&gt;&lt;/IOSTREAM&gt;&lt;/FSTREAM&gt;&lt;/PRE&gt; &lt;BR /&gt;</description>
    <pubDate>Thu, 13 Dec 2007 18:59:21 GMT</pubDate>
    <dc:creator>xraygenfit</dc:creator>
    <dc:date>2007-12-13T18:59:21Z</dc:date>
    <item>
      <title>Help with convolving data sets</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-convolving-data-sets/m-p/878437#M9263</link>
      <description>Hi guys, &lt;BR /&gt;&lt;BR /&gt;I've been banging my head against the wall trying to convolve two data sets. They are of equal length. One is a gaussian, and the other is a Lorentzian. I haven't been able to get it to work using a regular convolution. &lt;BR /&gt;&lt;BR /&gt;i.e.&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;for (j = 0; j &amp;lt; 64; j += 1)&lt;BR /&gt;{ &lt;BR /&gt; y&lt;J&gt;= 0.0; &lt;BR /&gt; for (i = 0; i &amp;lt;= j; i++)&lt;BR /&gt; {&lt;BR /&gt; y&lt;J&gt; += x&lt;I&gt; * h[j - i];&lt;BR /&gt; }&lt;BR /&gt;}&lt;/I&gt;&lt;/J&gt;&lt;/J&gt;&lt;/PRE&gt; &lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;and I haven't been able to get it to work using a Fourier Transform (see below). My convolution is orders of magnitude larger than the input functions and a completely wrong shape.&lt;BR /&gt;&lt;BR /&gt;Now, I have been getting all of my information about this from Google, so I must be missing something pretty obvious. Especially since both ways of doing it are failing for me. I know this isn't completely related to the MKL, but I plan on using the MKL wrappers for fftw after i get my test case working. If anyone could give me a hand with either the FT or regular convolution, I would really appreciate it. You can download the project from here&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://diehard2.googlepages.com/fftw" target="_blank" title="http://diehard2.googlepages.com/fftw"&gt;Convolution project&lt;/A&gt; &lt;BR /&gt;&lt;BR /&gt;I know I'm using the FFTW correctly, as I can FT and inverse FT a function without a problem. Thanks for any help.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;&lt;PRE&gt;&lt;BR /&gt;&lt;BR /&gt;#include "stdafx.h"&lt;BR /&gt;#include &lt;FSTREAM&gt;&lt;BR /&gt;#include &lt;IOSTREAM&gt;&lt;BR /&gt;#include &lt;CONIO.H&gt;&lt;BR /&gt;#include "fftw3.h"&lt;BR /&gt;&lt;BR /&gt;using namespace std;&lt;BR /&gt;&lt;BR /&gt;int _tmain(int argc, _TCHAR* argv[])&lt;BR /&gt;{&lt;BR /&gt; double *x = (double*)fftw_malloc(1000*sizeof(double));&lt;BR /&gt; double *y = (double*)fftw_malloc(1000*sizeof(double));&lt;BR /&gt; double *conv3 = (double*)fftw_malloc(1000*sizeof(double));&lt;BR /&gt; int NumberofPoints = 0;&lt;BR /&gt; &lt;BR /&gt; fftw_plan p;&lt;BR /&gt; fftw_complex* out1 = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * 1000);&lt;BR /&gt; fftw_complex* out2 = (fftw_complex*) fftw_malloc(sizeof(fftw_complex) * 1000);&lt;BR /&gt; fftw_complex* final = (fftw_complex*) fftw_malloc(sizeof(fftw_complex)* 1000);&lt;BR /&gt;&lt;BR /&gt; for(int i = 0; i &amp;lt; NumberofPoints; i++)&lt;BR /&gt; {&lt;BR /&gt;  out1&lt;I&gt;[0] = 0;&lt;BR /&gt;  out1&lt;I&gt;[1] = 0;&lt;BR /&gt;  out2&lt;I&gt;[0] = 0;&lt;BR /&gt;  out2&lt;I&gt;[1] = 0;&lt;BR /&gt;  final&lt;I&gt;[0] = 0;&lt;BR /&gt;  final&lt;I&gt;[1] = 0;&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; //Read in our files&lt;BR /&gt; ifstream stream("individgraphs.dat");&lt;BR /&gt;&lt;BR /&gt; if(stream.is_open() == false)&lt;BR /&gt;  cout &amp;lt;&amp;lt; "Error" &amp;lt;&amp;lt; endl;&lt;BR /&gt;&lt;BR /&gt; while(stream &amp;gt;&amp;gt; x[NumberofPoints]&amp;gt;&amp;gt;y[NumberofPoints])&lt;BR /&gt; {&lt;BR /&gt;  NumberofPoints++;&lt;BR /&gt; }&lt;BR /&gt; stream.close();&lt;BR /&gt;&lt;BR /&gt; //FFTW&lt;BR /&gt;&lt;BR /&gt; //FT data file 1&lt;BR /&gt; p = fftw_plan_dft_r2c_1d(NumberofPoint
s, x, out1, FFTW_ESTIMATE);&lt;BR /&gt; fftw_execute(p); &lt;BR /&gt; fftw_destroy_plan(p);&lt;BR /&gt; //FT data file 2&lt;BR /&gt; p = fftw_plan_dft_r2c_1d(NumberofPoints, y, out2, FFTW_ESTIMATE);&lt;BR /&gt; fftw_execute(p);&lt;BR /&gt; fftw_destroy_plan(p);&lt;BR /&gt;&lt;BR /&gt; //Convolution - Complex multiplication and scaling&lt;BR /&gt; for(int i = 0; i &amp;lt; NumberofPoints; i++)&lt;BR /&gt; {&lt;BR /&gt;   final&lt;I&gt;[0] = (out1&lt;I&gt;[0]*out2&lt;I&gt;[0]-out1&lt;I&gt;[1]*out2&lt;I&gt;[1])*(1.0/(double)NumberofPoints);&lt;BR /&gt;   final&lt;I&gt;[1] = (out1&lt;I&gt;[0]*out2&lt;I&gt;[1]+out1&lt;I&gt;[1]*out2&lt;I&gt;[0])*(1.0/(double)NumberofPoints);&lt;BR /&gt; }&lt;BR /&gt;&lt;BR /&gt; //Invert the product&lt;BR /&gt; p = fftw_plan_dft_c2r_1d(NumberofPoints, final, conv3,FFTW_ESTIMATE);&lt;BR /&gt; fftw_execute(p);&lt;BR /&gt; fftw_destroy_plan(p);&lt;BR /&gt;&lt;BR /&gt; //Write output file&lt;BR /&gt; ofstream test("outfile.txt");&lt;BR /&gt; for (int i = 0; i &amp;lt; NumberofPoints; i++)&lt;BR /&gt; {&lt;BR /&gt;  test &amp;lt;&amp;lt; conv3&lt;I&gt;/NumberofPoints &amp;lt;&amp;lt; endl;&lt;BR /&gt; }&lt;BR /&gt; test.close();&lt;BR /&gt;&lt;BR /&gt; //Free memory&lt;BR /&gt; fftw_free(x);&lt;BR /&gt; fftw_free(y);&lt;BR /&gt; fftw_free(out1);&lt;BR /&gt; fftw_free(out2);&lt;BR /&gt; fftw_free(conv3);&lt;BR /&gt;&lt;BR /&gt; getch();&lt;BR /&gt; return 0;&lt;BR /&gt;}&lt;BR /&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/I&gt;&lt;/CONIO.H&gt;&lt;/IOSTREAM&gt;&lt;/FSTREAM&gt;&lt;/PRE&gt; &lt;BR /&gt;</description>
      <pubDate>Thu, 13 Dec 2007 18:59:21 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/Help-with-convolving-data-sets/m-p/878437#M9263</guid>
      <dc:creator>xraygenfit</dc:creator>
      <dc:date>2007-12-13T18:59:21Z</dc:date>
    </item>
  </channel>
</rss>

