Manually creating a lowpass filter from the frequency domain: what phase? In an attempt to gain a better understanding of DSP, I want to create a very simple (1D) lowpass, or I think more correctly "stop-band" or "band-reject" filter, to filter out a single frequency, e.g., f2 in my code example below.

The idea is to build in in the frequency domain, by putting all ones values in every component of the filter's magnitude part EXCEPT of course in the position corresponding to f2. What i don't understand, is what phases am I would be supposed to put in the corresponding LP phase vector? (I think this is related to my problems of understanding phases in general)

For and ideal lowpass filter (brick-wall) I know the corresponding impulse response would be a sinc in the time domain. But e.g. if I built the magnitude part of the brickwall "manually" ones around 0 frequency and 0s for higher freq than the cutoff freq, I would have no idea what to put for the phase ?

My code:

clc;clear all;

fs=1000;
t=0:(1/fs):1-(1/fs);
f1=5;
f2=27;
A1=13;
A2=3;
foffset=3;
posFreqPos=f2+1;
negFreqPos=fs-f2+1;

s=A1*cos(2*pi*f1*t)+A2*cos(2*pi*f2*t);

S=fft(s);
Smag=abs(S);
Sphase=angle(S);

LP_mag=ones(size(S));
LP_mag(posFreqPos)=0;%filter out high freq f2
LP_mag(negFreqPos)=0;

%%%%%%%%%%%%%%%%%%%
% LPphase= ???
%%%%%%%%%%%%%%%%%%%

%the filter built from mag and phase
LPf=LP_mag.*exp(-i.*LPphase);

figure;
plot(LPf)

figure;
plot(s);
figure;
plot(Smag);


I have modified the code here, the first version didn't make sense sorry.
It's really a question about the phase.

The idea is to build a filter such as:


Following the convolution theorem which states that a point-wise multiplication in the frequency domain corresponds to a convolution in the time domain. Of course one simple solution which "roughly" works is to just set to zero the frequencies I want to remove (following the same idea as shown on the image ) in the magnitude image of the FFT of my image, the rebuild the image with 

myImage_filtered = real(ifft(myImageMag_filtered.*exp(-i.*myImagephase))); %real(.) to avoid rounding error causing imaginary part to be non-zero

(image source:http://www.robots.ox.ac.uk/~az/lectures/ia/lect2.pdf )
Typically if you're designing to an amplitude response, you set the phase at zero.  In processing time-domain signals, this is to keep the group delay of the filter constant.  In processing images, this will keep the filter effects centered, rather than displacing different spectral components of the image with respect to one another.
At least in time-domain processing there can be good reasons not to do this.  I can't think of any reason you would want a non-constant delay filter in image processing.
Keeping the phase at zero makes a constant-delay filter.  If you're doing your filtering after the fact, then you can just delay everything else by the same amount so that it appears that you're using a zero-delay noncausal filter.
However, if you're responding to the filter output in the real world (usually for some sort of closed-loop control, but possibly for fault detection), then that delay can be a performance-killer.  In addition, there's a feeling in the audio community that unwisely-designed constant-delay filters can cause aesthetic problems (Google on &quot;pre-ring&quot;).  You solve these problems (and cause others) by using a minimum-phase filter.  These are almost always done by using an IIR filter rather than an FIR.