by [Theo Verelst] Using the Tcl/Tk package [Bwise], and some fundamental, tcl-coded, signal processing procedures, such as fourier transformation, I'll examplify the important signal processing concept of ''frequency modulation'' by making an Tk applet to play around with this modulation principle, known in radio engineering, wireless communication, modems, and sound synthesis, to mention a few fields. The interest comes mainly from two signal processing considerations (are the signal processing page leaders on holiday ?! ;) ), first, it is an overlooked principle/theorym which is of great value in many signal processing/analysis applications, also when tcl is used (as appears regulalrly on these pages), and second, I think it is a fun and interesting and relevant use of tcl/tk to examplify an important principle, which for me historically goes back to the advent of the Yamaha DX-7 synthesizer which is based on sine wave frequency modulation sound synthesis. When I was a second year electrical engineering student looking for a section to graduate in, I had just worked enough to buy a DX-7, and I had the schematic diagram of it, because I was very interested in what the chips (at the time competatively big and complicated ones) in that synthesizer worked like, and also how FM synthesis worked, so at the time I programmed a sample reproducer and FM program on the Atari ST. At the time, such programs were preferably compiled, but nowadays we can use Tcl and do things more or less in interaction time, and even make an interactive user interface in Tk on top. IMNSHO a very important, and protection-worthy use of a modern progamming language like tcl/tk. First, lets make a few one-liners to de signal frequency analysis, first a 256 (tcl-list) sample sinewave (three wavelengths are fitted in the list in this case, so a third harmonic): set twopi 2.0*3.1415926535 set r {}; for {set i 0} {$i < 256} {incr i} {lappend r [expr sin( 3.0 * $twopi*$i/256)] } To find a certain harmonic in the signal, we can use the well known [fourier] analysis, in this case in discrete form (multiplying the signal sample for sample with a certain harmonic component): set t 0.0; for {set i 0} {$i < 256} {incr i} {set t [expr $t+ [lindex $r $i] * sin( 3.0 * $twopi*$i/256)] } ; puts [ expr $t/([llength $r] /2.0)] The third harmonic returns a 'strength' of 1 (full amplitude), then the 3.0 above is replaced by 1.0 for fundamantal (1st harmonic) or another harmonic (smaller than 128) some number very close to zero (background numerical noise) is returned. I'd rather make an application which does something like this [http://82.168.209.239/Menu/jsmenu3.html] (Click on the left on Waveform Lab, Theory, View Applet, Making Wavews, Sine f=2) in tcl/tk, but I want to do other things first, and I don't know if something like it already exists. Lets first make sure we can get some of the important spectral lines from a [tcl]-list of samples, first, a fourier transform [proc] based on the above oneliner tries, and a filter for all components higher then 1e-10: proc fourier { {s} } { set r {} set twopi 2.0*3.1415926535 for {set j 0} {$j < [expr [llength $s]/2]} {incr j} { set t 0.0 for {set i 0} {$i < 256} {incr i} {set t [expr $t+ [lindex $s $i] * sin( $j * $twopi*$i/256)] }; lappend r [ expr $t/([llength $s] /2.0)] } return $r } set i 0; foreach j [fourier $r] {if {[expr abs($j)] > 1e-10} {puts "$i $j"} ; incr i} I've used the signal from list r, which can contain any number of samples with harmonics of a multiple of largest wave which fits in the interval, up to half te number of samples -1. Note that I've not used an FFT ([Fast Fourier Transform], but just a convolution of the signal wil each of the possible harmmonics in the interval seperately. Lets try a signal with more components before we plot it and the discrete fourier transform result in a Tk canvas, and compare the result with the target: FM modulates signals, which we'll also store in [tcl] lists, as sampled signals. ([TV] aug 10, 2004, 19:47 Ooops, (local) power outage in Amsterdam, I'll see what I can do right now, might be I have to get some car power as soon as the notebook is running out of current... For the moment, mind that my images on the wiki are served from a not completely up to date server, though most is there. 20:01, ok all data should be served in latest version again!)