Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- L = 2; % length
- M = 200; % number of samples
- dx = L/M; % sample interval
- x = -L/2:dx:L/2-dx; % x coordinates
- f_1 = exp(-pi*(x.^2)); % Gaussian 1
- f_2 = exp(-pi*(x.^2)); % Gaussian 2 (same as 1)
- figure(1)
- plot(x,f_1,x,f_2,'--'); title('functions');
- xlabel('x (m)');
- %% Step 2. Perform convolution
- F_1 = fft(f_1); % transform f_1
- F_2 = fft(f_2); % transform f_2
- F_0 = F_1.*F_2; % multiply pointwise
- f_0 = ifft(F_0)*dx; % inverse transform and scale
- f = fftshift(f_0); % center result
- figure(1)
- hold on
- plot(x,f); title('Convolution');
- xlabel('x')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement