ASPL User Guide v 1.00
© 2025 Bassem W. Jamaleddine


21. 5
   Finding the Beat Frequency of Two Waves

 

Finding the Beat Frequency of Two Waves

ELEMENTS-GROUPING-CLASS: TIE_OSCILLATORS_AREA_VARY_GROUP

Script To Locate Beats : wavesbeat.pl

GG-function: ggtieoscillatorsareavaryS()

Get the oscillating waves along their summed areas:

      W12 = ggtieoscillatorsareavaryS( .. )       where W12 is a set variable

Finding the Beat Frequency of Two Waves

●  Finding the Beat Frequency of Two Waves

Beats occur when two waves with slightly different frequencies interfere, creating a periodic fluctuation in loudness. The script wavesbeat.pl finds the beat frequency when two waves intersect. On lines 6 and 7, we set the frequency of the first wave to 4.9, and the frequency of the second wave to 5. Line 9 is a for-iterative-loop where we increment i by 0.02 up to 0.5, this will be the increment for the first wave frequency as shown on line 12. In the loop, we concatenate the the ASPL operations to find the intersection of the waves along their summed area. Finally on line 19, we run the script via ASPL to get the points of intersection where the oscillating functions intersect along their summed areas.

 -LIS- Listing. 21.5.1   [LISTING wavesbeat.pl][Script wavesbeat.pl]
(raw text)
1.     #!/usr/bin/perl
2.     use strict;
3.     
4.     my $interpreter = "aspl -groupingclass TIE_OSCILLATORS_AREA_VARY_GROUP 
      -wsname TRANSIENT -singlepass"; 
5.     
6.     my $frequency1 = 4.9;
7.     my $frequency2 = 5;
8.     my $s = "\n";
9.     $s .= "ks fx sumarea aelm\n";
10.    for (my $i=0; $i<=0.5; $i += 0.02) {
11.        $s .= "displayoff\n";
12.        my $freq1 = $frequency1 + $i;
13.        my $freq2 = $frequency2;
14.        $s .= "printblock INTERSECTION OF BOTH WAVES WHEN THEIR SUMMED AREAS ARE 
      THE SAME WITH freq1=$freq1 freq2=$freq2\n"; 
15.        $s .= "W12 = ggtieoscillatorsareavaryS(points,300, 
      frequency1,$freq1,frequency2,$freq2,roundfrac,1,aggregate,1)\n"; 
16.        $s .= "displayon\n";
17.        $s .= "gU,`ks=  W12\n";
18.    }
19.    open(ASPL, "| $interpreter -STDIN") or die "ERROR OPENING A PIPE TO aspl: $! 
      \n"; 
20.    print ASPL $s;
21.    close ASPL;

ASPL(C) 2025 Bassem Jamaleddine


The following two figures show some of the beat occurences. You can scroll over the output of the script to see all the points of intersection where the beats occured.
full view

Image File

 -FG- Fig. 21.5.1   [Figure: Finding the Beat Frequency of Two Waves: beat frequency located]
ASPL (C) 2025 Bassem Jamaleddine


full view

Image File

 -FG- Fig. 21.5.2   [Figure: Finding the Beat Frequency of Two Waves: another beat frequency located]
ASPL (C) 2025 Bassem Jamaleddine


viewme

 -TC- Display. 21.5.1   [Script output of wavesbeat.pl]
run for wavesbeat.pl




Reassigning the W12 over time causes to turn the variable into a differential group variable: the waves are changing over time along the slight variation of the frequency of the first wave. Therefore we can use the ASPL playop on the group union of the differential group variable W12 to find where the beats occured. The following script, wavesbeat2.pl, is an alternative script to the one shown above. Here on line LL the playop ...

 -LIS- Listing. 21.5.2   [LISTING wavesbeat2.pl][Script wavesbeat2.pl]
(raw text)
1.     #!/usr/bin/perl
2.     
3.     use strict;
4.     
5.     my $interpreter = "aspl -groupingclass TIE_OSCILLATORS_AREA_VARY_GROUP 
      -wsname TRANSIENT -singlepass"; 
6.     
7.     my $s = "\n";
8.     my $frequency1 = 4.9;
9.     my $frequency2 = 5;
10.    $s .= "ks fx sumarea aelm\n";
11.    $s .= "displayoff\n";
12.    for (my $i=0; $i<=0.5; $i += 0.02) {
13.        my $freq1 = $frequency1 + $i;
14.        my $freq2 = $frequency2;
15.        $s .= "W12 = ggtieoscillatorsareavaryS(points,300,frequency1,$freq1, 
      frequency2,$freq2,roundfrac,1,aggregate,1)\n"; 
16.    }
17.    $s .= "intermittentarc 1\n";
18.    $s .= "displayon\n";
19.    $s .= "playop  gU,`ks=  W12\n";
20.    open(ASPL, "| $interpreter -STDIN") or die "ERROR OPENING A PIPE TO aspl: $! 
      \n"; 
21.    print ASPL $s;
22.    close ASPL;

ASPL(C) 2025 Bassem Jamaleddine


viewme

 -TC- Display. 21.5.2   [Script output of wavesbeat2.pl]
run for wavesbeat2.pl