An Audio Phase-Locked-Loop (PLL) Block

Status
Not open for further replies.

DerekR

Well-known member
I'm pleased to post a new Audio Block that implements a real-time phase-locked-loop for use with the Teensy Audio Board. The necessary files are contained in the AudioPLL.zip file here: View attachment AudioPLL.zip

What is a PLL? Well, they are found everywhere in modern electronics. They are a feedback control system, but with a special purpose. They have an in-built frequency synthesizer that is "locked" to an external waveform in frequency and phase, by a feedback loop that continuously measures the instantaneous phase difference between the two signals, and modifies the synthesizer so as to reduce the phase difference to zero, thus locking the two signals together. They are most common in high frequency rf communications work.

The AudioPLL block works at audio frequencies, currently from less than 100Hz to about 12kHz, and over a >40dB range in the reference level. Further tweaking of the loop filter should extend the upper frequency limit. Internally the algorithms use quadrature processing, and a Hilbert Transformer is used to convert from the single input channel to quadrature.

These can be tricky little devils to understand, so I've put a bit of effort into comments in the code. In addition I've included a document that describes some of the issues in the designing analog hardware PLLs, it may help understand the concepts.

The necessary files are included in AudioPLL.zip, as well as another block, AudioSerialPlotter, that will let you view the output on the Arduino Serial Plotter. The set up is simple - here is the attached sketch included:
Code:
//------------------------------------------------------------------------------
// Simple test sketch for AudioPLL phase-locked-loop audio block
//
// 
// D. Rowell      Sept 20,2017
//------------------------------------------------------------------------------
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "AudioPLL.h"
#include "AudioSerialPlotter.h"
//
AudioSynthWaveformSine   ReferenceInput;
AudioPLL                 PLL;
AudioSerialPlotter       Plotter;
AudioOutputI2S           myOutput;
AudioControlSGTL5000     audioShield;
//
AudioConnection c2(ReferenceInput,0, PLL,0);
AudioConnection c3(PLL,0,            Plotter,0);    // Plot outputs on Arduino SerialPlotter
AudioConnection c4(PLL,1,            Plotter,1);    // (or view on SerialMonitor :-) )
//

//----------------------------------------------------------------------------
void setup() {
   Serial.begin(57600); while(!Serial){};
   audioShield.enable();
   AudioMemory(20);
   audioShield.inputSelect(AUDIO_INPUT_LINEIN);
  //
   float frequency = 500;
   float amplitude = 0.5;
   ReferenceInput.frequency(frequency);  
   ReferenceInput.amplitude(amplitude);
   PLL.enable();
//  PLL.analysisOutputs();      // Output synthesized output + frequency
   PLL.quadratureOutputs();     // Output quadrature outputs
// Plotter.disable();
}

//----------------------------------------------------------------------------------
void loop() {
  // Switch frequency every 3 secs.
  ReferenceInput.frequency(200.);  
  delay(3000);
  //
  ReferenceInput.frequency(1500.);  
  delay(3000);
}

The block processing time is 330 usec on a Teensy 3.6 at 180 MHz.

Ongoing work includes generating a waveform that is related to, but not identical to, the reference. For example - a waveform that is offset from the reference frequency by a constant, or an arbitrary multiple of the reference (eg an integer harmonic or subharmonic, or a fractional factor).
PLLs can also be used to find and report (with sub-Hz) accuracy the frequency of the reference. The AudioPLL has a function myFrequency = myPLL.getFrequency that returns a float, BUT it can also stream the running frequency estimates as an int16() in Hz through the channel 1 output. by setting myPLL.analysisOutputs(), while if you set myPLL.quadratureOutputs() Channels 0 and 1 will contain the two synthesizer waveforms, that is cos(wt) and sin(wt).

Comments, criticisms, suggestions etc are all welcome

Derek
 
Great job. Thanks alot Derek. I have gone through with all your codes and read the Analog PLL design document as well.
You have done a great effort on writing comments. It will explain well about how things work. You have a really good explanation ability. Firstly when i read the code comments i didn't understood much. But now i can understand well after gone through with lot of theoretical stuff.
Your PLL code block will be really useful on Software Defined Radio (SDR) systems.
I have attached two documents which helped me to understand about digital PLL

Anyway this software phase lock loop block can be use on my project. Once you have told me

can use set of software phase-locked-loop (PLL's) to lock on to the fundamentals and overtones and track their frequencies exactly in real-time

Could you please explain this more. Then i can check your PLL block for fundamentals and overtones. So since I'm using microphone signals i can set the adc output into PLL input(reference) right? To set the fundamental frequency and adjust bandwidth, need to change the parameters of the filter right? Since i really don't know how to change filter parameters you could help me with that. For analysis i guess i can use "PLL.analysisOutputs();" Also how to identify whether pll get locked?
Thank you
 

Attachments

  • digital pll's part1.pdf
    648.2 KB · Views: 339
  • digital pll's part 2.pdf
    696.2 KB · Views: 399
Last edited:
Why don't you simply play your .wav file through the PLL, watch the output on the Serial Monitor and report back here what happens.
 
This are some of the results. I can't understand the pattern. But seems like its trying to give some valuable information

Code:
32767 , 0
31586 , -3782
23760 , -3104
13998 , -2090
6238 , -1419
986 , -849
-1803 , -347
-2705 , -40
-2636 , 68
-2348 , 53
-2122 , 41
-1997 , 10
-1934 , 14
-1878 , 9
-1890 , -16
-1916 , 5
-1872 , 13
-1796 , 17
-1740 , 6
-1696 , 10
-1659 , 5
-1627 , 8
-1583 , 9
-1533 , 10
-1502 , 1
-1483 , 6
-1445 , 9
-1395 , 12
-1357 , 4
-1326 , 8
-17354 , -7278
-27461 , 1160
-31617 , -5535
-32712 , 2606
-32700 , -4293
-25777 , -4168
-13479 , -2593
-3774 , -1739
2460 , -938
5347 , -308
6077 , -9
21558 , -7455
30186 , 1087
32654 , -5545
32545 , 2762
32057 , -4056
23446 , -3881
10539 , -2718
175 , -1805
-6066 , -884
-3112 , 2162
11787 , 4339
26491 , 3716
32469 , 3230
31652 , 2326
27552 , 2033
21783 , 1782
15323 , 1595
8751 , 1441
2666 , 1209
-2611 , 1054
-6688 , 712
-9368 , 472
-10296 , -55
-9349 , -370
-7112 , -620
-4398 , -561
-2191 , -389
-1100 , -80
-1282 , 158
-2504 , 364
-4454 , 475
-6946 , 608
-9806 , 659
-12921 , 763
-16151 , 782
-19387 , 871
-22502 , 868
-25392 , 950
-27931 , 931
-30031 , 1013
-31589 , 986
-32523 , 1071
-32753 , 1042
-32217 , 1133
-30861 , 1109
-28629 , 1209
-25487 , 1199
-21418 , 1311
-16363 , 1349
-10356 , 1478
-3194 , 1665
4919 , 1820
15815 , 3137
30417 , 6500
32659 , -2282
28782 , -3586
19744 , -2393
11121 , -1825
4179 , -1241
-1081 , -1017
-4709 , -545
-6848 , -386
-7706 , 9
-7479 , 88
-6553 , 317
-5044 , 337
-3250 , 436
-1119 , 477
1224 , 526
3873 , 612
6681 , 605
9727 , 743
12851 , 683
16090 , 864
19305 , 775
22488 , 997
25450 , 871
28184 , 1180
30456 , 1032
32118 , 1474
32766 , 1343
31818 , 2020
28136 , 2150
20757 , 2719
8853 , 3072
-4653 , 2772
-16770 , 2773
-25546 , 2237
-30631 , 2167
-32630 , 1653
-32435 , 1619
-30871 , 1187
-28422 , 1326
-25232 , 1077
-21081 , 1451
-14950 , 1709
-5732 , 2476
10038 , 4366
26363 , 4390
32737 , 3965
29284 , 3142
20873 , 2684
10973 , 2220
1664 , 1863
-6393 , 1608
-13031 , 1377
-18370 , 1238
-22734 , 1172
-26262 , 1116
-29049 , 1132
-31081 , 1098
-32325 , 1121
-32765 , 1097
-32391 , 1117
-31207 , 1105
-29251 , 1110
-26540 , 1125
-23152 , 1114
-19163 , 1132
-14659 , 1126
-9776 , 1133
-4647 , 1124
615 , 1139
5861 , 1122
10931 , 1129
15715 , 1120
20064 , 1109
23885 , 1108
27095 , 1095
29634 , 1100
31445 , 1091
32489 , 1085
32756 , 1086
32243 , 1073
30978 , 1075
28981 , 1082
26303 , 1075
23003 , 1081
19147 , 1083
14854 , 1073
10212 , 1083
5304 , 1085
257 , 1089
-4815 , 1091
-9776 , 1093
-14496 , 1089
-18879 , 1098
-22806 , 1090
-26171 , 1090
-28907 , 1090
-30928 , 1070
-32214 , 1077
-32748 , 1048
-32539 , 1059
-31611 , 1028
-30028 , 1012
-27842 , 1004
-25131 , 980
-21996 , 962
-18521 , 937
-14788 , 923
-10909 , 887
-6965 , 872
-3050 , 828
753 , 803
4378 , 755
7760 , 721
10824 , 648
13570 , 619
15969 , 533
18009 , 490
19754 , 425
21186 , 360
22377 , 324
23384 , 280
24270 , 271
25086 , 261
25896 , 292
26727 , 305
27607 , 371
28543 , 407
29505 , 483
30454 , 529
31319 , 589
32039 , 638
32542 , 681
32760 , 729
32631 , 767
32101 , 795
31143 , 813
29709 , 863
27795 , 861
25391 , 911
22501 , 908
19183 , 939
15418 , 964
11298 , 973
6871 , 1003
2259 , 996
-2479 , 1038
-7241 , 1027
-11863 , 1046
-16249 , 1038
-20287 , 1051
-23860 , 1028
-26965 , 1091
-29448 , 1020
-31241 , 1052
-32345 , 997
-32761 , 1024
-25893 , 8468
6822 , 7274
29198 , 5226
32434 , 3380
27791 , 2462
21326 , 1805
15583 , 1186
11033 , 951
6994 , 850
3061 , 857
-955 , 865
-4982 , 869
-8975 , 883
-12863 , 887
-16526 , 872
-19949 , 896
-23080 , 887
-25829 , 888
-28185 , 906
-30090 , 896
-31526 , 943
-32441 , 953
-32766 , 988
-32435 , 1048
-31374 , 1062
-29434 , 1215
-26308 , 1367
-21469 , 1689
-13679 , 2295
-1075 , 3291
16073 , 4369
29631 , 4296
32509 , 3655
26996 , 3048
17835 , 2467
8599 , 1886
1111 , 1367
-4622 , 1095
-9374 , 992
-13651 , 968
-17546 , 933
-21047 , 929
-24142 , 907
-26783 , 896
-28956 , 887
-30644 , 871
-31838 , 860
-32545 , 857
-32765 , 846
-32508 , 846
-31782 , 838
-30609 , 834
-29005 , 834
-26997 , 833
-24608 , 834
-21869 , 836
-18822 , 834
-15507 , 834
-11968 , 837
-8266 , 832
-4454 , 836
-597 , 823
3255 , 829
7043 , 817
10706 , 814
14190 , 801
17444 , 793
20423 , 775
23111 , 767
25470 , 744
27494 , 733
29184 , 714
30522 , 685
31527 , 669
32219 , 638
32622 , 617
32764 , 593
32670 , 573
32369 , 542
31885 , 534
31232 , 515
30428 , 508
29474 , 504
28364 , 511
27085 , 519
25615 , 541
23936 , 560
22023 , 593
19849 , 619
17401 , 658
14653 , 694
11622 , 724
8326 , 759
4789 , 790
1042 , 823
-2843 , 844
-6805 , 875
-10748 , 880
-14591 , 908
-18277 , 920
-21672 , 919
-24733 , 945
-27379 , 935
-29553 , 959
-31210 , 968
-32289 , 973
-32751 , 1004
-32557 , 1008
-31657 , 1067
-29981 , 1102
-27464 , 1165
-23890 , 1319
-19108 , 1411
-12696 , 1744
-3687 , 2260
8575 , 3042
22967 , 4146
32206 , 4409
30074 , 3918
19644 , 3382
6362 , 2904
-6406 , 2602
-16873 , 2230
-24496 , 2031
-29500 , 1845
-32127 , 1699
-32735 , 1689
-31505 , 1610
-28635 , 1610
-24304 , 1586
-18760 , 1588
-12341 , 1549
-5348 , 1572
1965 , 1572
9222 , 1591
16151 , 1639
22400 , 1693
27672 , 1859
31410 , 2023
32757 , 2344
30363 , 2748
22796 , 3096
10152 , 3285
-4995 , 3287
-18568 , 3025
-27700 , 2659
-32023 , 2261
-32679 , 1763
-31286 , 1440
-28856 , 1254
-25738 , 1186
-22042 , 1141
-17878 , 1114
-13354 , 1097
-8576 , 1079
-3600 , 1093
1438 , 1070
6472 , 1105
11398 , 1091
16035 , 1100
20311 , 1109
24082 , 1095
27262 , 1109
29770 , 1098
31531 , 1085
32523 , 1069
32750 , 1062
32241 , 1035
31053 , 1009
29253 , 994
26907 , 970
24082 , 965
20883 , 924
17433 , 902
13815 , 864
10176 , 813
6644 , 753
3380 , 663
546 , 554
-1621 , 375
-2868 , 160
-2893 , -149
-1477 , -457
1224 , -698
4739 , -814
8283 , -735
11227 , -587
13226 , -335
14151 , -100
14060 , 145
12937 , 383
10860 , 572
7943 , 733
4390 , 818
402 , 898
-3855 , 930
-8157 , 947
-12411 , 976
-16504 , 982
-20316 , 996
-23770 , 1009
-26761 , 1013
-29214 , 1025
-31065 , 1029
-32257 , 1036
-32752 , 1036
-32535 , 1039
-31606 , 1040
-29989 , 1035
-27713 , 1044
-24836 , 1032
-21413 , 1046
-17525 , 1029
-13291 , 1031
-8776 , 1027
-4105 , 1017
596 , 1001
5223 , 992
9655 , 961
13764 , 927
17492 , 894
20576 , 732
22967 , 642
24244 , 146
23071 , -873
14630 , -3596
-1426 , -3515
-14010 , -2076
-20415 , -1165
-23390 , -552
-24228 , 29
-23359 , 511
-21014 , 856
-17552 , 984
-13485 , 997
-9114 , 1001
-4553 , 999
56 , 984
4658 , 994
9173 , 988
13513 , 997
17582 , 988
21301 , 997
24603 , 992
27416 , 1001
29689 , 1003
31357 , 999
32389 , 1005
32763 , 1019
32453 , 1020
31454 , 1029
29759 , 1047
27385 , 1054
24357 , 1074
20723 , 1079
16536 , 1106
11892 , 1108
6884 , 1136
1608 , 1148
-3793 , 1170
-9192 , 1195
-14445 , 1223
-19392 , 1258
-23834 , 1287
-27615 , 1351
-30518 , 1397
-32302 , 1467
-32733 , 1541
-31577 , 1615
-28689 , 1666
-24014 , 1762
-17694 , 1778
-10177 , 1797
-1959 , 1798
6219 , 1724
13810 , 1704
20345 , 1594
25501 , 1524
29273 , 1466
31637 , 1382
32686 , 1336
32549 , 1252
31412 , 1186
29499 , 1086
27095 , 976
24378 , 914
21652 , 732
19407 , 504
18172 , 142
18297 , -205
20159 , -779
23402 , -1086
26857 , -1233
29543 , -1052
31130 , -770
31885 , -424
32140 , -87
32069 , 236
31664 , 514
30801 , 724
29336 , 869
27275 , 898
24669 , 942
21553 , 949
18009 , 959
14072 , 980
9805 , 986
5391 , 959
935 , 961
-3356 , 880
-7345 , 854
-10998 , 778
-14106 , 666
-16591 , 539
-18422 , 390
-19629 , 246
-20263 , 96
-20326 , -61
-19904 , -166
-19169 , -224
-18298 , -228
-17594 , -131
-17301 , -14
-17578 , 156
-18588 , 364
-20233 , 510
-22351 , 685
-24733 , 786
-27061 , 848
-29167 , 922
-30889 , 945
-32102 , 1003
-32713 , 1034
-32622 , 1075
-31758 , 1102
-30080 , 1129
-27557 , 1174
-24207 , 1186
-20079 , 1223
-15246 , 1244
-9830 , 1273
-3924 , 1320
2290 , 1347
8575 , 1388
14726 , 1439
20463 , 1487
25474 , 1548
29433 , 1617
31980 , 1688
32754 , 1765
31452 , 1851
27890 , 1919
22170 , 1945
14636 , 1989
5898 , 1971
-3125 , 1911
-11658 , 1855
-19011 , 1728
-24778 , 1622
-28916 , 1518
-31468 , 1394
-32635 , 1320
-32622 , 1242
-31613 , 1180
-29758 , 1145
-27189 , 1106
-23997 , 1095
-20287 , 1070
-16168 , 1060
-11711 , 1052
-7051 , 1034
-2291 , 1028
2447 , 1004
7080 , 1004
11522 , 982
15671 , 974
19483 , 965
22868 , 942
25800 , 939
28244 , 923
30171 , 915
31567 , 899
32427 , 892
32760 , 900
32564 , 880
31848 , 894
30643 , 860
28990 , 867
26907 , 854
24445 , 849
21628 , 852
18546 , 823
15222 , 840
11716 , 810
8077 , 826
4322 , 814
502 , 828
-3362 , 832
-7222 , 846
-11051 , 864
-14794 , 884
-18381 , 902
-21766 , 937
-24864 , 958
-27560 , 977
-29789 , 1015
-31460 , 1039
-32473 , 1060
-32759 , 1095
-32258 , 1102
-30940 , 1129
-28789 , 1151
-25813 , 1179
-22024 , 1209
-17477 , 1242
-12271 , 1268
-6559 , 1292
-465 , 1338
5725 , 1327
11816 , 1386
17582 , 1388
22684 , 1396
26946 , 1427
30141 , 1413
32105 , 1421
32766 , 1420
32083 , 1425
30082 , 1428
26814 , 1447
22363 , 1463
16867 , 1493
10492 , 1524
3492 , 1555
-3855 , 1600
-11204 , 1645
-18083 , 1665
-24053 , 1701
-28701 , 1712
-31672 , 1718
-32762 , 1726
-31915 , 1674
-29282 , 1653
-25099 , 1615
-19689 , 1587
-13417 , 1541
-6701 , 1490
144 , 1464
6853 , 1433
13117 , 1392
18769 , 1389
23595 , 1335
27467 , 1336
30326 , 1307
32074 , 1260
32756 , 1280
32382 , 1217
31033 , 1219
28816 , 1160



And i'm reading .wav file from sd card. I modified the code to read sd .wav

Code:
//------------------------------------------------------------------------------
// Simple test sketch for AudioPLL phase-locked-loop audio block
//
// 
// D. Rowell      Sept 20,2017
//------------------------------------------------------------------------------
#include <Audio.h>
#include <Wire.h>
#include <SPI.h>
#include <SD.h>
#include <SerialFlash.h>
#include "AudioPLL.h"
#include "AudioSerialPlotter.h"
//
AudioSynthWaveformSine   ReferenceInput;
AudioPlaySdWav           playSdWav1;
AudioPLL                 PLL;
AudioSerialPlotter       Plotter;
AudioOutputI2S           myOutput;
AudioControlSGTL5000     audioShield;
//
AudioConnection c2(playSdWav1,0, PLL,0);
AudioConnection c3(PLL,0,            Plotter,0);    // Plot outputs on Arduino SerialPlotter
AudioConnection c4(PLL,1,            Plotter,1);    // (or view on SerialMonitor :-) )
//
// Use these with the Teensy Audio Shield
#define SDCARD_CS_PIN    10
#define SDCARD_MOSI_PIN  7
#define SDCARD_SCK_PIN   14

// Use these with the Teensy 3.5 & 3.6 SD card
//#define SDCARD_CS_PIN    BUILTIN_SDCARD
//#define SDCARD_MOSI_PIN  11  // not actually used
//#define SDCARD_SCK_PIN   13  // not actually used

// Use these for the SD+Wiz820 or other adaptors
//#define SDCARD_CS_PIN    4
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13

// Use these with the Teensy Adaptor
//#define SDCARD_CS_PIN    10
//#define SDCARD_MOSI_PIN  11
//#define SDCARD_SCK_PIN   13
//----------------------------------------------------------------------------
void setup() {
   Serial.begin(57600); while(!Serial){};
   audioShield.enable();
   audioShield.volume(0.5);
   SPI.setMOSI(SDCARD_MOSI_PIN);
   SPI.setSCK(SDCARD_SCK_PIN);
   if (!(SD.begin(SDCARD_CS_PIN))) {
    while (1) {
      Serial.println("Unable to access the SD card");
      delay(500);
    }
  }
   AudioMemory(20);
   audioShield.inputSelect(AUDIO_INPUT_LINEIN);
  //
//   float frequency = 500;
//   float amplitude = 0.5;
//   ReferenceInput.frequency(frequency);  
//   ReferenceInput.amplitude(amplitude);


//  playSdWav1.play("FE55L.WAV");  
  playSdWav1.play("FE55M.WAV");
//  playSdWav1.play("FE55LW.WAV");
//  playSdWav1.play("FE53L.wav");
//  playSdWav1.play("FE53M.WAV");
//  playSdWav1.play("FE53LW.WAV");
//  playSdWav1.play("FE52L.WAV");
//  playSdWav1.play("FE52M.WAV");
//  playSdWav1.play("FE52LW.WAV");
//  playSdWav1.play("FE49L.WAV");
//  playSdWav1.play("FE49M.WAV");
//  playSdWav1.play("FE49LW.WAV");
//  playSdWav1.play("FE47L.WAV");
//  playSdWav1.play("FE47M.WAV");
//  playSdWav1.play("FE47LW.WAV");
//  playSdWav1.play("FE46L.WAV");
//  playSdWav1.play("FE46M.WAV");
//  playSdWav1.play("FE46LW.WAV");

  PLL.enable();
  PLL.analysisOutputs();      // Output synthesized output + frequency
//   PLL.quadratureOutputs();     // Output quadrature outputs
// Plotter.disable();
}

//----------------------------------------------------------------------------------
void loop() {
  // Switch frequency every 3 secs.
//  ReferenceInput.frequency(350.);  
//  delay(3000);
  //
//  ReferenceInput.frequency(1500.);  
//  delay(3000);
}

.wav file if needed
 

Attachments

  • Female55_Mid.zip
    312.9 KB · Views: 151
Last edited:
The documentation will tell you what the two channels on the Serial Monitor output are in "analysis" mode: the first is the output waveform from the synthesizer, the second is the instantaneous frequency (dPhase/dt) in Hz, reported at 44.1ksamples/sec. Now I have absolutely no idea what is actually on your files - or its integrity/validity, so I can't interpret the data.

I did make several spot checks where I compared the indicated frequency (column 2), and the period (in samples) of the osc. output, and that all seems to make sense. However, the indicated frequency seems to be changing very fast, so I question whether the PLL is failing to lock, OR whether there is anything in the data to lock on to? It would be much better to look at the graphical output on the Serial Plotter instead of the numbers on the Monitor. The big question is: what do we really expect to see? Only you can answer that.

What you really need to do is find a way of plotting your raw .wav data right on top of the PLL synthesizer output (allowing for processing loop delays) so you can see directly whether the PLL frequency is following the input signal. You could do it on a 'scope, or on the Serial Plotter. It would be very easy to do, but I don't have time to do it just now. Maybe in a few days...
 
@Wicky21
I just took a look at your data. I think it might not be quite as you imagine it! It might be quite interesting from an entomological point of view :D but this particular data set is DEFINITELY NOT suited to FFT type spectral analysis! Remember that FFT's rely on the fact that there are NO changes in the spectral content, or time-domain statistics, within the data record. Otherwise the results are simply garbage! And that is what I assert is probably happening with your analysis, at least in this particular record. (I think it is an interesting question as to what is happening acoustically - are you REALLY seeing the wing beat frequency, or just acoustic non-linear effects of micro-turbulence and flexural dynamics of the wing membrane generating acoustic energy at random frequencies. I, of course, have no idea;) )

I read Female55_Mid.wav into MATLAB, and plotted out segments in 1000 sample blocks. What I see is that there are many, many very short data segments with obviously different spectral characteristics, and sudden switches between them. For example, here is a plot of samples 117300 - 118300:
Buzz.png
Note that 1000 samples represents just 1/44.1 secs (or 22.7 msec) of data. There is an apparent sudden switch in the center of the plot, where the lower frequency on the left computes to a period of (533-40)/9 samples, or a frequency of 805 Hz, while on the right hand side it looks almost like its second-harmonic, with a period of (982-533)/16 samples, or a frequency of 1571 Hz. My quick look through your data shows this sort of thing happening over and over. This will completely mess up any FFT analysis... No wonder your Audacity spectrum was so wide.

These frequencies I see here are also much higher than you have suggested in earlier posts.

I also think that this is what I see happening in the PLL output data you posted - sudden jumps in frequency in the same broad frequency band of 500-1500 Hz.

BUT what is clear is that if this particular .wav file is typical, then the mosquito data is NOT suitable for FFT type spectral analysis to determine wing beat frequency because it is not statistically "stationary". You will always get numbers out, but you must ask yourself if those numbers mean anything.
 
Last edited:
The main reason im using PLL is to identify the presence of a species and start to record when PLL get lock.(lock in the sense just trigger. No need to keep lock for a long time) Once I have done hardware PLL by using LM567. In that case I made center freq around 850Hz which has the highest amplitude of the signal after analysing spectrogram. In that case when I play the .wav file through my mobile it recognized. (As a output I only used led and it blinks until .wav is over) So this hardware PLL can only used on one center frq with limited bandwidth. So what if I use 2 or 3 Software PLL' s and identify at the same moment from each PLL gives some threshold outputs. Let's say PLL1 set threshold something like 800-890, PLL2 set threshold something like 1100-1200 like wise and check each PLL gives output at the same moment. If it gives output same moment then I can trigger hardware to start recording the sound into SD card for further analysing. What about that approach? I'm trying to use some mechanism to identify the presence.
(Also Derek check your inbox I PM you regarding STFT. If you have time read that and rply back. )
 
The audio library offers a FFT1024 object so you can analyze all frequencies at once. I would think that would offer the greatest flexibility when you are interested in more than one frequency.
 
The audio library offers a FFT1024 object so you can analyze all frequencies at once. I would think that would offer the greatest flexibility when you are interested in more than one frequency.

Yes im using FFT1024 for further analysis of samples. But rather than that thought about other mechanisms something like PLL for real time capturing frequencies. Without high end of processing.
 
I was very curious to see how my AudioPLL block actually did on tracking the mosquito wing data, so I modified it to stream the input data and the synthesizer output to the Serial Plotter, and recorded the output from Female55_mid.zip. As I found from my quick scan in MATLAB above, that input file is a complete mess with large frequency jumps all over the place. A sample PLL output is shown here:

Wick21.jpg

The blue line is from the raw input file, the red is the PLL synthesizer output. Again we see a large frequency jump, this time downwards, halfway through this 500 sample segment. As far as I am concerned, the PLL has done a remarkable job of tracking the phase in this data file. Remember, we don't expect the traces to overlay one another, 1) because the synthesizer is a fixed amplitude device (in steady-state), and 2) we expect the dynamics of the PLL loop-filter (feedback controller) to cause transient phase errors during phase transients in the input. I was delighted to see how well it did on a wonky waveform.

A quick estimate on the frequency on the lefthand side shows 8 periods in approx 210 samples, which comes out as 1680 Hz at a sampling frequency of 44.1kHz. On the righthand side it's anybody's guess what is going on...

BTW - in order to look at more data in a single screen, I have modified AudioSerialPlotter to just display every nth output to the screen, I didn't use it on the above plot but it was very handy in looking at the data in real time. I'll publish it soon.
 
Impressive. Keep remember all this recordings were made at noisy background.
Here i attached another sample file. Its a different species .wav file. Can check both of .wav files have the same typical characteristics.
Anyway i hope your PLL block can be used to identify the frequencies right?

I mean just to capture the presence of a mosquito. Because i really needed to use your PLL on my project. I only needed to trigger the teensy to start record. At the end of the recording By using Short Time Fourier Transformation and peak analysis method can extract more information. Something like What are the exact frequency value of fundamental and harmonics. As well as the what are the Amplitude values of the each harmonics. Then i can take amplitude ratios between maximum peak harmonic to other harmonic and check whether is there any pattern.
But i have to wait until you release your next Multiple peak detection block
Once you have told me

"To-do" list
1) Report the magnitude (and possibly phase) of the peaks when they lie between lines. I have already written code (for another project) to do interpolation between spectral lines using Whittaker (cardinal) interpolation, and I just need to incorporate that.
2) Investigate the use of the Hilbert transform to produce an analytic signal, which hopefully should minimize image reflection from the negative frequency components at very low frequencies. (I also have the transform code, from yet another project)
3) Include a detection threshold to prevent noise peaks from being included.

BTW: What i understand was Fundamental peak cannot detect exactly by using amplitude detection method. But for duffy's noteFreq block it can capture well the fundamental. So no problem about fundamental. But Derek your multiple peak detection block can be used to identify the maximum amplitude harmonics. Since harmonics have the higher amplitudes.(refer to PM STFT i have explained it more)
 

Attachments

  • Female53_Mid.zip
    283.1 KB · Views: 132
Last edited:
BTW - in order to look at more data in a single screen, I have modified AudioSerialPlotter to just display every nth output to the screen, I didn't use it on the above plot but it was very handy in looking at the data in real time. I'll publish it soon.

Publish it soon. Anyway i have to do more experiments with species and recordings. Actually at research labs we'r capturing wing beat sound by trapping mosquito's inside a cage. By using Doppler optical or ultrasonic measurements of reflections off of the wings. Sampling around 96KHz. So what i have attached .wav files were, i just played the recorded wav files at research labs through speaker and by using Leons microphone board again i recorded through teensy at 3 different sound levels. Maybe there are some issues. I have to put the microphone inside the cage and should get some recordings.

Anyway as i felt your PLL block is perfectly works right? Also if i input some square wave pulse it should detect fundamental and harmonic as well right? So i have another question since PLL block can identify fundamental and harmonics at which time filter parameters should change?
 
Last edited:
Ongoing work includes generating a waveform that is related to, but not identical to, the reference. For example - a waveform that is offset from the reference frequency by a constant, or an arbitrary multiple of the reference (eg an integer harmonic or subharmonic, or a fractional factor).

How is this going? I would like to experiment with using phased lock loops to reinforce a frequency with an arbitrary offset, was planning a hardware logic approach but I wonder if a software approach would work...
 
Status
Not open for further replies.
Back
Top