View previous topic :: View next topic |
Author |
Message |
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sat Jul 16, 2016 3:16 pm Post subject: Goertzel algorithm |
|
|
hi All!
I want to do caller ID. But I live in Russia. We have most of the telephone exchanges of old, they were made in the USSR. In the old telephone exchanges not used for FSK or DTMF, but own Soviet standard transmission of the calling subscriber.
The old standard differs by the algorithm, and frequencies. For example, here's the frequencies, they are transmitted without a pause between digits.
I found the code for Goertzel algorithm, but I can't figure out how to obtain the necessary data from this program and how to connect the signal to the ADC input.
code "2 of 6".
f, Hz The level dB
700 -6.5 To 27.4
900 -6.5 To 29.0
1100 -6.5 To 31.0
1300 -6.5 To 32.6
1500 -6.5 To 34.3
1700 -6.5 To 36.0
Combinations of two of the six frequencies above means:
f1 + f2, Hz The code "2 6"
The number
1 700 + 900 000011
2 700 + 1100 000101
3 900 + 1100 000110
4 700 + 1300 001001
5 900 + 1300 001010
6 1100 + 1300 001100
7 700 + 1500 010001
8 900 + 1500 010010
9 1100 + 1500 010100
0 1300+ 1500 011000
"Start" 1100 + 1700 100100
"Repeat" 1300+ 1700 101000
"Start" - represents the start and end of the two-frequency chip package (multi-frequency sequence is repeated several times a packet of information, the beginning and end of which points to this combination).
"Repeat" - it means that another figure repeats the previous (in the absence of the combination of decoding two series following the same numbers would be extremely difficult).
information package contains 10 two-frequency packages for 38-42 ms
Code: |
'( The results are good: the Filter 700Hz on the frequency produces a signal at 4094 parrot, and the "alien" 900Гц - 11. This is at 128 samples.
When 64 - 1022/11, when 32 - 272/18. So the algorithm itself is quite suitable for caller ID.
Only listing was a few typos, here is fixed.
Also - don't worry - the output data will have a value of million. As it should be, the ratio of resonance/noise remain the same.
Mrshilov Http://Bascomavr.3bb.ru/Viewtopic.phpPrintId=550
On arrival a phone call emitiram off hook - connected to line resistance Ohms 620-470.
Send the request to the PBX 500Hz, duration 100 ms. The answer comes in 10 packs of two-tone signals at 40ms each.
Run the algorithm - the duration of work for about 32 ms. At the end of his work in the variable Level will be information on the levels of each of the 6 frequencies.
If the level is above a threshold, then the frequency was in the parcel. Table of the combinations of the designated number (for example 900+1300= "5").
Recorded it and just move on to the next parcel. Run the algorithm we need to produce over 40ms to get to each new parcel, obviously will need another timer.
K=2*cos(2*pi*f/F), where f is the desired frequency, F is the sampling frequency.
The sampling period 256us. I.e. the sampling frequency F=3906,25 Hz
2 * 3 , 14 * 700 / 3906 , 25 = 1 , 1259468
Cos(1,1259468)=0,43032205 ----- the cosine in radians
2*0,43032205=0,8606441
')
$regfile = "m8adef.dat"
$crystal = 4000000
$hwstack = 64
$swstack = 32
$framesize = 48
$baud = 9600
'Variables
Dim K(6) As Single
K(1) = 0.86064410 'For frequency700Hz
K(2) = 0.24567877 'For frequency 900Hz
K(3) = -0.39449342 'For frequency 1100Hz
K(4) = -0.99419024 'For frequency1300Hz
K(5) = -1.49188229 'For frequency 1500Hz
K(6) = -1.83650594 'For frequency 1700Hz
Const N = 128 'Number of samples = 128
Dim New_sample As Word 'Data from ADC
Dim Samples As Byte 'Counter sample
Dim F As Byte 'Counter frequency
Dim Y2(6) As Single
Dim Y1(6) As Single
Dim Y0(6) As Single
Dim Level(6) As Single 'The amplitude of the frequency
Dim Ready As Bit 'Signal the end of calculations
'The configuration of the ADC
Config Pinc.0 = Input ' input ADC(0)
Config Adc = Single , Prescaler = 32 , Reference = Internal 'ADC 125kHz
Start Adc
'Timer sample
Config Timer2 = Timer , Prescale = 8 , Compare = Disconnect , Clear Timer = 1 'the sampling period 256uS
Compare2 = 128
On Compare2 Algorithm
Enable Compare2
Stop Timer2 'The timer is stopped
'===============================================================================
'=============================== The program =====================================
Do
'The start of the algorithm
For F = 1 To 6 'reset Y1 and Y2 in the beginning of the cycle
Y1(f) = 0
Y2(f) = 0
Next F
Ready = 0
Samples = 0
Enable Interrupts
Start Timer2
Loop
'-------------------------------------------------------------------------------
Algorithm:
New_sample = Getadc(0) 'Get ADC data
For F = 1 To 6 'Calculate all the frequencies
Y0(f) = K(f) * Y1(f)
Y0(f) = Y0(f) - Y2(f)
Y0(f) = Y0(f) + New_sample 'Result in Y0
Y2(f) = Y1(f) 'Move the data
Y1(f) = Y0(f)
Next F
Incr Samples 'the counter of the processed samples
'Final settlement after receipt of all 128 samples
If Samples = N Then
Stop Timer2 'Stop the sample was collected
For F = 1 To 6
Level(f) = Y1(f) * Y1(f)
Y0(f) = Y2(f) * Y2(f)
Level(f) = Level(f) + Y0(f)
Y0(f) = Y1(f) * Y2(f)
Y0(f) = Y0(f) * K(f)
Level(f) = Level(f) - Y0(f) ''Amplitude are regarded
Ready = 1
Next F
End If
Return
|
The telephone exchange transmits the calling number after the subscriber request - 500 Hz, 100-200 milliseconds. To improve the reliability of the signals can be transmitted 2-9 times.
https://upload.wikimedia.org/wikipedia/commons/3/38/ANI-signals.wav
info: https://translate.google.ru/translate?sl=ru&tl=en&js=y&prev=_t&hl=ru&ie=UTF-8&u=https%3A%2F%2Fru.wikipedia.org%2Fwiki%2F%25D0%2590%25D0%259E%25D0%259D&edit-text=
https://translate.google.ru/translate?sl=ru&tl=en&js=y&prev=_t&hl=ru&ie=UTF-8&u=http%3A%2F%2Fradio.cybernet.name%2Fshem%2Ftel%2Faon.html&edit-text=
(BASCOM-AVR version : 2.0.7.8 ) |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Jul 16, 2016 7:34 pm Post subject: |
|
|
This code is that far off from any reason, that I doubt it will ever work, where did you get it from?
I'll explain:
Every 1032 cpu cycles a timer2 interrupt is generated, (compare2 +1)*8.
Obviously the used up cycles within the ISR should be less than these 1032 cycles.
Now, an getadc() alone does a double adc sample cycle, each one takes 13 adc clocks, which is prescaled by 32, ergo adc sampling takes a bit more than 2 * 13 * 32 = 832 cpu cycles. ISR entry and exit code will take some 120 or so cycles more, it tells you have 1032 - 832 - 120 = 80 cycles left for other code.
This "other code" consists out of loops within the ISR and therein multiple float operations with singles, which use up a true hell of cycles.
"Hell" means a few thousand, while you have less than 80 left.
Sure these cycles will be executed, but then the sample timing does not depend any more on timer2, instead on runtime of the ISR, which is much slower. At the end of an ISR already a new interrupt request is waiting, ISR follows ISR.
And that's one part of the reason, why it does not, and also won't work.
Other parts are flaws in logic and potential errors in the calculation scheme, but this doesn't matter, because already the used up cycles are far too much. |
|
Back to top |
|
|
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sat Jul 16, 2016 7:44 pm Post subject: |
|
|
I don't know the math, so I can't understand the algorithm
the author has deleted their posts after an argument with other users of the forum.
Mrshilov Http://Bascomavr.3bb.ru/Viewtopic.phpPrintId=550 |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sat Jul 16, 2016 8:00 pm Post subject: |
|
|
I don't know the exact reason why the user deleted his posts, all I can say is, that this code won't work, as the timing is already out of step. |
|
Back to top |
|
|
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sat Jul 16, 2016 8:07 pm Post subject: |
|
|
I see ...
thanks! |
|
Back to top |
|
|
EDC
Joined: 26 Mar 2014 Posts: 971
|
|
Back to top |
|
|
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sun Jul 17, 2016 12:21 pm Post subject: |
|
|
Hello EDC
thanks for the interesting idea! Dziękuję, panie!
I have a few questions:
1. my signals shorter than 50 ms, the usual length of 25-45 ms
2. I have two frequencies in one signal packet at a time, for example 700+900 Hz
ps
I understand that chip CMX823 cannot perceive two signals simultaneously? is this true ?
Last edited by Alexander-Dan on Sun Jul 17, 2016 12:25 pm; edited 2 times in total |
|
Back to top |
|
|
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sun Jul 17, 2016 12:24 pm Post subject: |
|
|
--- deleted |
|
Back to top |
|
|
MWS
Joined: 22 Aug 2009 Posts: 2262
|
Posted: Sun Jul 17, 2016 1:50 pm Post subject: |
|
|
Alexander-Dan wrote: | 2. I have two frequencies in one signal packet at a time, for example 700+900 Hz |
EDC's linked code is a simple frequency counter based on measured period and can't detect two or more overlaying tones.
That's what Goertzel can do, it detects one frequency out of a tone mix.
How about a FFT?
If you'd search this forum, you'll find several discussions.
Your tone frequencies are quiet evenly spaced, so I guess a FFT can be adapted.
I've experimented a few years ago with Goertzel, still some data left in the lower braincell-lairs.
That's why I still know some basics and also why extensive use of floats is a nogo while at limited computing power.
Even was able to find some code I wrote then, but I don't even know, if and how well it worked then, so I won't release it to the public.
It may give other user headaches in trying to make something work, which I'm not sure myself anymore, if I made it work.
For your 6 frequencies, I'd consider FFT a good choice. |
|
Back to top |
|
|
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sun Jul 17, 2016 8:55 pm Post subject: |
|
|
the problem is solved, but not completely: I took the program from Arduino for DTMF receiving and remade it for my task. Signals are received, but there are some unpleasant moments.
When the finish and test the program, then rewrite it for Bascom |
|
Back to top |
|
|
Meister
Joined: 27 May 2010 Posts: 319
|
|
Back to top |
|
|
Alexander-Dan
Joined: 13 Mar 2014 Posts: 111 Location: S.Posad
|
Posted: Sun Jul 17, 2016 10:27 pm Post subject: |
|
|
Thanks! |
|
Back to top |
|
|
|
|
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 You cannot attach files in this forum You cannot download files in this forum
|
|