CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Software LPF

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

Software LPF
PostPosted: Thu Jun 25, 2020 8:31 am     Reply with quote

Hello to everyone.
I want to make lpf software. However, I would like to know what you know about HPF and Bpf.
Below Steves shared a post. Thank you to him. But is lpf as simple as shown here?
As I understand it; (1 new data + 3 old data) / 4.
How many hertz is the frequency filtered here?
Actually, what I'm trying to do is write an lpf function.

void lpf (frequency) {
.......
}

I would be glad if you help me in this regard.

Best regards.


http://www.ccsinfo.com/forum/viewtopic.php?t=19509&highlight=filter
Quote:

===== Low Pass Filter =====

A really simple low pass filter that approximates a single pole (R-C) analog filter:

Out0 = a * In0 + b * Out1
where a + b = 1.0 (a and b are fractions > 0 and < 1)

This is an IIR filter since it uses past outputs. Basically it averages the new input with last output. The smaller the 'a' term is, the slower the response of the filter. If you use constants divisible by a power of two it is a very fast calculation. A good starting point is to set a = 1/4 and b = 3/4:

Out0 = (In0 + Out1 + Out1 + Out1) / 4;
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jun 25, 2020 10:12 am     Reply with quote

Problem is that doing a 'generic' filter, without knowing the parameters
at compile time, involves a lot of maths. There is an example using a
PIC that has a built in hardware lpf, in ex_lowpass_filter_adc2.c, and
one doing audio, but using a DsPIC in ex_fft_filter.c.
Honestly the best way to approach the other filter types is to look at
the fft solutions. All the examples of these use the DsPIC's to get the
performance needed.
To do hpf requires much higher frequency sampling than the lpf.


Last edited by Ttelmah on Thu Jun 25, 2020 11:42 am; edited 1 time in total
temtronic



Joined: 01 Jul 2010
Posts: 9093
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Thu Jun 25, 2020 10:41 am     Reply with quote

Mr T is right, again.
'Generic' LPF....really need to know frquencies involved as well as which PIC. You can create LPF for any PIC but one with a DAC has obvious benfits. Microchip has an apnote( 2 decade+ago) about doing FFT, in assembler of course. Modified, it was the basis of a 'glass break detector' used to replace PIR sensors.
Speed is essential !You'll probably need a PIC clocked at 32-64MHz if you're doing 'other stuff' as well as filters.
bkamen



Joined: 07 Jan 2004
Posts: 1611
Location: Central Illinois, USA

View user's profile Send private message

PostPosted: Thu Jun 25, 2020 11:50 am     Reply with quote

Ttelmah wrote:
All the examples of these use the DsPIC's to get the performance needed.


Yes. the dsPIC series is the way to go. And NOT the PIC24. The difference between the two is the dsPIC specifically have DSP style instructions in the processor.

You'll want to look at:

https://www.microchip.com/design-centers/16-bit for more information.

(if you haven't already)
_________________
Dazed and confused? I don't think so. Just "plain lost" will do. :D
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Jun 25, 2020 1:10 pm     Reply with quote

Yes, and the fft example from CCS, does use the DSP abilities.
ressas



Joined: 15 Nov 2019
Posts: 135

View user's profile Send private message

PostPosted: Fri Jun 26, 2020 3:06 am     Reply with quote

As I understand it, LPF means multiplying with different coefficients.
I will not work at high frequencies. Maximum 60 hz. So I think I don't have to work with dspic.
How to start using appropriate coefficients and using ADC in a program like Matlab?
I looked at the function in the link you provided. But I want to design it myself.
Let it be plain and let me understand the logic.
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Fri Jun 26, 2020 6:22 am     Reply with quote

Even at 60Hz, if you want to do a high pass filter, If you had a waveform
that has high frequency components (remember a square wave has HF
components extending up to infinity!..), you would need to be sampling
well above this frequency, and the maths is huge.

With FFT, you are calculating the frequency components needed to 'build'
the waveform you have. Even a basic FFT algorithm (example here):

<http://www.ccsinfo.com/forum/viewtopic.php?t=54587&highlight=fft>

Involves performing sin & cos calculations on the data.

Now, you talk about a lpf, and an hpf. Both of these would involve
performing the FFT in 'realtime'. You are underestimating enormously
just how much is involved in doing this. Even on a 40MHz PIC18, a
sin takes nearly 700uSec. You are performing two of these each time
round the FFT loop, and a minimum of 6 loops per data point. Several
mSec per point. Doesn't give you much time... Sad

A non realtime 'test' to verify what frequencies are in a signal, yes. But
realtime (even on low frequency data), no.
temtronic



Joined: 01 Jul 2010
Posts: 9093
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Fri Jun 26, 2020 6:55 pm     Reply with quote

re: FFT ... download and read Microchip APnote AN00542c.
While the code is in assembly language for the 17C42, it's easy enough to translate into C though I suspect C versions exist.
Obviously much better (faster ,more memory,etc) PICs can be used but the apnote does show what can be done.

I imagine you could fill a library with FFT info......a LOT depends upon what you need the PIC to actually do.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group