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 ?
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.
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 )