My goal is to compute the Fourier of the product between two discrete time signals, y1 and y2. This can be done by computing the convolution between the fourier transform of y1, f1 and the fourier transform of y2, f2 (This is what I understood from the Wikipedia Page).
I tried the following code in MATLAB, it shows that the convolution between y1 and y2 is equal to ifft(f1.*f2) as shown on the Wikipedia page, the code worked perfectly:
y1=sin(x); y2=sin(3*x); n=length(y1); convol=conv(y1,y2); f1=fft(y1,n*2-1); f2=fft(y2,n*2-1); plot(ifft(f1.*f2)) hold on plot(convol,'x')
Now I want to be able to compute the fourier transform of the product of y1 by y2 using the convolution theorem, this can be done by computing the convolution between f1 and f2, so I wrote the following code:
x=0:0.01:10; y1=sin(x); y2=sin(3*x); n=length(y1); f1=fft(y1,n*2-1); f2=fft(y2,n*2-1); convol=conv(f1,f2); ffty1y2=fft(y1.*y2,length(convol)); plot(abs(ffty1y2)) hold on plot(abs(convol)/length(convol),'x')
As you can see the results do not match (neither in location of the peaks nor in their values), what could be wrong here? How do I fix this?