Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Coding for Low/High pass filters

Status
Not open for further replies.

luckyvictor

Member level 4
Member level 4
Joined
Dec 1, 2009
Messages
78
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Visit site
Activity points
1,903
Hi All

I am given two pieces of codes for Low pass filter and High pass filter, however I am not able to fully understand it and have the following question:

High Pass Filter:

Code:
if isempty(val)
    val = single(zeros(numel(input),1));
    out = single(zeros(numel(input),1));
end

for i = 1:numel(input)
    if reset
        out(i) = single(0.0);
        val(i) = single(0.0);     
    else 
        out(i) = input(i) - (samplePeriod / tc) * val(i);
        val(i) = val(i) + out(i);
    end
end

output = out(:);

How does it work please? My main question is, how come the val(i) is multiplied before it is updated? Because when I dry run it, every time the for loop is entered, val(i) is a fresh zero value because the i is updated.

Low Pass Filter:

Code:
if isempty(previousOutput)
    previousOutput = single(zeros(numel(input),1));
    out = single(zeros(numel(input),1));
end

for i = 1:numel(input)
    if reset
        out(i) = single(0.0);
    else       
        out(i) = ((input(i) - previousOutput(i)) * samplePeriod / tc) + previousOutput(i);
    end
end

output = out(:);    
previousOutput = out(:);

For this one, I just simply can not derive the above equation from y = 1/(1+Tc/Ts*z-1).

Many thanks
 
Last edited by a moderator:

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top