Advertisement
Guest User

Untitled

a guest
Jul 20th, 2017
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. L = 2; % length
  2. M = 200; % number of samples
  3. dx = L/M; % sample interval
  4.  
  5. x = -L/2:dx:L/2-dx; % x coordinates
  6. f_1 = exp(-pi*(x.^2)); % Gaussian 1
  7. f_2 = exp(-pi*(x.^2)); % Gaussian 2 (same as 1)
  8.  
  9. figure(1)
  10. plot(x,f_1,x,f_2,'--'); title('functions');
  11. xlabel('x (m)');
  12.  
  13. %% Step 2. Perform convolution
  14. F_1 = fft(f_1); % transform f_1
  15. F_2 = fft(f_2); % transform f_2
  16. F_0 = F_1.*F_2; % multiply pointwise
  17. f_0 = ifft(F_0)*dx; % inverse transform and scale
  18. f = fftshift(f_0); % center result
  19.  
  20. figure(1)
  21. hold on
  22. plot(x,f); title('Convolution');
  23. xlabel('x')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement