# Gaussian Blur For Entire Image

I am trying to simulate the blurring process (defocus) of a sinusoidal. For this I have build my own Gaussian filter and performed the convolution in Fourier domain.

The result of the blurred signal is shown below.

The effect in the left and right most part of the blurred image is I assume due to the filter size. If I take sufficiently narrow sized filter the effect becomes less visible.

However, is there a way to get rid of this effect? For example if I take a real picture of a sinusoidal which is out of focus, then one wouldn't observe this effect in the real captured image. What is the correct way to get rid of this effect?

• "if I take a real picture of a sinusoidal which is out of focus" that's because the blur is applied before the photons land on the imager. If you had a field stop (I think that's the right term) that was applied before the light went into the lens, or if your sine wave were on a rectangular surface that was exactly matched with the camera's field of view, then you would have that effect. Nov 2 '21 at 21:55
• Telling us why you want to get rid of that effect would be nice -- for example, if you're trying to simulate an out-of-focus camera, it would be helpful to say so. Please edit your question with any changes. Nov 2 '21 at 21:56

The issue is probably because of the start-up transients. You can possibly fix this using the zi parameter on the filter function:

The other option might be to use the filtfilt method which attempts to choose the initial conditions:

If I take that approach, then the resulting filterings are shown below. The original sinusoid is in blue, the filter version (without matching the initial conditions) is in red and the filtfilt version is in black +s.

# Matlab code

N = 1000;
ts = 0.001;
t = (0:N-1)*ts;
omega = 2*pi*23;
phi = 2*pi*0.829879;
Nsmooth = 10;
Nextra = 10*Nsmooth;

x = sin(omega*t+phi);
xx = [ fliplr(x(1:Nextra)) x fliplr(x((end-Nextra):end)) ];
y = filter(ones(1,Nsmooth)/Nsmooth, 1, x);
zz = filtfilt(ones(1,Nsmooth)/Nsmooth, 1,x);

clf;
plot(x);
hold on;
plot(y,'r');
plot(zz,'k+');