Speakers
WHAT IS IT?
This model simulates sound wave interference. There is one speaker at each end of a linear space; a sinusoidal signal generator powers each speaker. In the canvas, the yellow line represents the sound wave propagated from the left speaker, the cyan line represents the sound wave propagated from the right speaker, and the red line represents the sum of these sound waves.
HOW IT WORKS
Sound waves are longitudinal waves, propagated via pressure changes (compression and rarefaction) spatially and temporally. In this model, however, the waveforms are represented as transverse waves, consisting up of three lines of turtles. Each turtle acts as if it were connected to its neighboring turtles with springs. When neighboring turtles are further away, they exert a stronger force.
When the left end of the sound level goes up, it "pulls up" the turtle to its right, which in turn pulls up the turtle to its right, and so on. In that way, the wave is propagated.
The green turtles (speakers) continue to put more energy into the air. When there is no friction in the air, the waves in the air travel without losing amplitude.
HOW TO USE IT
Click the "Setup" button to set up the system. Then, click "Go!" to turn on the speakers.
The "Friction" slider controls the amount of sound damping in the air. The "Frequency" sliders controls the frequency of the signal generator. The "Amplitude" sliders controls the sound level of the speakers.
Click anywhere on the horizontal line between the speakers on the canvas and you will be able to observe the sound level vs. time at the position you selected. (White markers on the canvas indicate the position you have selected.)
THINGS TO NOTICE
How do the patterns of the waves emanating from the left and right speakers change when you change the "Frequency" sliders? How are they affected by changes to the "Amplitude" sliders?
When two speakers are turned on, the sound level at a certain point at a certain time is the sum of the sound levels produced by the two speakers at that time. This resulting pattern may be quite different from either of the speaker sound patterns.
THINGS TO TRY
Change the values on the sliders and observe what happens to the sum of the sound levels -- the red curve.
Try adding friction to see what it does to the waves.
Move the listening-point -- what do you observe in the plot window?
Try to create a "standing wave," in which some points on the lines do not move at all, and plot one of the points to see if the sum there is zero.
Try to create a flat red curve.
Compare the relationship between frequency and wavelength.
Find a way to measure the speed of the wave such that the relationship, speed = frequency * wavelength, is true.
EXTENDING THE MODEL
Program the red turtles to find the sum of the absolute values of the two waves.
Make it possible to "fix" the waves to zero at some point along the line -- as if this were a string and you put your finger on it.
Make the waves "reflect" from each end instead of going on.
STARLOGO FEATURES
In order to have three separate waves, three lines of turtles are created - yellow, cyan, and red - in order from left to right. Special turtles are created to control the ends of the first two waves: one end generates the wave (green) and the other end prevents the wave motion from wrapping (dark blue).
Since none of the turtles move laterally in this model, it is easy for the turtles to keep track of their neighbors. All of the turtles are created and placed on the canvas in order, and none are destroyed; thus, each turtle can locate it's neighbor to the left by using the turtle number one less than its own, while the neighbor to the right has the turtle number one more than its own.
In this model, it does not make sense for the turtles to "wrap" when they get to the top or bottom of the screen. So the y-coordinate of each red turtle is computed in a local variable (:ycor-new), and the turtle is hidden if this position moves outside the boundary of the screen.
During each iteration of the go procedure, each turtle looks at its neighbors and calculates a new speed and position accordingly. The order in which this is done is not obvious, since the turtles are running in parallel. In fact, it's important that the order in which the turtles look at their neighbors doesn't matter. Therefore a turtle variable, "ycor-old", contains the position of each turtle at the end of the previous iteration. Each turtle (besides the drivers at each end) looks at the value of this variable in the adjacent turtles, in order to update its own velocity and position. Then all the turtles update their states together.
The "no-display" and "display" commands are used to minimize the time required for (and the visual distraction of) initializing the turtles and canvas.
A TRUE STORY
A CCL member was asked by an undergraduate student to help her with some physics experiment problems:
The experiment was about wave propagation and interference. In the experiment, two speakers are put on a straight track one meter apart and facing each other. The speakers are connected to a 1500 Hz sinusoidal signal generator. The student is asked to use a microphone to measure the sound level along the track between the two speakers and write down the positions where the microphone readings are a minimum.
The student is asked to explain the results and to determine if the minimum readings should be zero or not.
The results of the experiment show that the average distance between two minimum readings is about one half of the wavelength. The CCL member could not explain the results and determine if the readings should be zero or not.
The ROPE sample model helped him to answer the student. In the rope model, one end of the rope is fixed. So the model setup is similar to the experiment setup except for the length and the frequency. The CCL member and the student then worked together to modify the rope model and change the meaning of the y coordinate -- changing it from representing the absolute value of the deflection, because the microphone reading is the root mean square value of the sound level. When they ran the program, they got the experimental results and, more importantly, it became very clear to them why the minimum readings should be zero and the distance between any two minima is one half of the wavelength.
Isn't it amazing that such a simple program can be so helpful?
Try and repeat what the student and CCL member did and answer the physical experiment problems.
CREDITS AND REFERENCES
To refer to this model in academic publications, please use: Wilensky, U. (1998). NetLogo Speakers model. http://ccl.northwestern.edu/netlogo/models/Speakers. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.
In other publications, please use: Copyright 1998 by Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/Speakers for terms of use.
This model was converted & modified for StarLogo v2.2 by Nick Bennett, Grass Roots Consulting (nickbenn@g-r-c.com), for use in an Acoustics section of the "Computer-based Exploration of the Science Behind the Headlines" course, at the Monte del Sol Charter School, Santa Fe, NM.
Turtle procedures
; The breeds in the model are "drivers" (which represent the waves' originating points),
; "slaves", which are the interior points of component waves; "anchors", which are the
; waves' terminating points; and "sums", which make up the points in the wave which is
; the interation between the two component waves.
breeds [
drivers
slaves
anchors
sums
]
; Each turtle in the interior of the component waves has a velocity, and a position at
; the end of the previous iteration.
turtles-own [
velocity
ycor-old
]
; Each turtle is placed along the line running horizontally through the middle of the
; canvas; the horizontal positon is determined by the turtle number - i.e. all turtles
; are placed along the line in order, from left to right. and wrapping around
; automatically.
to initialize :color
set color :color
set shape bubble-shape-color
set xcor (who - screen-half-width)
set velocity 0
set ycor-old 0
end
; Wave driver turtles have sinusoidal motion.
to drive
ifelse (who = 0) [
set ycor (amplitude-left * sin (0.2 * frequency-left * time-ticks))
] [
set ycor (amplitude-right * sin (0.2 * frequency-right * time-ticks))
]
end
; Each turtle in the interior of the component waves has a velocity, which is affected
; by the directed distances between the turtle and its neighbors, and attenuated by the
; friction parameter. After the velocity is updated, a new position is computed.
to follow :friction-scale
set velocity (velocity + (ycor-old-of (who - 1)) - ycor-old
+ (ycor-old-of (who + 1)) - ycor-old)
set velocity (velocity * (:friction-scale))
set ycor (ycor-old + velocity)
end
; Turtles at the terminating ends of the component waves simply move together with
; their neighbors. Since they end each iteration at the same Y position as their
; neighbors, they do not contribute to the velocity of their neighbors.
to anchor
ifelse (who = (screen-width - 1)) [
set ycor ycor-old-of (who - 1)
] [
set ycor ycor-old-of (who + 1)
]
end
; Turtles in the wave resulting from the interaction between the component waves simply
; update their position by computing the sum of the Y positions of the two turtles in
; the same column in the canvas - i.e. from the corresponding turtles in the component
; waves.
to sum
let [:ycor-new ((ycor-of (who - screen-width))
+ (ycor-of (who - (2 * screen-width))))]
ifelse ((round (abs :ycor-new)) <= screen-half-height) [
set ycor :ycor-new
showturtle
] [
hideturtle
]
end
; At the end of an iteration, each turtle records its current Y position, so that its
; neighbors can use this value for computing distances in the next iteration.
to refresh
set ycor-old ycor
end
Observer procedures
; Besides the sliders, the model keeps track of the current iteration/time
; count; the location of the listener; and the amplitude of the resultant wave
; form at the listener's location.
globals [
time-ticks
listening-point
listener-wave-value
]
; The setup procedure creates all of the turtles, and draws the center line,
; speakers, and listening point.
to setup
no-display
clear-all
set time-ticks 0
create-drivers-and-do 1 [
initialize green
]
create-slaves-and-do (screen-width - 2) [
initialize yellow
]
create-anchors-and-do 1 [
initialize blue
]
create-anchors-and-do 1 [
initialize blue
]
create-slaves-and-do (screen-width - 2) [
initialize cyan
]
create-drivers-and-do 1 [
initialize green
]
create-sums-and-do screen-width [
initialize red
]
draw-center-line
draw-speakers
draw-listening-point listening-point white
display
end
; At each iteration, the drivers update their positions (according to the sine
; function); then all of the interior turtles in the component waves are
; updated (in parallel); then, the terminal anchors of the component waves are
; updated; then, all of the turtles in the wave which is the result of the
; interaction between the two component waves are updates in parallel; finally,
; the current Y position of each turtle is saved, for use by its neighbors in
; the next iteration. After all turtles are updated, the listening point is
; checked for a change, and the value of the wave at that point is recorded.
to go
set time-ticks (time-ticks + 1)
let [:friction-scale ((1000.0 - friction) / 1000.0)]
ask-drivers [
drive
]
ask-slaves [
follow :friction-scale
]
ask-anchors [
anchor
]
ask-sums [
sum
]
ask-turtles [
refresh
]
update-listening-point
set listener-wave-value (ycor-of ((2 * screen-width)
+ screen-half-width + listening-point))
end
; The color for the listening point can be specified in a procedure parameter,
; to allow "undrawing" (i.e. drawing in the background color) when the
; listening position moves.
to draw-listening-point :position :color
stamp-at :position -1 :color
stamp-at :position 1 :color
end
; Before updating the value of the interaction wave at the listening point, the
; model checks for the user clicking the mouse in the neighborhood of the center
; line, between the speakers. If a click is detected, the previous listening
; point is erased, and a new one is drawn.
to update-listening-point
if ((mouse-down?)
and ((round (abs mouse-xcor)) < (round (0.9 * screen-half-width)))
and ((abs mouse-ycor) < 3)) [
draw-listening-point listening-point black
set listening-point (round mouse-xcor)
draw-listening-point listening-point white
]
end
; At setup, a gray line is drawn horizontally through the middle of the canvas.
to draw-center-line
ask-patches-with [ycor = 0] [
setpc gray
]
end
; The "speakers" are represented by orange lines, at opposite ends of the
; center line. Like the center line, the speaker patches serve no purpose,
; except (hopefully) to make clearer to the user what is going on in the
; simulation.
to draw-speakers
ask-patches-with [(abs xcor) = screen-half-width] [
if ((10 * (abs ycor)) < screen-half-height) [
setpc orange
]
]
ask-patches-with [(abs xcor) = (round (0.9 * screen-half-width))] [
if ((5 * (abs ycor)) < screen-half-height) [
setpc orange
]
]
end
; *** Model Copyright Notice ***
;
; This model was created as part of the project: CONNECTED MATHEMATICS:
; MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL
; MODELS (OBPML). The project gratefully acknowledges the support of the
; National Science Foundation (Applications of Advanced Technologies
; Program) -- grant numbers RED #9552950 and REC #9632612.
;
; Copyright 1998 by Uri Wilensky. All rights reserved.
;
; Permission to use, modify or redistribute this model is hereby granted,
; provided that both of the following requirements are followed:
; a) this copyright notice is included.
; b) this model will not be redistributed for profit without permission
; from Uri Wilensky.
; Contact Uri Wilensky for appropriate licenses for redistribution for
; profit.
;
; This model was converted to NetLogo as part of the project:
; PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN
; CLASSROOMS. The project gratefully acknowledges the support of the
; National Science Foundation (REPP program) -- grant number REC #9814682.
; Converted from StarLogoT to NetLogo, 2002. Updated 2002.
;
; To refer to this model in academic publications, please use:
; Wilensky, U. (1998). NetLogo Speakers model.
; http://ccl.northwestern.edu/netlogo/models/Speakers.
; Center for Connected Learning and Computer-Based Modeling,
; Northwestern University, Evanston, IL.
;
; In other publications, please use:
; Copyright 1998 by Uri Wilensky. All rights reserved. See
; http://ccl.northwestern.edu/netlogo/models/Speakers
; for terms of use.
;
; In January, 2006, this model was converted and modified for use with
; StarLogo v2.2, by Nick Bennett, Grass Roots Consulting.
;
; *** End of Model Copyright Notice ***
| Attachment | Size |
|---|---|
| Speakers.slogo | 55.84 KB |
