<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://pc5271.org/PC5271_AY2425S2/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Yuzhen</id>
	<title>PC5271 wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://pc5271.org/PC5271_AY2425S2/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Yuzhen"/>
	<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php/Special:Contributions/Yuzhen"/>
	<updated>2026-04-15T20:52:13Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.43.6</generator>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2243</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2243"/>
		<updated>2025-04-29T04:24:28Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
&#039;&#039;&#039;Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
===Current Applications===&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
===Future Imrovement===&lt;br /&gt;
&lt;br /&gt;
Issues:&lt;br /&gt;
&lt;br /&gt;
1.No reference standard – Speed validated by eye, causing errors.&lt;br /&gt;
&lt;br /&gt;
2.Doppler method ineffective – Works best &amp;gt;1 m/s, but we measure cm/s.&lt;br /&gt;
&lt;br /&gt;
3.High noise – Lab interference distorts signals.&lt;br /&gt;
&lt;br /&gt;
Solutions:&lt;br /&gt;
&lt;br /&gt;
1.Add calibration – Use a motorized stage or laser sensor for reference.&lt;br /&gt;
&lt;br /&gt;
2.Switch to time-difference method – More accurate for slow speeds.&lt;br /&gt;
&lt;br /&gt;
3.Noise reduction – Narrowband filters, shielding, or signal averaging.&lt;br /&gt;
&lt;br /&gt;
4.Higher sampling rate – Improves resolution for low-speed detection.&lt;br /&gt;
&lt;br /&gt;
5.Coded signals – Use chirp pulses for better SNR.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2242</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2242"/>
		<updated>2025-04-29T04:23:51Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
&#039;&#039;&#039;Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
&lt;br /&gt;
Issues:&lt;br /&gt;
&lt;br /&gt;
1.No reference standard – Speed validated by eye, causing errors.&lt;br /&gt;
&lt;br /&gt;
2.Doppler method ineffective – Works best &amp;gt;1 m/s, but we measure cm/s.&lt;br /&gt;
&lt;br /&gt;
3.High noise – Lab interference distorts signals.&lt;br /&gt;
&lt;br /&gt;
Solutions:&lt;br /&gt;
&lt;br /&gt;
1.Add calibration – Use a motorized stage or laser sensor for reference.&lt;br /&gt;
&lt;br /&gt;
2.Switch to time-difference method – More accurate for slow speeds.&lt;br /&gt;
&lt;br /&gt;
3.Noise reduction – Narrowband filters, shielding, or signal averaging.&lt;br /&gt;
&lt;br /&gt;
4.Higher sampling rate – Improves resolution for low-speed detection.&lt;br /&gt;
&lt;br /&gt;
5.Coded signals – Use chirp pulses for better SNR.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2241</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2241"/>
		<updated>2025-04-29T04:16:13Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Filtering and Signal Recovery */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
&#039;&#039;&#039;Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2240</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2240"/>
		<updated>2025-04-29T04:15:03Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Reasults */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
&#039;&#039;&#039;In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2239</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2239"/>
		<updated>2025-04-29T04:09:00Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Fast Fourier Transform (FFT) */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2238</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2238"/>
		<updated>2025-04-29T04:07:03Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2237</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2237"/>
		<updated>2025-04-29T04:01:27Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Conclusion */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2236</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2236"/>
		<updated>2025-04-29T04:01:08Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Frequency Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2235</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2235"/>
		<updated>2025-04-29T03:59:01Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Magnitude Spectrum and Spectral Peaks */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2234</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2234"/>
		<updated>2025-04-29T03:58:13Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis===&lt;br /&gt;
&lt;br /&gt;
====Discrete Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Magnitude Spectrum and Spectral Peaks====&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
====Signal Filtering in the Frequency Domain====&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2233</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2233"/>
		<updated>2025-04-29T03:56:37Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Sound Propagation and Time-of-Flight====&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis: Discrete Fourier Transform===&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Magnitude Spectrum and Spectral Peaks====&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
===Signal Filtering in the Frequency Domain===&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2232</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2232"/>
		<updated>2025-04-29T03:56:18Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Practical Considerations */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Sound Propagation and Time-of-Flight===&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis: Discrete Fourier Transform===&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Magnitude Spectrum and Spectral Peaks====&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
===Signal Filtering in the Frequency Domain===&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2231</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2231"/>
		<updated>2025-04-29T03:55:44Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Signal Detection and Thresholding */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Practical Considerations====&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
===Sound Propagation and Time-of-Flight===&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis: Discrete Fourier Transform===&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Magnitude Spectrum and Spectral Peaks====&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
===Signal Filtering in the Frequency Domain===&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2230</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2230"/>
		<updated>2025-04-29T03:54:49Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Practical Considerations====&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
===Sound Propagation and Time-of-Flight===&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Signal Detection and Thresholding===&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis: Discrete Fourier Transform===&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Magnitude Spectrum and Spectral Peaks====&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
===Signal Filtering in the Frequency Domain===&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2229</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2229"/>
		<updated>2025-04-29T03:54:06Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Practical Considerations====&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
===Signal Detection and Thresholding===&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
===Frequency Analysis: Discrete Fourier Transform===&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
====Periodicity and Symmetry of the DFT====&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
====Frequency Resolution====&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
====Fast Fourier Transform (FFT)====&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
====Magnitude Spectrum and Spectral Peaks====&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
===Signal Filtering in the Frequency Domain===&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
===Time Thresholding and TOF Detection===&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
===Distance Calibration and Linear Fit===&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
===Conclusion===&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2228</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=2228"/>
		<updated>2025-04-29T03:52:37Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
====Doppler Shift for Stationary Transmitter and Moving Reflector====&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
====Practical Considerations====&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[3] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[4] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Main_Page&amp;diff=2227</id>
		<title>Main Page</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Main_Page&amp;diff=2227"/>
		<updated>2025-04-29T03:51:09Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Ultrasonic Doppler Speedometer */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&#039;&#039;&#039;Welcome to the wiki page for the course PC5271: Physics of Sensors!&#039;&#039;&#039;&lt;br /&gt;
&lt;br /&gt;
This is the repository where projects are documented. Creation of new accounts have now been blocked,and editing/creating pages is enabled. If you need an account, please contact Christian.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;span style=&amp;quot;color: red&amp;quot;&amp;gt;&#039;&#039;&#039;Deadline for report&#039;&#039;&#039;&amp;lt;/span&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Deadline for finishing your report on this wiki will be &amp;lt;span style=&amp;quot;color: red&amp;quot;&amp;gt;&#039;&#039;&#039;29 April 2025 23:59:59&amp;lt;/span&amp;gt;&#039;&#039;&#039; ;) Please be ensured you are happy with your project page at this point, as this will be the basis for our assessment.&lt;br /&gt;
Thanks!! Ramanathan Mahendrian and Christian Kurtsiefer&lt;br /&gt;
&lt;br /&gt;
==Projects==&lt;br /&gt;
===[[Project 1 (Example)]]===&lt;br /&gt;
Keep a very brief description of a project or even a suggestion here, and perhaps the names of the team members, or who to contact if there is interest to join. Once the project has stabilized, keep stuff in the project page linked by the headline.&lt;br /&gt;
&lt;br /&gt;
===[[Laser Gyroscope]]===&lt;br /&gt;
Team members: Darren Koh, Chiew Wen Xin&lt;br /&gt;
&lt;br /&gt;
Build a laser interferometer to detect rotation.&lt;br /&gt;
&lt;br /&gt;
===[[Laser Distance Measurer]]===&lt;br /&gt;
Team members: Arya Chowdhury, Liu Sijin, Jonathan Wong&lt;br /&gt;
&lt;br /&gt;
This project aims to build a laser interferometer to measure distances.&lt;br /&gt;
&lt;br /&gt;
(CK: We should have fast laser diodes and fast photodiodes, mounted in optics bench kits)&lt;br /&gt;
&lt;br /&gt;
===[[Non-contact Alcohol Concentration Measurement Device At NIR Spectrum]]===&lt;br /&gt;
Team members: Lim Gin Joe,Sun Weijia, Yan Chengrui, Zhu Junyi&lt;br /&gt;
This project aims to build a sensor to measure the concentration of alcohol by optical method&lt;br /&gt;
(CK: you can check  Optics Letters &amp;lt;b&amp;gt;47&amp;lt;/b&amp;gt;, 5076-5079 (2022) https://doi.org/10.1364/OL.472890 for some info)&lt;br /&gt;
&lt;br /&gt;
===[[Ultrasonic Acoustic Remote Sensing]]===&lt;br /&gt;
Team member(s): Chua Rui Ming&lt;br /&gt;
&lt;br /&gt;
How well can we use sound waves to survey the environment?&lt;br /&gt;
&lt;br /&gt;
(CK: we have some ultrasonic transducers around 40kHz, see datasheets below)&lt;br /&gt;
&lt;br /&gt;
===[[Blood Oxygen Sensor]]===&lt;br /&gt;
Team members: He Lingzi, Zhao Lubo, Zhang Ruoxi, Xu Yintong&lt;br /&gt;
&lt;br /&gt;
This project aims to build a sensor to detect the oxygen concentration in the blood.&lt;br /&gt;
&lt;br /&gt;
(CK: We have LEDs at 940nm and 660nm peak wavelenth emission, plus some Si photodiodes)&lt;br /&gt;
&lt;br /&gt;
===[[Terahertz Electromagnetic Wave Detection]]===&lt;br /&gt;
Team members: Shizhuo Luo, Bohan Zhang&lt;br /&gt;
&lt;br /&gt;
This project aims to detect Terahertz waves, especially terahertz pulses (This is because they are intense and controllable). We may try different ways like electro-optical sampling and thermopile detectors.&lt;br /&gt;
&lt;br /&gt;
===[[Optical measurement of atmospheric carbon dioxide]]===&lt;br /&gt;
Team member(s): Ta Na, Cao Yuan, Qi Kaiyi, Gao Yihan, Chen Yiming&lt;br /&gt;
&lt;br /&gt;
This project aims to make use of the optical properties of carbon dioxide gas to create a portable and accurate measurement device of carbon dioxide.&lt;br /&gt;
&lt;br /&gt;
===[[Photodetector with wavelength @ 780nm and 1560nm]]===&lt;br /&gt;
Team members: Sunke Lan&lt;br /&gt;
&lt;br /&gt;
To design photodetector as power monitor with power within 10mW.&lt;br /&gt;
&lt;br /&gt;
(CK: Standard problem, we have already the respective photodiodes)&lt;br /&gt;
&lt;br /&gt;
===[[LED based avalanched photodetector]]===&lt;br /&gt;
&lt;br /&gt;
Team members: Cai Shijie, Nie Huanxin, Yang Runzhi&lt;br /&gt;
&lt;br /&gt;
1.Build a single photon detector using LED. The possible LED is gallium compounds based, emitting wavelength around 800nm(red light).&lt;br /&gt;
&lt;br /&gt;
2. Other possible detector: photomultiplier or avalanche photon detector(do we have that?).&lt;br /&gt;
&lt;br /&gt;
3.Do single double-slit interference experiment.&lt;br /&gt;
&lt;br /&gt;
Other devices needed: use LED as single photon source (wavelength shorter than the emitting wavelength 800nm)&lt;br /&gt;
&lt;br /&gt;
prove the detection is single photon: need optical fibre, counting module&lt;br /&gt;
&lt;br /&gt;
===[[Motor Rotation Speed Measurement via the Hall Effect Sensor]]===&lt;br /&gt;
&lt;br /&gt;
Team members: Mi Tianshuo&lt;br /&gt;
&lt;br /&gt;
This project implements a Hall effect sensor to measure the rotation speed of a circuit board-controlled rotary plate.&lt;br /&gt;
&lt;br /&gt;
===[[STM32-Based IMU Attitude Estimation]]===&lt;br /&gt;
&lt;br /&gt;
Team members: Li Ding, Fan Xuting&lt;br /&gt;
&lt;br /&gt;
This project utilizes an STM32 microcontroller and an MPU6050 IMU sensor to measure angular velocity and acceleration, enabling real-time attitude angle computation for motion tracking.&lt;br /&gt;
&lt;br /&gt;
===[[Magnetic field sensing using a fluxgate magnetometer]]===&lt;br /&gt;
Team members: Ni Xueqi&lt;br /&gt;
&lt;br /&gt;
This project investigates magnetic field sensing using a fluxgate magnetometer (FLC100). A 5 V supply drives the sensor, and the output is monitored with an oscilloscope. A permanent magnet is modeled in COMSOL and experimentally measured, showing expected distance-dependent field decay. A toroidal solenoid is also studied; due to imperfections, a magnetic field decaying as &amp;lt;math&amp;gt; 1/r^3 &amp;lt;/math&amp;gt; outside the toroid is observed. Measurements confirm dipole-like behavior and linear current dependence, demonstrating the fluxgate magnetometer&#039;s sensitivity and validating magnetic field modeling.&lt;br /&gt;
&lt;br /&gt;
===[[CO2 Concentration Detector]]===&lt;br /&gt;
Team members: Xie Zihan，Zhao Yun，Zhang Wenbo&lt;br /&gt;
&lt;br /&gt;
Infrared absorption-based CO₂ gas sensors are developed based on the principle that different substances exhibit different absorption spectra. Because the chemical structures of different gas molecules vary, their degrees of absorption of infrared radiation at various wavelengths also differ. Consequently, when infrared radiation of different wavelengths is directed at the sample in turn, certain wavelengths are selectively absorbed and thus weakened by the sample, generating an infrared absorption spectrum.&lt;br /&gt;
&lt;br /&gt;
Once the infrared absorption spectrum of a particular substance is known, its infrared absorption peaks can be identified. For the same substance, when the concentration changes, the absorption intensity at a given absorption peak also changes, and this intensity is directly proportional to the concentration. Therefore, by detecting how the gas alters the wavelength and intensity of the light, one can determine the gas concentration.&lt;br /&gt;
&lt;br /&gt;
===[[Humidity Sensor of Graphite]]===&lt;br /&gt;
Team members: Xu Ruizhe, Wei Heyi, Li Zerui, Ma Shunyu&lt;br /&gt;
&lt;br /&gt;
This project aims to build a humidity sensor with Graphite.&lt;br /&gt;
&lt;br /&gt;
===[[Temperature and humidity sensors]]===&lt;br /&gt;
Team members: Chen Andi, Chen Miaoge, Chen Yingnan, Fang Ye&lt;br /&gt;
&lt;br /&gt;
This project aims to design and evaluate a real-time temperature and humidity monitoring system based on Arduino and the DHT11 sensor. The system is low-cost, easy to implement, and suitable for applications such as smart homes, agriculture, and storage environments. In addition to system development, the project compares the performance of the DHT11 and SHT31 sensors in various environments—indoor, outdoor, and rainy conditions—to assess their accuracy, stability, and response time. The results help guide practical sensor selection, especially in scenarios where cost and simplicity are prioritized over high precision.&lt;br /&gt;
&lt;br /&gt;
===[[Ultrasonic Doppler Speedometer]]===&lt;br /&gt;
Team members: Yang Yuzhen, Liu Xueyi, Shao Shuai &lt;br /&gt;
&lt;br /&gt;
Design and build an ultrasonic Doppler speedometer to measure the distance and velocity of a moving object.&lt;br /&gt;
&lt;br /&gt;
==Resources==&lt;br /&gt;
===Books and links===&lt;br /&gt;
* A good textbook on the Physics of Sensors is Jacob Fraden: Handbook of Mondern Sensors, Springer, ISBN 978-3-319-19302-1 or [https://link.springer.com/book/10.1007/978-3-319-19303-8 doi:10.1007/978-3-319-19303-8]. There shoud be an e-book available through the NUS library at https://linc.nus.edu.sg/record=b3554643&lt;br /&gt;
* Another good textbook: John B.Bentley: Principles of Measurement Systems, 4th Edition, Pearson, ISBN: 0-13-043028-5 or https://linc.nus.edu.sg/record=b2458243 in our library.&lt;br /&gt;
&lt;br /&gt;
===Software===&lt;br /&gt;
* Various Python extensions. [https://www.python.org Python] is a very powerful free programming language that runs on just about any computer platform. It is open source and completely free.&lt;br /&gt;
* [https://www.gnuplot.info Gnuplot]: A free and very mature data display tool that works on just about any platform used that produces excellent publication-grade eps and pdf figures. Can be also used in scripts. Open source and completely free.&lt;br /&gt;
* Matlab: Very common, good toolset also for formal mathematics, good graphics. Expensive. We may have a site license, but I am not sure how painful it is for us to get a license for this course. Ask if interested.&lt;br /&gt;
* Mathematica: More common among theroetical physicists, very good in formal maths, now with better numerics. Graphs are ok but can be a pain to make looking good. As with Matlab, we do have a campus license. Ask if interested.&lt;br /&gt;
&lt;br /&gt;
===Apps===&lt;br /&gt;
Common mobile phones these days are equipped with an amazing toolchest of sensors. There are a few apps that allow you to access them directly, and turn your phone into a powerful sensor. Here some suggestions:&lt;br /&gt;
&lt;br /&gt;
* Physics Toolbox sensor suite on [https://play.google.com/store/apps/details?id=com.chrystianvieyra.physicstoolboxsuite&amp;amp;hl=en_SG Google play store] or [https://apps.apple.com/us/app/physics-toolbox-sensor-suite/id1128914250 Apple App store].&lt;br /&gt;
&lt;br /&gt;
===Data sheets===&lt;br /&gt;
A number of components might be useful for several groups. Some common data sheets are here:&lt;br /&gt;
* Photodiodes:&lt;br /&gt;
** Generic Silicon pin Photodiode type [[Media:Bpw34.pdf|BPW34]]&lt;br /&gt;
** Fast photodiodes (Silicon PIN, small area): [[Media:S5971_etc_kpin1025e.pdf|S5971/S5972/S5973]]&lt;br /&gt;
* PT 100 Temperature sensors based on platinum wire: [[Media:PT100_TABLA_R_T.pdf|Calibration table]]&lt;br /&gt;
* Thermistor type [[Media:Thermistor B57861S.pdf|B57861S]] (R0=10k&amp;amp;Omega;, B=3988Kelvin). Search for   [https://en.wikipedia.org/wiki/Steinhart-Hart_equation Steinhart-Hart equation]. See [[Thermistor]] page here as well.&lt;br /&gt;
* Humidity sensor&lt;br /&gt;
** Sensirion device the reference unit: [[media:Sensirion SHT30-DIS.pdf|SHT30/31]]&lt;br /&gt;
* Thermopile detectors:&lt;br /&gt;
** [[Media:Thermopile_G-TPCO-035 TS418-1N426.pdf|G-TPCO-035 / TS418-1N426]]: Thermopile detector with a built-in optical bandpass filter for light around 4&amp;amp;mu;m wavelength for CO&amp;lt;sub&amp;gt;2&amp;lt;/sub&amp;gt; absorption&lt;br /&gt;
* Resistor color codes are explained [https://en.wikipedia.org/wiki/Electronic_color_code here]&lt;br /&gt;
* Ultrasonic detectors:&lt;br /&gt;
** plastic detctor, 40 kHz, -74dB: [[Media:MCUSD16P40B12RO.pdf|MCUSD16P40B12RO]]&lt;br /&gt;
** metal casing/waterproof, 48 kHz, -90dB, [[Media:MCUSD14A48S09RS-30C.pdf|MCUSD14A48S09RS-30C]]&lt;br /&gt;
** metal casing, 40 kHz, sensitivity unknown, [[Media:MCUST16A40S12RO.pdf|MCUST16A40S12RO]]&lt;br /&gt;
** metal casing/waterproof, 300kHz, may need high voltage: [[Media:MCUSD13A300B09RS.pdf|MCUSD13A300B09RS]]&lt;br /&gt;
* Magnetic field sensor&lt;br /&gt;
** Fluxgate magnetometer [[media:Data-sheet FLC-100.pdf|FCL100]]&lt;br /&gt;
* Lasers&lt;br /&gt;
** Red laser diode [[media:HL6501MG.pdf|HL6501MG]]&lt;br /&gt;
* Generic amplifiers&lt;br /&gt;
** Instrumentation amplifiers: [[media:Ad8221.pdf|AD8221]] or [[media:AD8226.pdf|AD8226]]&lt;br /&gt;
** Conventional operational amplifiers: Precision: [[media:OP27.pdf|OP27]], General purpose: [[media:OP07.pdf|OP07]]&lt;br /&gt;
** Transimpedance amplifiers for photodetectors: [[media:AD8015.pdf|AD8015]]&lt;br /&gt;
&lt;br /&gt;
===Some code snippets===&lt;br /&gt;
* For the [[media:Generic FPGA board version 3 - Quantum Optics Wiki.pdf|pattern generator]], you need to send the following text file to it to generate ultrasonic pulses:&lt;br /&gt;
&lt;br /&gt;
 # This pattern is to generate a burst of 10..20 oscillations at 40 kHz&lt;br /&gt;
 # every 100ms for a sonar test. Pulses are TTL level on the AUX output,&lt;br /&gt;
 # I/O lane 0 bit 7 is a sync pulse (10ns long), I/O lane 0 bit 0 copies the&lt;br /&gt;
 # aux line, bit 1 indicates the pause periode between bursts.&lt;br /&gt;
 # Internal counter 0 is for burst counting, int counter 1 for pause cycles&lt;br /&gt;
 &lt;br /&gt;
 # Set device to programming mode: reset table, reset RAM, program params&lt;br /&gt;
 config 13&lt;br /&gt;
 writew 0, 60571;         # basic address is 0, input thres -0.5V (not used)&lt;br /&gt;
 writew 0,0,0,0;          # external counter preload (not used)&lt;br /&gt;
 writew 9,999,0,0;        # internal cnt preload only first one is relevant&lt;br /&gt;
                          # and determines the number of pulses (minus 1) and&lt;br /&gt;
                          # number minus 1 of multiples of 100us for pause&lt;br /&gt;
 writew 0,0,0,0,0,0,0,0;  # DAC preload - not used &lt;br /&gt;
 &lt;br /&gt;
 config 4; # switch to RAM write&lt;br /&gt;
 &lt;br /&gt;
 # This is the RAM sequence- starting with 40kHz burst&lt;br /&gt;
 writew 0x80,0,0,0,0,0,   0,0x1010;  # ad 0: sync pulse 10nsec, load cnt 0&lt;br /&gt;
 writew 0x01 0,0,1,0,0,1248,0xc004;  # ad 1: pulse on (12.49us), if done go ad4 &lt;br /&gt;
 writew 0x01 0,0,1,0,0,   0,0x1100;  # ad 2: pulse on for 10ns, decr int cnt 0&lt;br /&gt;
 writew 0x00,0,0,0,0,0,1249,0x0001;  # ad 3: pulse off for 12.5us, then go 1 &lt;br /&gt;
 &lt;br /&gt;
 # Waiting time / pause &lt;br /&gt;
 writew 0x02,0,0,0,0,0,   0,0x1020;  # ad 4: preload internal cntr 1 (10ns)&lt;br /&gt;
 writew 0x02,0,0,0,0,0,9998,0x1200;  # ad 5: decr cnt1 (10ns)&lt;br /&gt;
 writew 0x02,0,0,0,0,0,   0,0xd008;  # ad 6: if count is down goto ad 8(10ns)&lt;br /&gt;
 writew 0x02,0,0,0,0,0,   0,0x0005;  # ad 7: goto ad 5(10ns)&lt;br /&gt;
 &lt;br /&gt;
 writew 0x02,0,0,0,0,0,   0,0x0000;  # ad 8: restart (goto ad 0; 10ns)&lt;br /&gt;
 &lt;br /&gt;
 # start pattern and keep output level on AUX line to TTL level&lt;br /&gt;
 config 0x400;&lt;br /&gt;
&lt;br /&gt;
==Some wiki reference materials==&lt;br /&gt;
* [https://www.mediawiki.org/wiki/Special:MyLanguage/Manual:FAQ MediaWiki FAQ]&lt;br /&gt;
* [[Writing mathematical expressions]]&lt;br /&gt;
* [[Uploading images and files]]&lt;br /&gt;
&lt;br /&gt;
== Old Wiki ==&lt;br /&gt;
You can find entries to the wiki from [https://pc5271.org/PC5271_AY2324S2 AY2023/24 Sem 2]&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1858</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1858"/>
		<updated>2025-04-28T11:21:31Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1857</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1857"/>
		<updated>2025-04-28T11:20:06Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With advancements in ultrasonic sensing and signal processing, ultrasonic Doppler speedometers are poised for substantial growth. Miniaturized transducers, combined with machine learning and real-time analytics, will significantly improve system accuracy, adaptability, and range. Future applications include autonomous vehicles for detailed environment sensing, wearable medical devices for continuous monitoring, and smart infrastructure for structural diagnostics. Research is also advancing toward multi-modal systems that fuse ultrasonic Doppler with optical, LiDAR, and radar data for robust, precise tracking. Additionally, innovations in piezoelectric materials will extend frequency range and sensitivity, driving high-resolution, low-power motion detection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1854</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1854"/>
		<updated>2025-04-28T11:17:52Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness.：&lt;br /&gt;
&lt;br /&gt;
1.Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
2.Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
3.Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
4.Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
5.Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1853</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1853"/>
		<updated>2025-04-28T11:16:00Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness. &lt;br /&gt;
Current Applications&lt;br /&gt;
Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot; style=&amp;quot;text-align:center&amp;quot;&lt;br /&gt;
|+ Doppler Speedometer Comparison&lt;br /&gt;
! Model !! Manufacturer !! Frequency Range !! Velocity Range !! Measurement Accuracy !! Typical Application&lt;br /&gt;
|-&lt;br /&gt;
| Doppler SVR-100 || Ametek || 20–100 kHz || 0.1–10 m/s || ±2% || Industrial flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| SonoMeter® 1130 || Siemens || 40 kHz || 0.01–5 m/s || ±1% || Medical blood flow monitoring&lt;br /&gt;
|-&lt;br /&gt;
| UltraLab UDV-2 || Dantec Dynamics || 1–10 MHz (Pulse Doppler) || 0.001–2 m/s || ±0.5% || Microfluidics research&lt;br /&gt;
|-&lt;br /&gt;
| SonicPro S3 || Badger Meter || 20–30 kHz || 0.1–12 m/s || ±1.5% || Large pipe flow measurement&lt;br /&gt;
|-&lt;br /&gt;
| TruSense TS-D100 || TruSense Tech || 40 kHz || 0.05–5 m/s || ±1% || Educational and experimental research&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=File:WechatIMG88.jpg&amp;diff=1849</id>
		<title>File:WechatIMG88.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=File:WechatIMG88.jpg&amp;diff=1849"/>
		<updated>2025-04-28T11:08:44Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1842</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1842"/>
		<updated>2025-04-28T10:58:18Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness. &lt;br /&gt;
Current Applications&lt;br /&gt;
Industrial Inspection: Used for monitoring the velocity of objects on production lines and the flow rate of fluids.&lt;br /&gt;
&lt;br /&gt;
Traffic Management: Applied in vehicle speed detection and violation monitoring on highways.&lt;br /&gt;
&lt;br /&gt;
Medical Field: Utilized in measuring blood flow velocity to assist in diagnosing cardiovascular diseases.&lt;br /&gt;
&lt;br /&gt;
Robotics and Automation: Supports target tracking in autonomous navigation systems.&lt;br /&gt;
&lt;br /&gt;
Sports Science: Used to analyze the speed and trajectory of athletes’ movements.&lt;br /&gt;
&lt;br /&gt;
This is a comparative table of currently available commercial instrument specifications.&lt;br /&gt;
Model | Manufacturer | Frequency Range | Velocity Range | Measurement Accuracy | Typical Application&lt;br /&gt;
Doppler SVR-100 | Ametek | 20–100 kHz | 0.1–10 m/s | ±2% | Industrial flow measurement&lt;br /&gt;
SonoMeter® 1130 | Siemens | 40 kHz | 0.01–5 m/s | ±1% | Medical blood flow monitoring&lt;br /&gt;
UltraLab UDV-2 | Dantec Dynamics | 1–10 MHz (Pulse Doppler) | 0.001–2 m/s | ±0.5% | Microfluidics research&lt;br /&gt;
SonicPro S3 | Badger Meter | 20–30 kHz | 0.1–12 m/s | ±1.5% | Large pipe flow measurement&lt;br /&gt;
TruSense TS-D100 | TruSense Tech | 40 kHz | 0.05–5 m/s | ±1% | Educational and experimental research&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1832</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1832"/>
		<updated>2025-04-28T10:52:14Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer operates based on the transmission and reflection of high-frequency acoustic waves, utilizing the Doppler effect to determine the velocity of moving objects. In this system, a square wave signal at approximately 40 kHz, generated by a signal source such as an oscilloscope, drives an ultrasonic transmitter to emit coherent sound waves. These waves travel through the ambient medium (typically air), interact with moving targets, and are reflected back. The reflected signals are subsequently captured by an ultrasonic receiver and visualized on an oscilloscope for further analysis.&lt;br /&gt;
&lt;br /&gt;
The primary objective of this experiment is to construct a complete ultrasonic Doppler measurement system, structured sequentially through square wave generation, acoustic wave emission, echo reception, and oscilloscope signal acquisition. Through this implementation, the experiment seeks to enhance the understanding of acoustic wave propagation dynamics, Doppler frequency shifting principles, and time-of-flight analysis. Moreover, it provides hands-on experience in signal conditioning, noise reduction, and quantitative velocity extraction techniques.&lt;br /&gt;
&lt;br /&gt;
Compared to traditional mechanical or optical methods, ultrasonic Doppler systems offer notable advantages including non-contact operation, superior real-time responsiveness, and reduced susceptibility to environmental noise. The simplicity of the circuit design, combined with low operational costs, makes this technique highly suitable for both educational purposes and fundamental research in dynamic system monitoring and flow diagnostics.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness. In automotive systems, it is used for adaptive cruise control and collision avoidance by accurately detecting the speed and distance of surrounding vehicles. In industrial sectors, it is applied in flow metering of liquids and gases, monitoring conveyor belt speeds, and ensuring quality control in manufacturing processes. In the biomedical field, ultrasonic Doppler methods are employed for blood flow analysis, cardiovascular diagnostics, and non-invasive monitoring of physiological parameters. Additionally, it is increasingly used in robotics for object tracking and navigation under complex environments where optical methods might fail.&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1817</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1817"/>
		<updated>2025-04-28T10:44:34Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Discussion and Improvement */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer measures the velocity of moving objects by utilizing ultrasonic waves and the Doppler effect. A square wave (~40 kHz) generated by an oscilloscope drives an ultrasonic transmitter to emit sound waves, which propagate through the air, reflect off moving objects, and are captured by a receiver. The signals are then displayed and analyzed using the oscilloscope. By comparing the transmitted and received signals, the system enables real-time, non-contact velocity measurements with a simple and efficient setup.&lt;br /&gt;
&lt;br /&gt;
The purpose of this experiment is to build a complete measurement system following the sequence of square wave generation, ultrasonic transmission, signal reception, and oscilloscope display. Through this setup, the experiment aims to deepen understanding of ultrasonic propagation, Doppler shifts, and time-of-flight principles, while also developing skills in signal processing and velocity extraction.&lt;br /&gt;
&lt;br /&gt;
This method offers advantages such as non-contact measurement, high real-time performance, and minimal disturbance to moving targets. Its simple structure and low cost make it ideal for educational experiments and basic dynamic monitoring research.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
Current Applications:&lt;br /&gt;
Ultrasonic Doppler speedometer technology has found broad applications across various industries due to its non-contact nature, high sensitivity, and robustness. In automotive systems, it is used for adaptive cruise control and collision avoidance by accurately detecting the speed and distance of surrounding vehicles. In industrial sectors, it is applied in flow metering of liquids and gases, monitoring conveyor belt speeds, and ensuring quality control in manufacturing processes. In the biomedical field, ultrasonic Doppler methods are employed for blood flow analysis, cardiovascular diagnostics, and non-invasive monitoring of physiological parameters. Additionally, it is increasingly used in robotics for object tracking and navigation under complex environments where optical methods might fail.&lt;br /&gt;
&lt;br /&gt;
Future Imrovement:&lt;br /&gt;
With the continued advancement of ultrasonic sensing and signal processing technologies, the future of ultrasonic Doppler speedometers is poised for significant growth. Miniaturization of transducer components, combined with the integration of machine learning and real-time data analytics, will dramatically enhance the system’s accuracy, adaptability, and range. Emerging applications are expected in autonomous vehicles for fine-grained environment sensing, in wearable medical devices for continuous health monitoring, and in smart infrastructure systems for structural health diagnostics. Research is also moving toward multi-modal sensing systems, where ultrasonic Doppler measurements are fused with optical, LiDAR, or radar data to enable highly resilient, precise tracking under diverse conditions. Improvements in materials science, such as the development of more efficient piezoelectric materials, will further extend the operational frequency range and sensitivity, pushing the frontiers of high-resolution, low-power motion detection.&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1813</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1813"/>
		<updated>2025-04-28T10:40:02Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer measures the velocity of moving objects by utilizing ultrasonic waves and the Doppler effect. A square wave (~40 kHz) generated by an oscilloscope drives an ultrasonic transmitter to emit sound waves, which propagate through the air, reflect off moving objects, and are captured by a receiver. The signals are then displayed and analyzed using the oscilloscope. By comparing the transmitted and received signals, the system enables real-time, non-contact velocity measurements with a simple and efficient setup.&lt;br /&gt;
&lt;br /&gt;
The purpose of this experiment is to build a complete measurement system following the sequence of square wave generation, ultrasonic transmission, signal reception, and oscilloscope display. Through this setup, the experiment aims to deepen understanding of ultrasonic propagation, Doppler shifts, and time-of-flight principles, while also developing skills in signal processing and velocity extraction.&lt;br /&gt;
&lt;br /&gt;
This method offers advantages such as non-contact measurement, high real-time performance, and minimal disturbance to moving targets. Its simple structure and low cost make it ideal for educational experiments and basic dynamic monitoring research.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1810</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1810"/>
		<updated>2025-04-28T10:36:30Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Introduction */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
The ultrasonic Doppler speedometer measures the velocity of moving objects by utilizing ultrasonic waves and the Doppler effect. A square wave (~40 kHz) generated by an oscilloscope drives an ultrasonic transmitter to emit sound waves, which propagate through the air, reflect off moving objects, and are captured by a receiver. By analyzing the time-of-flight differences and frequency shifts between the transmitted and received signals, the system enables real-time, non-contact velocity measurements with simple hardware setup and easy operation.&lt;br /&gt;
&lt;br /&gt;
The purpose of this experiment is to construct an ultrasonic Doppler speed measurement system, gain an understanding of the principles behind ultrasonic propagation, Doppler shifts, and time-of-flight, and to develop skills in signal processing and velocity extraction.&lt;br /&gt;
&lt;br /&gt;
This method offers advantages such as non-contact operation, high real-time performance, and the ability to monitor moving targets without interference. Its simple structure and low cost make it suitable for educational experiments and basic dynamic monitoring research.&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1419</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1419"/>
		<updated>2025-04-25T11:11:14Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* fPeriodicity and Symmetry of the DFT */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===Periodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1418</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1418"/>
		<updated>2025-04-25T11:09:17Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* References */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===fPeriodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
[4] Cobbold, R. S. C. (2006). *Foundations of Biomedical Ultrasound*. Oxford University Press.&lt;br /&gt;
&lt;br /&gt;
[5] Oppenheim, A. V., &amp;amp; Schafer, R. W. (2009). *Discrete-Time Signal Processing* (3rd ed.). Pearson.&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1416</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1416"/>
		<updated>2025-04-25T11:02:37Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Doppler Effect in Acoustics */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===fPeriodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1415</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1415"/>
		<updated>2025-04-25T11:02:10Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Doppler Effect in Acoustics==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===fPeriodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1414</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1414"/>
		<updated>2025-04-25T11:00:29Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Principles */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Doppler Effect in Acoustics==&lt;br /&gt;
The Doppler effect describes the change in the observed frequency of a wave when there is relative motion between the source and the observer. It applies to all types of waves, including sound, light, and electromagnetic radiation. In the context of ultrasound sensing, the Doppler effect enables the measurement of the relative velocity between an emitter and a moving object.&lt;br /&gt;
&lt;br /&gt;
===Basic Principle===&lt;br /&gt;
Consider a source emitting a wave of frequency &amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; and an observer moving relative to the source. In the case of sound waves propagating in a medium (such as air), the observed frequency &amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o = f_s \cdot \left( \frac{v + v_o}{v - v_s} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s &amp;lt;/math&amp;gt; is the transmitted frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_o &amp;lt;/math&amp;gt; is the observed (received) frequency,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v &amp;lt;/math&amp;gt; is the speed of sound in the medium,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_o &amp;lt;/math&amp;gt; is the velocity of the observer (positive if moving towards the source),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v_s &amp;lt;/math&amp;gt; is the velocity of the source (positive if moving away from the observer).&lt;br /&gt;
&lt;br /&gt;
===Doppler Shift for Stationary Transmitter and Moving Reflector===&lt;br /&gt;
In our experimental setup, the ultrasound transducer acts as both the source and receiver, and the wave reflects off a moving object (e.g., a glider or slider on a track). This is equivalent to a two-stage Doppler shift:&lt;br /&gt;
&lt;br /&gt;
The moving target receives a wave at frequency &amp;lt;math&amp;gt; f_1 &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_1 = f_s \left( \frac{v + v_t}{v} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
The target acts as a moving source, reflecting the wave back toward the sensor. The sensor receives frequency &amp;lt;math&amp;gt; f_r &amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_1 \left( \frac{v}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Combining both effects:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_r = f_s \cdot \left( \frac{v + v_t}{v - v_t} \right) &amp;lt;/math&amp;gt;&lt;br /&gt;
Using binomial expansion and assuming &amp;lt;math&amp;gt; v_t \ll v &amp;lt;/math&amp;gt; (small velocity approximation), the Doppler frequency shift becomes:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = f_r - f_s \approx \frac{2 f_s v_t}{v} &amp;lt;/math&amp;gt;&lt;br /&gt;
This equation relates the observed shift in frequency &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to the velocity &amp;lt;math&amp;gt; v_t &amp;lt;/math&amp;gt; of the moving object.&lt;br /&gt;
&lt;br /&gt;
===Practical Considerations===&lt;br /&gt;
The Doppler effect only measures the component of velocity along the axis of the wave. Transverse motion does not produce a Doppler shift.&lt;br /&gt;
&lt;br /&gt;
The resolution depends on the sampling rate and window size in FFT.&lt;br /&gt;
&lt;br /&gt;
Noise and multiple reflections can obscure the true Doppler peak.&lt;br /&gt;
&lt;br /&gt;
A calibration procedure is typically needed to convert &amp;lt;math&amp;gt; \Delta f &amp;lt;/math&amp;gt; to velocity accurately.&lt;br /&gt;
&lt;br /&gt;
==Sound Propagation and Time-of-Flight==&lt;br /&gt;
Ultrasound refers to mechanical waves with frequencies above the audible range (&amp;gt;20 kHz), which propagate through air by causing oscillations of air molecules. The speed of sound in air at room temperature (~20°C) is approximately:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; v \approx 343 , \text{m/s} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If a pulse is transmitted at time &amp;lt;math&amp;gt; t_{\mathrm{tx}} &amp;lt;/math&amp;gt; and received at time &amp;lt;math&amp;gt; t_{\mathrm{rx}} &amp;lt;/math&amp;gt;, the Time-of-Flight (TOF) is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \mathrm{TOF} = t_{\mathrm{rx}} - t_{\mathrm{tx}} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The corresponding propagation distance is then calculated by:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d = v \cdot \mathrm{TOF} &amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
This method assumes straight-line propagation, negligible reflection loss, and consistent environmental conditions.&lt;br /&gt;
&lt;br /&gt;
==Signal Detection and Thresholding==&lt;br /&gt;
Ultrasonic distance sensors consist of a pair of piezoelectric transducers — one acting as a transmitter and the other as a receiver. When excited by a voltage pulse, the transmitter emits an acoustic wave at a known frequency (typically ~40 kHz). The receiver detects the echo after the wave travels through air.&lt;br /&gt;
&lt;br /&gt;
The emitted signal is typically a short burst of sinusoidal oscillation, and the received signal is its attenuated and delayed counterpart.&lt;br /&gt;
&lt;br /&gt;
The challenge lies in accurately determining the moment of transmission and the first arrival of the received echo, which requires signal processing techniques due to the presence of noise, reflections, and the gradual build-up of the waveform.&lt;br /&gt;
&lt;br /&gt;
==Frequency Analysis: Discrete Fourier Transform==&lt;br /&gt;
In order to analyze the spectral content of a time-domain signal — especially to extract the dominant frequency component of the ultrasound wave — the Discrete Fourier Transform (DFT) is employed. The DFT is a powerful tool that transforms a sequence of time-domain samples into a set of complex frequency components.&lt;br /&gt;
&lt;br /&gt;
The DFT of a signal &amp;lt;math&amp;gt; {x_0, x_1, \ldots, x_{N-1}} &amp;lt;/math&amp;gt; is defined as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k = \sum_{n=0}^{N-1} x_n \cdot e^{-2\pi i kn/N}, \quad k = 0, 1, \ldots, N-1 &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n &amp;lt;/math&amp;gt; is the discrete time-domain signal (real or complex),&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents the complex amplitude of the frequency component at normalized frequency &amp;lt;math&amp;gt; k/N &amp;lt;/math&amp;gt;,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is the total number of samples,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; i = \sqrt{-1} &amp;lt;/math&amp;gt; is the imaginary unit.&lt;br /&gt;
&lt;br /&gt;
Each &amp;lt;math&amp;gt; X_k &amp;lt;/math&amp;gt; represents a specific frequency component of the signal. The magnitude &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; gives the amplitude of the corresponding frequency, and the argument &amp;lt;math&amp;gt; \arg(X_k) &amp;lt;/math&amp;gt; provides its phase.&lt;br /&gt;
&lt;br /&gt;
===fPeriodicity and Symmetry of the DFT===&lt;br /&gt;
Because the DFT is based on a finite-length sequence, it implicitly assumes that the signal is periodic with period &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt;. Moreover, for real-valued input signals (as is typical in this experiment), the DFT exhibits Hermitian symmetry:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_{N-k} = \overline{X_k}, \quad \text{for real input signals} &amp;lt;/math&amp;gt;&lt;br /&gt;
This property implies that only the first &amp;lt;math&amp;gt; N/2 &amp;lt;/math&amp;gt; coefficients are needed to characterize the spectral content, since the second half is just the complex conjugate mirror image.&lt;br /&gt;
&lt;br /&gt;
===Frequency Resolution===&lt;br /&gt;
The frequency corresponding to index &amp;lt;math&amp;gt; k &amp;lt;/math&amp;gt; is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_k = \frac{k}{N \cdot \Delta t} = \frac{k f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
where:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta t &amp;lt;/math&amp;gt; is the sampling interval,&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; f_s = 1 / \Delta t &amp;lt;/math&amp;gt; is the sampling frequency.&lt;br /&gt;
&lt;br /&gt;
Thus, the frequency resolution is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; \Delta f = \frac{f_s}{N} &amp;lt;/math&amp;gt;&lt;br /&gt;
Increasing the number of samples &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; improves frequency resolution and yields a more accurate estimate of the dominant frequency component.&lt;br /&gt;
&lt;br /&gt;
===Fast Fourier Transform (FFT)===&lt;br /&gt;
Although the DFT provides the essential frequency-domain transformation, its computational complexity is quadratic: &amp;lt;math&amp;gt; \mathcal{O}(N^2) &amp;lt;/math&amp;gt;, which is inefficient for large datasets.&lt;br /&gt;
&lt;br /&gt;
The Fast Fourier Transform (FFT) is a class of algorithms that efficiently compute the DFT with a significantly reduced complexity of &amp;lt;math&amp;gt; \mathcal{O}(N \log N) &amp;lt;/math&amp;gt;, by exploiting symmetries and redundancies in the DFT matrix.&lt;br /&gt;
&lt;br /&gt;
The most widely used FFT algorithm is the Cooley-Tukey algorithm, which recursively breaks the DFT computation into smaller DFTs — especially effective when &amp;lt;math&amp;gt; N &amp;lt;/math&amp;gt; is a power of two.&lt;br /&gt;
&lt;br /&gt;
In this experiment, FFT is applied to both the transmitted and received signals to:&lt;br /&gt;
&lt;br /&gt;
Identify the dominant frequency, which corresponds to the ultrasound carrier (typically ~40 kHz),&lt;br /&gt;
&lt;br /&gt;
Design an appropriate band-pass filter centered around this frequency to eliminate noise,&lt;br /&gt;
&lt;br /&gt;
Visually inspect the spectrum for anomalies, harmonics, or interference.&lt;br /&gt;
&lt;br /&gt;
===Magnitude Spectrum and Spectral Peaks===&lt;br /&gt;
The magnitude spectrum is computed as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; |X_k| = \sqrt{ \text{Re}(X_k)^2 + \text{Im}(X_k)^2 } &amp;lt;/math&amp;gt;&lt;br /&gt;
By plotting &amp;lt;math&amp;gt; |X_k| &amp;lt;/math&amp;gt; versus &amp;lt;math&amp;gt; f_k &amp;lt;/math&amp;gt;, the dominant frequency can be observed as the frequency with the highest amplitude peak. This forms the basis of frequency-domain filtering strategies used later in the experiment.&lt;br /&gt;
&lt;br /&gt;
==Signal Filtering in the Frequency Domain==&lt;br /&gt;
In practice, ultrasonic signals are contaminated with environmental noise and harmonics. To isolate the desired frequency band around the central ultrasonic frequency (e.g., 40 kHz), a band-pass filter is designed in the frequency domain.&lt;br /&gt;
&lt;br /&gt;
Let &amp;lt;math&amp;gt; H_k &amp;lt;/math&amp;gt; be the frequency filter such that:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; H_k = \begin{cases} 1, &amp;amp; f_{\mathrm{low}} \le f_k \le f_{\mathrm{high}} \\ 0, &amp;amp; \text{otherwise} \end{cases} &amp;lt;/math&amp;gt;&lt;br /&gt;
The filtered signal in frequency domain is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; X_k^{\mathrm{filtered}} = X_k \cdot H_k &amp;lt;/math&amp;gt;&lt;br /&gt;
Then the filtered time-domain signal is recovered via the inverse DFT:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; x_n^{\mathrm{filtered}} = \frac{1}{N} \sum_{k=0}^{N-1} X_k^{\mathrm{filtered}} \cdot e^{2\pi i kn/N} &amp;lt;/math&amp;gt;&lt;br /&gt;
This process removes irrelevant frequencies and enhances the signal-to-noise ratio, enabling more reliable detection of the echo pulse.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Time Thresholding and TOF Detection==&lt;br /&gt;
After filtering, a thresholding algorithm is applied to detect the first significant deviation in the signal. A fixed amplitude threshold &amp;lt;math&amp;gt; s_{\mathrm{th}} &amp;lt;/math&amp;gt; is defined based on empirical or statistical analysis of the signal amplitude. The time point &amp;lt;math&amp;gt; t_r &amp;lt;/math&amp;gt; where the filtered signal first exceeds this threshold is taken as the received time:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; t_{\mathrm{rx}} = \min \left\{ t \mid |x(t)| \ge s_{\mathrm{th}} \right\} &amp;lt;/math&amp;gt;&lt;br /&gt;
This approach ensures robust and automated detection of the TOF even in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Distance Calibration and Linear Fit==&lt;br /&gt;
To validate the accuracy of the system, measurements are taken at a series of known distances (e.g., 5 cm to 60 cm). For each case, TOF is extracted as above, and a calibration curve is constructed by fitting a linear model:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt; d_{\mathrm{measured}} = a \cdot \mathrm{TOF} + b &amp;lt;/math&amp;gt;&lt;br /&gt;
Ideally, the slope &amp;lt;math&amp;gt; a &amp;lt;/math&amp;gt; should match the speed of sound, and &amp;lt;math&amp;gt; b \approx 0 &amp;lt;/math&amp;gt;. Any deviation reflects systematic error due to electronics delay, transducer response time, or environmental factors.&lt;br /&gt;
&lt;br /&gt;
The goodness of the linear fit validates the consistency of the signal processing pipeline and the physical model.&lt;br /&gt;
==Conclusion==&lt;br /&gt;
This experiment demonstrates how ultrasonic distance estimation can be accurately implemented by combining time-domain thresholding and frequency-domain filtering. Proper filtering and frequency analysis are essential for reliable TOF detection in noisy environments.&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1185</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1185"/>
		<updated>2025-04-23T04:09:08Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Doppler Effect Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1184</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1184"/>
		<updated>2025-04-23T04:08:55Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Doppler Effect Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1182</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1182"/>
		<updated>2025-04-23T04:02:38Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Doppler Effect Analysis */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency.&lt;br /&gt;
&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency.&lt;br /&gt;
&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source).&lt;br /&gt;
&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1181</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1181"/>
		<updated>2025-04-23T04:01:49Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Raw Waveform Observation */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
1. High-frequency jitter from mechanical contact irregularities.&lt;br /&gt;
&lt;br /&gt;
2. Low-frequency rumble due to structural vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1180</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1180"/>
		<updated>2025-04-23T04:01:21Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Reasults */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1179</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1179"/>
		<updated>2025-04-23T04:01:07Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Waveform Analysis and Fourier Transform */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1178</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1178"/>
		<updated>2025-04-23T04:00:47Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Ultrasonic Transmitter and Receiver */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1177</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1177"/>
		<updated>2025-04-23T04:00:36Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Circuit Connections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1176</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1176"/>
		<updated>2025-04-23T04:00:12Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
1. The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
2. The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
1. The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
2. The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
3. These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
4. Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
1. Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
2. Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
3. Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
4. Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
1. Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
2. Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
3. Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
4. Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
1. &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
2. &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
3. &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
4. &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
1. Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
2. Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
3. Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
4. Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
5. Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1175</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1175"/>
		<updated>2025-04-23T03:58:26Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
* The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
* The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
* The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
* The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
* These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
* Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
* Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
* Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
* Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
* Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
* Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
* Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
* Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
* Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
* &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
* Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
* Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
* Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
* Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
* Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==References==&lt;br /&gt;
&lt;br /&gt;
[1] Kinsler, L. E., Frey, A. R., Coppens, A. B., &amp;amp; Sanders, J. V. (1999). &#039;&#039;Fundamentals of Acoustics&#039;&#039; (4th ed.). Wiley.&lt;br /&gt;
&lt;br /&gt;
[2] Smith, S. W. (1997). &#039;&#039;The Scientist and Engineer&#039;s Guide to Digital Signal Processing&#039;&#039;. California Technical Publishing.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1174</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1174"/>
		<updated>2025-04-23T03:50:08Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Circuit Connections */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
* The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
* The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
* The oscilloscope generates a square wave signal (~40 kHz), which is fed into the ultrasonic transmitter.&lt;br /&gt;
* The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
* These waves are captured by the ultrasonic receiver, which converts them back into an electrical signal.&lt;br /&gt;
* Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
* Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
* Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
* Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
* Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
* Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
* Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
* Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
* Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
* &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
* Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
* Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
* Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
* Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
* Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=File:UltrasonicCircuitDiagram.jpg&amp;diff=1172</id>
		<title>File:UltrasonicCircuitDiagram.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=File:UltrasonicCircuitDiagram.jpg&amp;diff=1172"/>
		<updated>2025-04-23T03:49:48Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1171</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1171"/>
		<updated>2025-04-23T03:47:54Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Experiment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Ultrasonic Transmitter and Receiver===&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
* The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
* The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
===Oscilloscope===&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
===Circuit Connections===&lt;br /&gt;
&lt;br /&gt;
The experimental circuit consists of three main components: the signal generator (or function output) from the oscilloscope, the ultrasonic transmitter, and the ultrasonic receiver. The connections are arranged as follows:&lt;br /&gt;
&lt;br /&gt;
* The oscilloscope generates a square wave signal (~40 kHz), which is fed into the **ultrasonic transmitter.&lt;br /&gt;
* The transmitter converts this signal into ultrasonic waves that propagate through the air.&lt;br /&gt;
* These waves are captured by the **ultrasonic receiver**, which converts them back into an electrical signal.&lt;br /&gt;
* Both the transmitted and received signals are connected to separate channels on the oscilloscope, enabling simultaneous real-time comparison.&lt;br /&gt;
&lt;br /&gt;
This configuration allows for precise time-of-flight (ToF) measurement, necessary for calculating sound velocity and Doppler shifts.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicCircuitDiagram.jpg|300px|Schematic of oscilloscope–transmitter–receiver setup]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
* Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
* Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
* Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
* Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
* Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
* Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
* Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
* Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
* &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
* Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
* Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
* Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
* Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
* Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=File:Oscilloscope.jpg&amp;diff=1169</id>
		<title>File:Oscilloscope.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=File:Oscilloscope.jpg&amp;diff=1169"/>
		<updated>2025-04-23T03:45:46Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=File:UltrasonicModules.jpg&amp;diff=1168</id>
		<title>File:UltrasonicModules.jpg</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=File:UltrasonicModules.jpg&amp;diff=1168"/>
		<updated>2025-04-23T03:45:22Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1167</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1167"/>
		<updated>2025-04-23T03:42:28Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Oscilloscope */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Experimental Setup===&lt;br /&gt;
&lt;br /&gt;
====Ultrasonic Transmitter and Receiver====&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
* The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
* The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
====Oscilloscope====&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a digital oscilloscope. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
* Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
* Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
* Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
* Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
* Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
* Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
* Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
* Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
* &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
* Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
* Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
* Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
* Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
* Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1166</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1166"/>
		<updated>2025-04-23T03:42:14Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Ultrasonic Transmitter and Receiver */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Experimental Setup===&lt;br /&gt;
&lt;br /&gt;
====Ultrasonic Transmitter and Receiver====&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the ultrasonic transmitter and ultrasonic receiver, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
* The ultrasonic transmitter converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
* The ultrasonic receiver does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
====Oscilloscope====&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a **digital oscilloscope**. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
* Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
* Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
* Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
* Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
* Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
* Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
* Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
* Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
* &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
* Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
* Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
* Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
* Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
* Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
	<entry>
		<id>https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1165</id>
		<title>Ultrasonic Doppler Speedometer</title>
		<link rel="alternate" type="text/html" href="https://pc5271.org/PC5271_AY2425S2/index.php?title=Ultrasonic_Doppler_Speedometer&amp;diff=1165"/>
		<updated>2025-04-23T03:41:15Z</updated>

		<summary type="html">&lt;p&gt;Yuzhen: /* Experiment */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;==Introduction==&lt;br /&gt;
&lt;br /&gt;
==Principles==&lt;br /&gt;
&lt;br /&gt;
==Experiment==&lt;br /&gt;
&lt;br /&gt;
===Experimental Setup===&lt;br /&gt;
&lt;br /&gt;
====Ultrasonic Transmitter and Receiver====&lt;br /&gt;
&lt;br /&gt;
The core components of our experiment are the **ultrasonic transmitter** and **ultrasonic receiver**, which operate at a center frequency of approximately 40 kHz.&lt;br /&gt;
&lt;br /&gt;
* The **ultrasonic transmitter** converts an electrical signal into mechanical vibrations to generate high-frequency sound waves that propagate through the air.&lt;br /&gt;
* The **ultrasonic receiver** does the reverse—it converts incoming ultrasonic waves into electrical signals for analysis.&lt;br /&gt;
&lt;br /&gt;
These transducers rely on the piezoelectric effect, where certain materials produce voltage when subjected to mechanical stress (and vice versa). They are commonly used in range-finding, object detection, and motion sensing applications.&lt;br /&gt;
&lt;br /&gt;
[[File:UltrasonicModules.jpg|300px|Ultrasonic transmitter and receiver modules]]&lt;br /&gt;
&lt;br /&gt;
====Oscilloscope====&lt;br /&gt;
&lt;br /&gt;
To visualize the waveforms generated and received, we use a **digital oscilloscope**. It allows us to observe and record time-domain signals in real-time, especially the transmitted pulse and its delayed echo after reflection or propagation.&lt;br /&gt;
&lt;br /&gt;
[[File:Oscilloscope.jpg|300px|Digital oscilloscope used in the experiment]]&lt;br /&gt;
&lt;br /&gt;
==Methods and Results==&lt;br /&gt;
&lt;br /&gt;
===Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we focus on measuring the velocity of sound using ultrasonic waves. By analyzing the time-of-flight (ToF) data between the transmitted and received signals, we estimate the distance and calculate the sound velocity. This approach uses experimental measurements from multiple sensor distances to create a response time versus distance curve, which is then analyzed to estimate the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
====Raw Data====&lt;br /&gt;
&lt;br /&gt;
First, we display the waveform shown on the oscilloscope. The following image shows the transmitted and received waveforms.（Take a distance of 10cm as an example）&lt;br /&gt;
&lt;br /&gt;
[[File:MyExperimentDevice1.jpg|300px|The transmitted waveform displayed on the oscilloscope]]&lt;br /&gt;
&lt;br /&gt;
====Waveform Analysis and Fourier Transform====&lt;br /&gt;
&lt;br /&gt;
Next, we analyze the waveforms using Python. The transmitted waveform is a square wave, while the received waveform is more complex, resembling a sinusoidal waveform that is a sum of many sine waves.&lt;br /&gt;
&lt;br /&gt;
[[File:SignalFig.png|300px|Waveform diagram of transmitted and received signals]]&lt;br /&gt;
&lt;br /&gt;
We perform a Fourier Transform on the received waveform to analyze its frequency content. The Fourier transform result is as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:FourierTransformResult.png|300px|Fourier transform of the received waveform]]&lt;br /&gt;
&lt;br /&gt;
From this plot, we observe that the received waveform contains a significant amount of low-frequency noise, which we need to filter out.&lt;br /&gt;
&lt;br /&gt;
This low-frequency noise is common in laboratory environments and can originate from several sources:&lt;br /&gt;
&lt;br /&gt;
* Power line interference: 50 Hz or 60 Hz noise from AC mains power is often present in lab equipment and cables.&lt;br /&gt;
* Electronic device vibrations: Fans, transformers, or other nearby equipment can produce low-frequency mechanical vibrations.&lt;br /&gt;
* Human activity and footsteps: Physical movement near the setup may introduce low-frequency noise through the table or sensor supports.&lt;br /&gt;
* Ambient acoustic noise: Conversations or nearby machinery can contribute sound energy at low frequencies.&lt;br /&gt;
&lt;br /&gt;
To ensure accurate signal interpretation, especially in ultrasonic experiments, these noise components must be filtered out before further analysis.&lt;br /&gt;
&lt;br /&gt;
====Digital Filtering====&lt;br /&gt;
&lt;br /&gt;
To remove the background noise, we apply a digital filter. After filtering, the frequency spectrum and waveform are significantly improved, showing much less noise. We also fit the filtered frequency spectrum using a Gaussian (normal distribution) curve to estimate the dominant frequency component, which results in a mean frequency of 40012.77 Hz. The filtered results are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredSpectrum.png|300px|Filtered frequency spectrum with Gaussian fit (mean frequency = 40012.77 Hz)]]&lt;br /&gt;
&lt;br /&gt;
[[File:FilteredWaveform.png|300px|Filtered waveform after noise reduction]]&lt;br /&gt;
&lt;br /&gt;
As shown, the noise is greatly reduced after filtering, making the waveform more suitable for experimental analysis.&lt;br /&gt;
&lt;br /&gt;
====Reasults====&lt;br /&gt;
&lt;br /&gt;
We measured waveforms from the detected sensor with various sensor-sensor distances. Considering the time difference between the transmitting sensor&#039;s waveform and the detecting sensor&#039;s waveform as the response time that the ultrasonic wave spreads this distance, we plotted the response time versus distance curve as follows:&lt;br /&gt;
&lt;br /&gt;
[[File:VelocityPlot.png|300px|Response time vs. distance]]&lt;br /&gt;
&lt;br /&gt;
In this plot, we can find the slope in the fitted curve around 338.95 m/s, which is close to the theoretical air sound velocity (343 m/s), with an error of around 1.18%.&lt;br /&gt;
&lt;br /&gt;
It is worth noting that the speed of sound in air is affected by several environmental factors:&lt;br /&gt;
&lt;br /&gt;
* Temperature: Sound velocity increases with temperature. For example, at 20 °C, the velocity is approximately 343 m/s, but at 0 °C it drops to about 331 m/s.&lt;br /&gt;
* Humidity: Higher humidity levels can increase the sound speed because water vapor is less dense than dry air.&lt;br /&gt;
* Air pressure and altitude: At constant temperature, changes in pressure have minimal effect, but at high altitudes where both pressure and temperature drop, sound speed decreases.&lt;br /&gt;
* Gas composition: Sound speed also depends on the medium&#039;s composition. For instance, sound travels faster in helium than in air.&lt;br /&gt;
&lt;br /&gt;
These factors may contribute to slight deviations between the measured and theoretical values.&lt;br /&gt;
&lt;br /&gt;
===Doppler Effect Measurement of Sound Velocity===&lt;br /&gt;
&lt;br /&gt;
In this section, we explore another method to measure the speed of sound using the Doppler effect. We move the ultrasonic receiver at a constant speed of 10 cm/s and analyze the frequency shift due to the relative motion between the transmitter and receiver.&lt;br /&gt;
&lt;br /&gt;
====Raw Waveform Observation====&lt;br /&gt;
&lt;br /&gt;
The waveform collected during receiver motion is shown below（Take a distance of 10cm/s as an example）:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawSignal.png|300px|Received waveform with receiver motion (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
As we can see, the raw waveform contains significant noise — even more than the previous static measurement. &lt;br /&gt;
&lt;br /&gt;
[[File:DopplerRawFrequency.png|300px|The frequency of the received signal (10 cm/s)]]&lt;br /&gt;
&lt;br /&gt;
This is mainly due to mechanical vibrations and irregular contact with the metal rail on which the ultrasonic receiver was moving. Metal surfaces can introduce:&lt;br /&gt;
&lt;br /&gt;
* High-frequency jitter from mechanical contact irregularities,&lt;br /&gt;
* Low-frequency rumble due to structural vibrations,&lt;br /&gt;
* Reflections and scattering, especially at non-uniform metal junctions.&lt;br /&gt;
&lt;br /&gt;
====Filtering and Signal Recovery====&lt;br /&gt;
&lt;br /&gt;
To isolate the useful frequency information, we apply digital filtering similar to the previous section. The filtered waveform and frequency spectrum are shown below:&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredWaveform.png|300px|Filtered waveform during receiver motion]]&lt;br /&gt;
&lt;br /&gt;
The signal is now cleaner, and a clear frequency shift can be observed.&lt;br /&gt;
Taking the case of a receiver moving at 10 cm/s as an example, the mean frequency after filtering is approximately 40245.66 Hz, which is noticeably higher than the stationary case (≈40012.77 Hz). This shift is consistent with the expected Doppler effect caused by motion toward the source.&lt;br /&gt;
&lt;br /&gt;
[[File:DopplerFilteredSpectrum.png|300px|Filtered frequency spectrum with Doppler shift (mean frequency ≈ 40245.66 Hz)]]&lt;br /&gt;
&lt;br /&gt;
====Doppler Effect Analysis====&lt;br /&gt;
&lt;br /&gt;
The Doppler effect equation for sound waves when the receiver is moving towards the stationary transmitter is:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;f&#039; = f \left( 1 + \frac{v}{c} \right)&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Where:&lt;br /&gt;
* &amp;lt;math&amp;gt;f&#039;&amp;lt;/math&amp;gt; is the observed frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;f&amp;lt;/math&amp;gt; is the transmitted (original) frequency,&lt;br /&gt;
* &amp;lt;math&amp;gt;v&amp;lt;/math&amp;gt; is the velocity of the receiver (toward the source),&lt;br /&gt;
* &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt; is the speed of sound in air.&lt;br /&gt;
&lt;br /&gt;
We rearrange the equation to solve for &amp;lt;math&amp;gt;c&amp;lt;/math&amp;gt;:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;math&amp;gt;c = \frac{v f}{f&#039; - f}&amp;lt;/math&amp;gt;&lt;br /&gt;
&lt;br /&gt;
We compute the measured sound velocity using the detected frequency shift. A comparison with the actual speed (10 cm/s) is shown below:&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;wikitable&amp;quot;&lt;br /&gt;
! Measured Frequency (Hz) !! Original Frequency (Hz) !! Calculated Velocity (cm/s) !! Actual Velocity (cm/s) !! Error (%)&lt;br /&gt;
|-&lt;br /&gt;
| 40019.85 || 40012.77 || 0.60 || 1 || 40.00&lt;br /&gt;
|-&lt;br /&gt;
| 40072.61 || 40012.77 || 5.05 || 2 || 152.50&lt;br /&gt;
|-&lt;br /&gt;
| 40115.24 || 40012.77 || 8.65 || 5 || 73.00&lt;br /&gt;
|-&lt;br /&gt;
| 40245.66 || 40012.77 || 19.67 || 10 || 96.70&lt;br /&gt;
|-&lt;br /&gt;
| 40745.79 || 40012.77 || 61.00 || 15 || 306.67&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
While the calculated velocities show significant errors, the magnitudes are correct. Possible reasons for the discrepancies include:&lt;br /&gt;
* Inaccurate Velocity Estimation: The velocity was estimated without precise measurement tools, leading to inconsistencies.&lt;br /&gt;
* Low Velocity Sensitivity: The Doppler effect is more accurate at higher velocities (typically &amp;gt; 1 m/s). At low speeds, the frequency shift is minimal, which reduces accuracy.&lt;br /&gt;
* Environmental Noise: Conducting the experiment on a metal rail may have introduced vibrations and noise that affected the results.&lt;br /&gt;
* Limited FFT Resolution: Small frequency shifts require high time resolution for accurate detection, which may not have been achieved here.&lt;br /&gt;
* Multipath Interference: Reflections from surrounding surfaces could distort the received signal.&lt;br /&gt;
&lt;br /&gt;
Despite these issues, the results demonstrate the general applicability of the Doppler effect for velocity estimation.&lt;br /&gt;
&lt;br /&gt;
==Discussion and Improvement==&lt;br /&gt;
&lt;br /&gt;
==Appendix==&lt;br /&gt;
===Python Code for Signal Processing and Sound Speed Estimation===&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
&lt;br /&gt;
  def process_ultrasound_csv(file_path, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      df = pd.read_csv(file_path, usecols=[0, 1, 2], encoding=encoding, skip_blank_lines=True)&lt;br /&gt;
      df.columns = [&#039;时间&#039;, &#039;接收信号&#039;, &#039;输出信号&#039;]&lt;br /&gt;
&lt;br /&gt;
      time = df[&#039;时间&#039;].values&lt;br /&gt;
      tx = df[&#039;输出信号&#039;].values&lt;br /&gt;
      rx = df[&#039;接收信号&#039;].values&lt;br /&gt;
&lt;br /&gt;
      tx_threshold = 0.5 * (np.max(tx) - np.min(tx)) + np.min(tx)&lt;br /&gt;
      tx_index = np.argmax(tx &amp;gt; tx_threshold)&lt;br /&gt;
      tx_time = time[tx_index]&lt;br /&gt;
&lt;br /&gt;
      rx_index = np.argmax(rx)&lt;br /&gt;
      rx_time = time[rx_index]&lt;br /&gt;
&lt;br /&gt;
      tof = rx_time - tx_time&lt;br /&gt;
      distance_estimated = tof * sound_speed&lt;br /&gt;
&lt;br /&gt;
      return {&lt;br /&gt;
          &#039;tx_time&#039;: tx_time,&lt;br /&gt;
          &#039;rx_time&#039;: rx_time,&lt;br /&gt;
          &#039;tof&#039;: tof,&lt;br /&gt;
          &#039;distance_estimated&#039;: distance_estimated&lt;br /&gt;
      }&lt;br /&gt;
  def process_multiple_ultrasound_files(file_paths_dict, encoding=&#039;utf-8&#039;, sound_speed=343):&lt;br /&gt;
      results = {}&lt;br /&gt;
      for distance_cm, file_path in file_paths_dict.items():&lt;br /&gt;
          result = process_ultrasound_csv(file_path, encoding=encoding, sound_speed=sound_speed)&lt;br /&gt;
          results[distance_cm] = result&lt;br /&gt;
      return results&lt;br /&gt;
&lt;br /&gt;
  def plot_estimated_vs_actual(results_dict):&lt;br /&gt;
      actual = []&lt;br /&gt;
      estimated = []&lt;br /&gt;
      for distance_cm, res in results_dict.items():&lt;br /&gt;
          actual.append(distance_cm / 100)&lt;br /&gt;
          estimated.append(res[&#039;distance_estimated&#039;])&lt;br /&gt;
&lt;br /&gt;
      coeffs = np.polyfit(actual, estimated, deg=1)&lt;br /&gt;
      fitted = np.polyval(coeffs, actual)&lt;br /&gt;
&lt;br /&gt;
      plt.figure(figsize=(6, 6))&lt;br /&gt;
      plt.scatter(actual, estimated, color=&#039;dodgerblue&#039;, label=&#039;Estimated distance&#039;)&lt;br /&gt;
      plt.plot(actual, fitted, &#039;r-&#039;, label=f&#039;fitting: y = {coeffs[0]:.3f}x + {coeffs[1]:.3f}&#039;)&lt;br /&gt;
      plt.xlabel(&#039;Actual distance (m)&#039;)&lt;br /&gt;
      plt.ylabel(&#039;Estimated distance (m)&#039;)&lt;br /&gt;
      plt.title(&#039;Actual distance vs Estimated distance&#039;)&lt;br /&gt;
      plt.legend()&lt;br /&gt;
      plt.grid(True)&lt;br /&gt;
      plt.axis(&#039;equal&#039;)&lt;br /&gt;
      plt.tight_layout()&lt;br /&gt;
      plt.show()&lt;br /&gt;
&lt;br /&gt;
  file_paths = {&lt;br /&gt;
      cm: fr&amp;quot;C:\Users\70905\Downloads\WFM\WFM\WFM_{cm}cm_01.CSV&amp;quot;&lt;br /&gt;
      for cm in range(5, 65, 5)&lt;br /&gt;
  }&lt;br /&gt;
&lt;br /&gt;
  all_results = process_multiple_ultrasound_files(file_paths)&lt;br /&gt;
&lt;br /&gt;
  for distance_cm, res in all_results.items():&lt;br /&gt;
      print(f&amp;quot;{distance_cm}cm: ToF = {res[&#039;tof&#039;]:.6f}s, Estimated distance = {res[&#039;distance_estimated&#039;]:.3f}m&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plot_estimated_vs_actual(all_results)&lt;br /&gt;
&lt;br /&gt;
===Python Code for Doppler Effect Signal Processing===&lt;br /&gt;
  import numpy as np&lt;br /&gt;
  import math&lt;br /&gt;
  import matplotlib.pyplot as plt&lt;br /&gt;
  import pandas as pd&lt;br /&gt;
  from scipy.optimize import curve_fit&lt;br /&gt;
  from scipy.stats import norm&lt;br /&gt;
&lt;br /&gt;
  file_dir = f&#039;C:\\Users\\70905\\Documents\\WeChat Files\\wxid_msmjcahnii2f22\\FileStorage\\File\\2025-04\\WFM\\WFM\\WFM_10cm_01.CSV&#039;&lt;br /&gt;
  df = pd.read_csv(file_dir)&lt;br /&gt;
&lt;br /&gt;
  signal = df[&#039;C1 in V&#039;].values&lt;br /&gt;
  T = df[&#039;in s&#039;].values&lt;br /&gt;
&lt;br /&gt;
  dt = T[2] - T[1]&lt;br /&gt;
  n = len(signal)&lt;br /&gt;
  N_pad = 50 * n&lt;br /&gt;
  signal_padded = np.zeros(N_pad)&lt;br /&gt;
  signal_padded[:n] = signal&lt;br /&gt;
&lt;br /&gt;
  fft_vals = np.fft.fft(signal_padded)&lt;br /&gt;
  freqs = np.fft.fftfreq(N_pad, dt)&lt;br /&gt;
&lt;br /&gt;
  pos_mask = freqs &amp;gt;= 0&lt;br /&gt;
  freqs = freqs[pos_mask]&lt;br /&gt;
  fft_vals = fft_vals[pos_mask]&lt;br /&gt;
  amplitudes = np.abs(fft_vals)&lt;br /&gt;
  max_index = np.argmax(amplitudes[5000:])&lt;br /&gt;
  dominant_freq = freqs[max_index + 5000]&lt;br /&gt;
  print(f&amp;quot;{dominant_freq} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freqs, amplitudes)&lt;br /&gt;
  plt.xlim(0, 1e5)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  def gauss(x, amp, mean, sigma):&lt;br /&gt;
      return amp * np.exp(-(x - mean) ** 2 / (2 * sigma ** 2))&lt;br /&gt;
&lt;br /&gt;
  cutoff_freq = 5000&lt;br /&gt;
  filter_mask1 = np.abs(freqs) &amp;lt; dominant_freq + cutoff_freq&lt;br /&gt;
  filter_mask2 = np.abs(freqs) &amp;gt; dominant_freq - cutoff_freq&lt;br /&gt;
  filter_mask = filter_mask1 * filter_mask2&lt;br /&gt;
  filtered_fft = fft_vals * filter_mask&lt;br /&gt;
  filtered_fft2 = np.abs(filtered_fft.copy())&lt;br /&gt;
  idx_sorted = np.argsort(filtered_fft2)&lt;br /&gt;
  second_idx = idx_sorted[-1]&lt;br /&gt;
&lt;br /&gt;
  freq_filtered = freqs[filter_mask]&lt;br /&gt;
  amplitudes_filtered = np.abs(filtered_fft[filter_mask])&lt;br /&gt;
&lt;br /&gt;
  initial_guess = [np.max(amplitudes_filtered), dominant_freq, np.std(freq_filtered)]&lt;br /&gt;
  params, covariance = curve_fit(gauss, freq_filtered, amplitudes_filtered, p0=initial_guess)&lt;br /&gt;
&lt;br /&gt;
  amp_fit, mean_fit, sigma_fit = params&lt;br /&gt;
  print(f&amp;quot;Fitted Gaussian parameters:&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Amplitude: {amp_fit}&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Center frequency: {mean_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
  print(f&amp;quot;Standard deviation: {sigma_fit:.2f} Hz&amp;quot;)&lt;br /&gt;
&lt;br /&gt;
  x_fit = np.linspace(np.min(freq_filtered), np.max(freq_filtered), 1000)&lt;br /&gt;
  y_fit = gauss(x_fit, *params)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(8, 4))&lt;br /&gt;
  plt.plot(freq_filtered, amplitudes_filtered)&lt;br /&gt;
  plt.plot(x_fit, y_fit, label=&amp;quot;Gaussian Fit&amp;quot;, linestyle=&amp;quot;--&amp;quot;, color=&amp;quot;red&amp;quot;)&lt;br /&gt;
  plt.xlabel(&#039;Hz&#039;)&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  filtered_signal = np.fft.ifft(filtered_fft)&lt;br /&gt;
  filtered_signal = np.real(filtered_signal)[:n]&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T, signal, label=&#039;Original&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;br /&gt;
&lt;br /&gt;
  T2 = np.linspace(T[0], T[-1], len(filtered_signal))&lt;br /&gt;
  B = []&lt;br /&gt;
  s = 15e-4&lt;br /&gt;
  Tr = 0&lt;br /&gt;
  for i in range(len(T2)):&lt;br /&gt;
      if abs(filtered_signal[i]) &amp;gt;= s:&lt;br /&gt;
          B.append(1)&lt;br /&gt;
          if Tr == 0:&lt;br /&gt;
              Tr += 1&lt;br /&gt;
      else:&lt;br /&gt;
          B.append(0)&lt;br /&gt;
  filtered_signal = filtered_signal * np.array(B)&lt;br /&gt;
&lt;br /&gt;
  plt.figure(figsize=(10, 4))&lt;br /&gt;
  plt.plot(T2 * math.pi, filtered_signal, label=&#039;After Filter&#039;, linestyle=&#039;--&#039;)&lt;br /&gt;
  plt.xlim(-0.001, 0.005)&lt;br /&gt;
  plt.legend()&lt;br /&gt;
  plt.show()&lt;/div&gt;</summary>
		<author><name>Yuzhen</name></author>
	</entry>
</feed>