Searching \ for 'Cheat-cheap FFT:' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: piclist.com/techref/index.htm?key=
Search entire site for: 'Cheat-cheap FFT:'.

Truncated match.
PICList Thread
'Cheat-cheap FFT:'
1999\08\30@161338 by MEDICINTEKNIK KB

picon face
Hello everyone out there ,

Is it my turn now? I have been on this list for a few months; find it very interesting, and have learnt a lot. I also hope I have added a few cents worth...

Competence is very high amongst contribituors, and I guess the following issue can be solved - or already have been solved by a few of you: A suggestion for approoach would be appreciated:

I would like to measure the frequency of signals in the 1 -- 20 Hz range, not using a DSP or anything other that the already engaged PIC 16C711. It uses a timer interrupt routine, that is it idles most of the time, but every millisecond it jumps out of the loop and polls the AD RES. The A/D is of course picking up the low freq. "AC" (actually 0 -- 5V) to be measured.

My idea was to see on each sample if the previous sample was smaller. If so, the voltage is ascending. When descending (implementing 3 bits of noice reducing "backlash") I have found a point in time when the peak was found. Correspondingly, I find the "valley". The idŽa is based on a counter that is stepped up every ms, and is used to measure the time between peaks and valleys. In other words, if there are 100 counts between a valley and a peak, we have ¸ wavelength being 100 ms long. 5Hz - right ?

I have 20 registers. If the frequency is 1.5 -- 2.5 Hz, I add one to the "2 Hz register". If the frequency is 18.5 -- 19.5 Hz, I call it 19Hz. After a few seconds of measurement, I should have a handfull of values in the registers, to correspond to the frequency components of the signal.

This should work for pretty and clear sinewaves. But these signals are actually noisy with - for instance - long "flats" to consider, when finding a correct point in time. Actually the signal can be considered a random pink noice.

The signal is in other words a bit complex for finding frequency components in a FFT-type fashion. If it is 5 Hz with a dent in it, it is maybe 80 % 5 Hz, 15 % 15 Hz . . so to speak. This is not imortant in detail. I would like to know that the base is 5 Hz.

Now to the problem. It doesn't  __  work. Am I too optimistic ? Should I realize that a PC or a DSP of some quick sort is needed for this? Am I better off "zero cross-detecting" at 2.5 Volts?

So - the question is -  has anyone been walking this path before ? Am I on the right track ?

Sven

1999\08\30@164317 by Erik Reikes

flavicon
face
At 09:52 PM 8/30/99 +0200, you wrote:
>Hello everyone out there ,
>
>My idea was to see on each sample if the previous sample was smaller. If so,
>the voltage is ascending. When descending (implementing 3 bits of noice
>reducing "backlash") I have found a point in time when the peak was found.
>Correspondingly, I find the "valley". The idŽa is based on a counter that is
>stepped up every ms, and is used to measure the time between peaks and
>valleys. In other words, if there are 100 counts between a valley and a
>peak, we have ¸ wavelength being 100 ms long. 5Hz - right ?
>
>I have 20 registers. If the frequency is 1.5 -- 2.5 Hz, I add one to the "2
>Hz register". If the frequency is 18.5 -- 19.5 Hz, I call it 19Hz. After a
>few seconds of measurement, I should have a handfull of values in the
>registers, to correspond to the frequency components of the signal.

The problem with this approach is that you are only getting the main low
frequency out of your signal and not any lower amplitude higher frequency
stuff on top of it.

My advice to you would be to lower your sampling rate from 1kHz to
something around 50Hz (40Hz nyquist number with some margin)  and actually
do the FFT calculation.  I'ts been a while since I've actually done this
(since college as a matter of fact), but you should be able to pull off the
FFT algorithm in a PIC with your 8 bit input values, especially at this
slow update rate.

You might be able to filter the signal somehow if you are only interested
in fundmental frequency... maybe an integration or something?

Good luck!

-E

1999\08\30@170823 by eplus1

flavicon
face
fft source for the SX is at
ftp://ftp.scenix.com/apps/sine&fft.zip
and Tony Nixon's SX to PIC asm menomic converter is at
http://210.8.30.173/parapic.zip
It needs the .lst file as well as the .src file to function correctly, so
compile the parallax file first with SPASM /L
ftp://ftp.scenix.com/tools/SASM.exe
then press the start button, click on a Parallax.src file, watch the
progress indicator on the form, and voila, you have a PIC.asm file. Any
errors are listed in the new .asm file

Or just read the source (SX instructions aren't that different; kind of like
the 8080 vs. the Z80)

James Newton, webmaster http://get.to/techref
(hint: you can add your own private info to the techref)
spam_OUTjamesnewtonTakeThisOuTspamgeocities.com
1-619-652-0593 phoneÊ



{Original Message removed}

1999\08\30@185720 by Sean H. Breheny

face picon face
Hi Sven,

It is interesting how the minds of people on this list often think alike! A
few years ago, before I had studied Fourier analysis, I had a very similar
idea to what you propose here. I got interesting results but I found some
problems with it at the time and pretty much came to the conclusion that it
wasn't quite working. I think if I were to go back and look at it again
now, I would find many problems with it.

The method you describe works if you want to find the fundamental (i.e.,
the period of the composite signal, which is NOT necessarily the period of
any sine wave component of it). It also might work in some special cases
(where a the appropriate number of peaks and troughs appear in the signal).
However, some quick examples will quickly show that there are flaws in the
method:

Take a square wave for example. It displays no peaks and valleys, only
steps,and yet it is composed of many sine wave harmonics. The same is true
for a triangle wave,and for many other cases. It is true that some ripple
will remain in a square wave or triangle wave if some ofhte upper harmonics
are cut off,but this will effectively be removed by the quantized nature of
the sampling.

I have not yet learned FFT, DFT, or any of the digital transform methods.
The basic idea, as I understand it (from doing the paper/pencil versions of
the continuous time transforms),is to run a bunch of correlation integrals
(i.e., multiply the input waveform by various frequency sine and cosine
waves and average over a period of the input. If the result is non-zero,the
there is some content at that frequency,and it is proportional to the result).

If the input is non-periodic,you should be able to make some approximation
based on the highest and lowest freq. components that you want to search for.

There are ways to simplify this and make it more amenable to
calculation,and that's where the FFT source code comes in.

So, I guess the answer is to take a look at the source code mentioned by
others,in addition to maybe taking a look at a textbook regarding signals
and systems. I am taking a course in that right now,but unfortunately,I do
not have my textbook yet.

>From work that I have done on how optical scanners deal with sine wave
patterns, my hunch is that FFT probably uses a discrete averaging technique
and looks for cases where the averaging process produces a minimum in the
signal amplitude,which would correspond to the "notch filter" effect of the
averaging window. When this happens,the window width is the same as the
period of one of the frequency components.

Sean



At 09:52 PM 8/30/99 +0200, you wrote:
>Hello everyone out there ,
>
>Is it my turn now? I have been on this list for a few months; find it very
interesting, and have learnt a lot. I also hope I have added a few cents
worth...
>
>Competence is very high amongst contribituors, and I guess the following
issue can be solved - or already have been solved by a few of you: A
suggestion for approoach would be appreciated:
>
>I would like to measure the frequency of signals in the 1 -- 20 Hz range,
not using a DSP or anything other that the already engaged PIC 16C711. It
uses a timer interrupt routine, that is it idles most of the time, but
every millisecond it jumps out of the loop and polls the AD RES. The A/D is
of course picking up the low freq. "AC" (actually 0 -- 5V) to be measured.
>
>My idea was to see on each sample if the previous sample was smaller. If
so, the voltage is ascending. When descending (implementing 3 bits of noice
reducing "backlash") I have found a point in time when the peak was found.
Correspondingly, I find the "valley". The idŽa is based on a counter that
is stepped up every ms, and is used to measure the time between peaks and
valleys. In other words, if there are 100 counts between a valley and a
peak, we have ¸ wavelength being 100 ms long. 5Hz - right ?
>
>I have 20 registers. If the frequency is 1.5 -- 2.5 Hz, I add one to the
"2 Hz register". If the frequency is 18.5 -- 19.5 Hz, I call it 19Hz. After
a few seconds of measurement, I should have a handfull of values in the
registers, to correspond to the frequency components of the signal.
>
>This should work for pretty and clear sinewaves. But these signals are
actually noisy with - for instance - long "flats" to consider, when finding
a correct point in time. Actually the signal can be considered a random
pink noice.
>
>The signal is in other words a bit complex for finding frequency
components in a FFT-type fashion. If it is 5 Hz with a dent in it, it is
maybe 80 % 5 Hz, 15 % 15 Hz . . so to speak. This is not imortant in
detail. I would like to know that the base is 5 Hz.
>
>Now to the problem. It doesn't  __  work. Am I too optimistic ? Should I
realize that a PC or a DSP of some quick sort is needed for this? Am I
better off "zero cross-detecting" at 2.5 Volts?
>
>So - the question is -  has anyone been walking this path before ? Am I on
the right track ?
>
>Sven
>
|
| Sean Breheny                  
| Amateur Radio Callsign: KA3YXM
| Electrical Engineering Student  
\--------------=----------------
Save lives, please look at http://www.all.org
Personal page: http://www.people.cornell.edu/pages/shb7
.....shb7KILLspamspam@spam@cornell.edu ICQ #: 3329174

1999\08\31@045033 by root

flavicon
face
Hi,

some advices:

1. I guess you should choose a greater PIC. AFAIK I have seen an ANxxx
containing a FFT for 17C42 definitely. Maybe there is meanwhile for the
16C family (16C74 I guess). Look at http://www.microchip.com Application Notes.

2. It is important to fix two things before starting an FFT application:

2.1: fmax =  1 / (2 * delta_t) where delta_t is the time between two
samples. For a PIC, it must be sufficient do finish all computations "on
the fly". That's why a high-speed (20MHz) PIC is recommended.

2.2: spectral resolution. delta_f = 1 / t_sample where

       t_sample =  N * delta_t

where N is the number of samples.

It is wise so determine N and delta_t that they fullfill the particular
goal of your analysis.

3. The original FFT (which is far simpler than other ones) uses the fact,
that        N =  2 ^ k        (k is a positive integer).

4. If you have an a priori information which frequencies are to be
expected, it is important so determine the parameters mentioned above that
l * delta_f equals to the most of that frequencies otherwise the quality
of the analysis will degrade (this is the so called leakage error). [l
above is another positive integer.]

5. If you suspect that your input signal contains also higher frequency
components than you fmax determined in 2.1 above, it is advised to
pre-filter the input data with a lowpass filter. Microchip offers some
good literature: AN699 can be used as a starting point.

6. Memory can be a concern. Either an I2C serial RAM (PCF8570 or whatever)
can be used, or a parallel RAM (I use 6164).

7. FFT uses some complicated transcendental function. The can be realized
with tables only. Another problem is the lack of floating point
arithmetic, but a good workaround is a so-called Integer FFT.

I hope this helps shomehow.

Regards,
Imre

PS: I'm working on my PhD theses. Of course, the subject is FFT,
especially, how to eliminate the leakage error.

On Mon, 30 Aug 1999, MILTON MEDICINTEKNIK KB wrote:

{Quote hidden}

1999\08\31@065022 by Steve Thackery

flavicon
face
Thanks for that, Imre.

I'm a mathematical dunderhead so have to see these things in very simple
terms. I can summarise the two key points of FFT very briefly, and do so in
order to help other mathematically-challenged people.

Firstly, the maximum frequency you can extract is half the sampling
frequency.  In other words, if you sample at 10kHz then the highest
frequency you can pull out is 5kHz (this is known as the Nyquist frequency).

Secondly, the maximum *resolution* is 1 / duration of sound bite.  In other
words, if your sound bite is 100ms long, then the output of the FFT is in
steps of 10Hz.  If it's 2 seconds long, the steps are 0.5Hz apart.  Note
that this is *independent* of the sampling frequency.

There is one last thing to emphasise: filter out everything above the
Nyquist frequency *before* you do the sampling.  In the example 1/ above
with a 10kHz sampling frequency, filter out everything above 5kHz.  The
reason for this is that frequencies above 5kHz get "mirrored" back into the
0 to 5kHz range and give you invalid results.

Hope this is a useful summary.

Steve Thackery
Suffolk, England.
Web Site: http://www.btinternet.com/~stevethack/

1999\08\31@072604 by Steve Thackery

flavicon
face
Colleagues,

Since sending my email I've realised that I've left out a couple of
important points.  I've gotta go out for a couple of hours, and after that
I'll rewrite and resubmit it.

Meanwhile, although there is nothing actually *wrong* with the previous
email, I'd like to suggest you delete it.

Steve Thackery
Suffolk, England.
Web Site: http://www.btinternet.com/~stevethack/


----- Original Message -----
From: Steve Thackery <steve.thackeryspamKILLspamBTINTERNET.COM>
To: <.....PICLISTKILLspamspam.....MITVMA.MIT.EDU>
Sent: 31 August 1999 11:48
Subject: Re: Cheat-cheap FFT:


> Thanks for that, Imre.
>
> I'm a mathematical dunderhead so have to see these things in very simple
> terms. I can summarise the two key points of FFT very briefly, and do so
in
> order to help other mathematically-challenged people.

1999\08\31@131039 by Anne Ogborn

flavicon
face
If you're just getting frequency, why not just look for a
zero crossing and not much about with the ADC.

Hardware becomes a 1 bit comparator. Time positive transition
to positive transition. 'Blank' after negative transitions for
a short (compared to expected frequency) to prevent noise from
making false counts.



--
Anniepoo
Need loco motors?
http://www.idiom.com/~anniepoo/depot/motors.html

1999\08\31@141038 by John Griessen

flavicon
face
Well, I suppose he is looking for frequencies (plural) and
wants to reject noise that is other frequency mostly, then FFT
methods will sift those several frequencies out.

IF there is only a sorta clean
sorta sine wave on the line, then zero crossing will do.

Maybe there is stuff from other active sensors rolling around nearby
coming in on his line that he wants to reject....

John G.
Austex

{Quote hidden}


'Cheat-cheap FFT:'
1999\09\01@024823 by root
flavicon
face
Hello,

a good abstract!

Imre


On Tue, 31 Aug 1999, Steve Thackery wrote:

{Quote hidden}

1999\09\01@091847 by tmariner

flavicon
face
I would suggest one of two approaches:

1. Try Walsh transforms that use relatively lightweight mathematics, but
give only frequency data in the bins.

2. Do a full FFT which consists of a) "butterflying" (which eliminates
redundant calculations and is the main difference between the DFT and the
FFT, then b) performing some seemingly complex multiplication by
transendental functions. As Imre suggests, the use of tables can be used if
your sampling frequency stays fixed. (Actually most DSP filters, etc. can be
approximated fairly closely using the table lookup methods if one knows the
coefficients, etc.) The 17C42 note is a good starting place.

In both cases, the number of bins is a concern because of the limited
memory.

Tom

> {Original Message removed}

More... (looser matching)
- Last day of these posts
- In 1999 , 2000 only
- Today
- New search...