0
votes

I have a complex frequency signal (which I have converted from time domain). Now I would like to implement low pass filter on the same with cut off frequency value. Can someone suggest me best way to implement low pass filter without using built in function (filter).

1
Why would you prefer to re-invent the wheel rather than just using what's already available ? - Paul R
Do you know the theory of how to define the lowpass filter? If so try it out and post code if you run into trouble. - paisanco
I am not sure of the low pass filter functionality, I just want to know how it functions and would like to recreate the same in JAVA - Dinesh
Any book on digital signal processing will help you. - Yvon
MATLAB can generate the coefficients for an FIR or IIR Filter for you - that's the hard part taken care of - then the easy part is plugging those coefficients into a few lines of Java code to implement the filter. - Paul R

1 Answers

1
votes

I suggest you take a look in Audio-EQ-Cookbook from Robert Bristow-Johnson, you can build a lot of filters.

Lets try build a LPF(low pass filter) following the equations, first I build a signal test ( four sinusoidal at 200, 500, 700 and 1000Hz), FFT plot:

enter image description here

Now after apply equations to cut off Frequency in 200hz

enter image description here

my code used to test:

%Low pass filter example from RBJ EQ-Cookbook
N = 4096;

%Test signal

Fs=44100;
f1  = 200;
f2  = 500;
f3  = 700;
f4  = 1000;

signal1 = 0.9*sin(2*pi*f1/Fs*(0:N+1));

signal2 = 0.9*sin(2*pi*f2/Fs*(0:N+1));

signal3 = 0.9*sin(2*pi*f3/Fs*(0:N+1));

signal4 = 0.9*sin(2*pi*f4/Fs*(0:N+1));


%mix all signals
signal= signal1 + signal2 + signal3  + signal4;

%test signal end

%%Start Filter

%F0 - cut off Frequency above ??
F0 = 200;
Q=1;
g = 80;

A = sqrt (10^(g/20));
w0 = 2 * pi * F0/Fs;
c= cos(w0);
s = sin(w0);

alpha = sin(w0)/(2*Q);


b0 = (1 - cos(w0))/2;
b1 = 1 - cos(w0);
b2 = (1- cos(w0))/2;
a0 = 1 + alpha;
a1 = -2*cos(w0);
a2 = 1 - alpha;

x1 = 0;
x2 = 0;
y1 = 0;
y2 = 0;

b0 = b0 / a0;

b1 = b1 / a0;

b2 = b2 / a0;

a1 = a1 / a0;

a2 = a2 / a0;


%y = filtred signal
for j=1:length(signal),

    y(j) = b0*signal(j) + b1*x1 + b2*x2 - a1*y1 - a2*y2;

    x2 = x1;
    x1 = signal(j);
    y2 = y1;
    y1 = y(j);

end