> For the complete documentation index, see [llms.txt](https://jonas.gitbook.io/seismo_rain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jonas.gitbook.io/seismo_rain/cross-comparison-between-seismic-and-rainfall-data/visualising-rainfall-with-frequency-domain.md).

# Visualising rainfall with frequency domain

We can transform our waveform (count value vs. time) using the Fourier transform to generate a frequency domain plot (amplitude vs. frequency). This approach allows us to assess when a high-frequency signal is detected by the geophone.

<figure><img src="/files/T7BV0OPYTQrnefKRLQ9b" alt="" width="375"><figcaption><p><strong>A visualisation of how time domain can convert to frequnecy domain via Fourier Transformation (</strong><a href="https://medium.com/the-modern-scientist/the-fourier-transform-and-its-application-in-machine-learning-edecfac4133c"><strong>Gomede, 2023</strong></a><strong>)</strong></p></figcaption></figure>

The provided code will generate a frequency domain plot of the seismic waveform within a 30-minute time bin. Here's a complete example specifically for the 2A.1517 station during the time interval from April 19, 2016, UTC 22:00 to 22:30. You can modify the seismic station to plot using `st[...]`, as well as adjust the time interval by changing the `start_timestep` and `end_timestep` variables.

```python
import numpy as np

# Recover "st" to its unprocessed state
st = st.bak

# Extract the trace of an individual channel
# [0]: 2A.1517; [1]: 2A.199; [2]: 2A.465; [3]: 2A.763
tr = st[0]

# Number of samples in 30 minutes
samples_30mins = tr.stats.sampling_rate*3600*0.5

# Selecting the start and end time step for the 30-minute interval
# 0 = 22:00, 1 = 22:30 , ..., 7 = 02:00(+1)
start_timestep = int(samples_30mins*0)
end_timestep = int(samples_30mins*1)
st_30mins = tr.data[start_timestep:end_timestep]

# Perform FFT on the 30-minute data
fft_data = np.fft.fft(st_30mins)
n = len(st_30mins)
dt = 1 / tr.stats.sampling_rate  # the sampling interval (s)
frequencies = np.fft.fftfreq(n, dt)

# Plotting the frequency domain data for the second half (only positive frequency)
plt.figure(figsize=(10, 6))
plt.plot(frequencies[:n // 2], 2.0 / n * np.abs(fft_data[:n // 2]), 'b')  # Only plot the first half

plt.title('2A.1517..DPZ (22:00-22:30)')
plt.xlabel('Frequency (Hz)')
plt.ylabel('Amplitude')
plt.grid()
plt.show()
```

The 30-minute frequency domain at 22:00, 23:00, and 0:00 have been displayed, highlighting a blue-shaded box indicating the bandpass filter range of 80-150 Hz. Across all four stations, a notable increase in amplitude within this range suggests rainfall activity during this specific timeframe. This amplification aligns with the observed pattern in the [rainfall intensity data](/seismo_rain/rainfall-data/extracting-rainfall-data.md#plotting-the-rainfall-intensity-at-all-seismic-stations).

<figure><img src="/files/3IXeoZ8TkTAj0LmTfFlw" alt=""><figcaption><p><strong>Frequncy domain of all four stations at 19 April 2016 22:00-22:30, 23:00-23:30 and 20 April 2016 UTC 00:00-00:30</strong></p></figcaption></figure>


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jonas.gitbook.io/seismo_rain/cross-comparison-between-seismic-and-rainfall-data/visualising-rainfall-with-frequency-domain.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
