Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #587: Enhanced FFT normalization handling across arithmetic ope…
…rations.
- Loading branch information
1 parent
cec6e77
commit f4c6ff3
Showing
405 changed files
with
3,626 additions
and
1,212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import pyfar as pf | ||
signal = pf.signals.exponential_sweep_time(44100, (50, 2e4)) | ||
signal.fft_norm = 'rms' | ||
1 / signal |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import pyfar as pf | ||
import matplotlib.pyplot as plt | ||
import numpy as np | ||
from pyfar.classes.audio import _match_fft_norm | ||
|
||
# create an exponential sweep signal | ||
signal = pf.signals.exponential_sweep_time(44100, (50, 20e3)) | ||
signal.fft_norm = 'rms' # Initial FFT normalization of the sweep | ||
|
||
# performing the division | ||
divided_signal = 1 / signal | ||
divided_signal.fft_norm = 'amplitude' # setting normalization post-division | ||
|
||
# generate white noise with the same length and sampling rate as the signal | ||
noise = pf.signals.noise(signal.n_samples, spectrum='white', seed=1, sampling_rate=signal.sampling_rate) | ||
noise.fft_norm = 'none' | ||
|
||
# multiplying divided signal | ||
result_signal = divided_signal * noise | ||
|
||
print("Before override:", divided_signal.fft_norm, noise.fft_norm) | ||
result_signal.fft_norm = _match_fft_norm(divided_signal.fft_norm, noise.fft_norm, 'multiply', norm_override='rms') | ||
print("After override:", result_signal.fft_norm) | ||
|
||
# match signal lengths with time vector | ||
t = np.linspace(0, signal.n_samples / signal.sampling_rate, num=signal.n_samples) | ||
|
||
|
||
plt.figure(figsize=(12, 9)) | ||
plt.subplot(3, 1, 1) | ||
plt.plot(t, signal.time.ravel(), label='Original Signal') | ||
plt.title('Original Signal') | ||
plt.xlabel('Time (s)') | ||
plt.ylabel('Amplitude') | ||
|
||
plt.subplot(3, 1, 2) | ||
plt.plot(t, divided_signal.time.ravel(), label='Divided Signal') | ||
plt.title('Divided Signal (1 / Original)') | ||
plt.xlabel('Time (s)') | ||
plt.ylabel('Amplitude') | ||
|
||
plt.subplot(3, 1, 3) | ||
plt.plot(t, result_signal.time.ravel(), label='Resulting Signal (Divided * Noise)') | ||
plt.title('* Noise') | ||
plt.xlabel('Time (s)') | ||
plt.ylabel('Amplitude') | ||
|
||
plt.tight_layout() | ||
plt.show() | ||
|
Oops, something went wrong.