```python
import ipywidgets as widgets
#https://towardsdatascience.com/bring-your-jupyter-notebook-to-life-with-interactive-widgets-bc12e03f0916
from IPython.display import display

#Have a table to compare when the best time to use radar vs ultrasound (cross reference on the slides)
speed_of_ultrasound_m_per_sec={ 'tissue':1540, #In most tissue
                                'water':1481, 
                                'air': 343
                              }
speed_of_light_m_per_sec={ 'air': 299792458 
                              }  
```

Our goal is to understand the effect of the speed of a wave on how far it travels and how that influences how many computation 

If we define the time the wave is traveling as:

\begin{equation}
\Delta t=t_{end}-t_{start}
\end{equation}

We can find the distance the wave travels given we know its speed (c) 
\begin{equation}
	d=c\Delta t
\end{equation}

This means for a round trip time
\begin{equation}
	d=\frac{c}{2}\Delta t
\end{equation}

The two types of waves we will be examining are ultrasound and radio waves. In air ultrasound has a  speed of:
\begin{equation}
c_{ultrasound}=343 \frac{m}{s}
\end{equation}

while radio waves have a speed of:
\begin{equation}
c_{light}=299,792,458 \frac{m}{s}
\end{equation}

Below find the time it would take for an ultrasound wave to travel 10 meters (+/- 1m). Compare this distance with the distance radio waves would travel. What is the ratio of the difference?


```python
from ipywidgets import Layout
style = {'description_width': 'initial'}

time_traveled_output = widgets.Output()
time_traveled_slider = widgets.IntSlider(
    min=1,
    max=100,
    step=10,
    description='Time traveled (milliseconds):',
    value=3,
    layout=Layout(width='auto', height='80px'),
    style=style
)

def time_traveled_eventhandler(change):
    time_traveled_output.clear_output()
    with time_traveled_output:
        t_milliseconds = time_traveled_slider.value
        t_sec = t_milliseconds/1000
        print(f"For a time of {t_milliseconds} milliseconds the distance traveled for ultrasound is {(speed_of_ultrasound_m_per_sec['air']*t_sec):.1f} m")
        print(f"For a time of {t_milliseconds} milliseconds the distance traveled for light is {(speed_of_light_m_per_sec['air']*t_sec):.1f} m")
        
time_traveled_slider.observe(handler=time_traveled_eventhandler,type='change')
display(time_traveled_slider)

```


    IntSlider(value=3, description='Time traveled (milliseconds):', layout=Layout(height='80px', width='auto'), mi…



```python
display(time_traveled_output)
```


    Output()


Assume you have a car with both ultrasound and radar sensors. Your task is to design a system that can detect a car when it is 10 meters in front of your car. Change the variables `t_ultrasound_sec` and `t_radar_sec` in the cell below to the correct values for a 20 meter round trip time.


```python
t_ultrasound_sec=0.1 
t_radar_sec=0.1

#Do not change anything below this line
d_m=10.0
d_ultrasound_m = t_ultrasound_sec*speed_of_ultrasound_m_per_sec['air']
d_radar_m = t_radar_sec*speed_of_light_m_per_sec['air']
print(f"An ultrasound signal completes a round trip distance of {d_ultrasound_m:.1f} meters in {t_ultrasound_sec} seconds.")
print(f"A radar signal completes a round trip distance of {d_radar_m:.1f} meters in {t_ultrasound_sec} seconds.")
```

    An ultrasound signal completes a round trip distance of 34.3 meters in 0.1 seconds.
    A radar signal completes a round trip distance of 29979245.8 meters in 0.1 seconds.


In this final section lets look at how many instructions a CPU that can complete 600 megaflops in a second can process. Which signal is the easiest to perform signal processing on and by what factor? Later we will investigate what level of processing can be completed by common algorihms such as the Fast Fourier Transform.


```python
CPU_flops=600e6
print(f"The number of flops a CPU can use to process the ultrasound signal is: {int(CPU_flops*t_ultrasound_sec)} flops")
print(f"The number of flops a CPU can use to process the radar signal is: {int(CPU_flops*t_radar_sec)} flops")
```

    The number of flops a CPU can use to process the ultrasound signal is: 60000000 flops
    The number of flops a CPU can use to process the radar signal is: 60000000 flops


d10ed397c7d72362c69cd6b4c9fa7cf04392c1af
ipynb
Jupyter Notebook
course/tds-100/week_01/calculate_ranges_and_flops.ipynb
potto216/tds-tutorials
2acf2002ac5514dc60781c3e2e6797a4595104e6
MIT
2020-07-12T19:17:59.000Z
2020-09-24T22:19:02.000Z
course/tds-100/week_01/calculate_ranges_and_flops.ipynb
potto216/tds-tutorials
2acf2002ac5514dc60781c3e2e6797a4595104e6
MIT
2020-09-16T12:18:01.000Z
2020-12-17T23:04:37.000Z
course/tds-100/week_01/calculate_ranges_and_flops.ipynb
potto216/tds-tutorials
2acf2002ac5514dc60781c3e2e6797a4595104e6
MIT
Qwen/Qwen-72B
1. YES
2. YES