Lets Learn together... Happy Reading

" Two roads diverged in a wood, and I,
I took the one less traveled by,
And that has made all the difference "-Robert Frost

One Dimensional Low pass , High Pass and band pass filtering

Consider a one dimensional signal in time domain.
For instance, generate cosine waves of different amplitudes and different frequencies and combine them to form a complicated signal.
Consider four cosines waves with frequencies 23, 18, 10 and 5 and amplitudes 1.2, 0.8, 1.1 and 2 respectively and combine them to generate a signal.

Eg.

Cosine wave with frequency 23 and amplitude 1.2.
 
Figure.1

Cosine wave with frequency 18 and amplitude 0.8
 
Figure.2
Cosine wave with frequency 10 and amplitude 1.1
 
Figure.3

Cosine wave with frequency 5 and amplitude 2.
Figure.4
MATLAB code:

%To generate a signal
%Input function A cos(2pift)
freq =[23 18 10 5];
Amp = [1.2 0.8 1.1 2];

fs = 100;
ts = 1/fs;
t = 0:ts:5;
xt1 = 0;
for Ind = 1:numel(freq)
Freq = freq(Ind);
A = Amp(Ind);
xt1 = xt1+A*cos(2*pi*Freq*t);
end

figure,plot(t,xt1);
 
Figure.5
Let’s make a little understanding of this signal in frequency domain.
i.e in Fourier domain.
Fourier transform is one of the various mathematical transformations known which is used to transform signals from time domain to frequency domain.
The main advantage of this transformation is it makes life easier for many problems when we deal a signal in frequency domain rather than time domain.

After fourier transform, the signal will look like the below figure.


MATLAB code:

f1 = linspace(-fs/2,fs/2,numel(xt1));
xf = fftshift(fft(xt1));
str = 'Frequency domain';
figure,plot(f1,abs(xf)),title(str);

 
Figure.6

EXPLANATION:

In the figure.6, there are 4 different colors to denote four different signals.
Due to symmetric property, we see two peaks of the same signal.

fftshift is useful for visualizing the Fourier transform with the zero-frequency component in the middle of the spectrum.

The yellow color peaks denote the frequency with 5
The blue color peaks denote the frequency with 10
The green color peaks denote the frequency with 18
And the red color denotes the frequency with 23.

From this, we can understand that the low frequency components are close to the centre of the plot and the high frequency components are away from the centre.


Now, lets try to separate each of the original 4 signals from the combined ones.

We will keep only one signal at a time and remove/filter the rest.

MATLAB code:

       Kernel_BP = abs(f1) < 8;
   BPF = Kernel_BP .* xf;
  
   figure,plot(f1,abs(BPF));


Figure.7

Figure.8





A kernel is used to obtain the essential frequency component alone.
This can be done by making the values one for the frequency range less than 8 and rest zero.

We have obtained the lowest frequency component and the kernel we designed is for low pass filtering. The value which we use to find the limit is the cut off frequency. Here 8 is the cut of frequency.

Now , let’s go back to time domain.

MATLAB code:

BP_t = ifft(ifftshift(BPF));
plot(t,real(BP_t));

Compare the figure.4 and figure.9, both have same frequency right!!

Figure.9

Now let’s try to design the kernel for filtering high frequency component.

High Pass filter:MATLAB code :

    
   Kernel_BP = abs(f1) > 20;
   BPF = Kernel_BP .* xf;
  
   figure,plot(f1,abs(BPF));
 
Figure.10

   
Figure.11

  BP_t = ifft(ifftshift(BPF));
  plot(t,real(BP_t));



Figure.12


We have obtained the same signal as in figure.1

We will try to filter the signal of frequency 18.
This is band pass filter.

Band Pass Filter:
MATLAB code:
   Kernel_BP = abs(f1) > 15 & abs(f1) < 20;
   BPF = Kernel_BP .* xf;
  
   figure,plot(f1,abs(BPF));

         
Figure.13
   BP_t = ifft(ifftshift(BPF));
   plot(t,real(BP_t));
 
Figure.14

Figure.15

This same type of filtering can be applied on noisy signals to remove undesired signals.

MATLAB code:

Noise = 2 * randn(size(t));
xt1 = xt1 + Noise;

Using this signal as input, we can apply low, high and band pass to remove noise and obtain the original signal(to some extent).

Wait for my next post on two dimensional low and high pass filtering. i.e on images in space domain.

like button Like "IMAGE PROCESSING" page

0 comments:

Enjoyed Reading? Share Your Views

Previous Post Next Post Home
Google ping Hypersmash.com