Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Complex normalization #567

Merged
merged 10 commits into from Apr 15, 2024
Merged

Conversation

tluebeck
Copy link

@tluebeck tluebeck commented Apr 4, 2024

Which issue(s) are closed by this pull request?

Changes proposed in this pull request:

  • adapt fft_norm setter and don't allow "rms" and "power" normalization of complex time signals
  • adapt complex setter and check if fit_norm is allowed
  • edit dsp.normalize accordingly

@tluebeck tluebeck changed the base branch from main to develop_complex_signals April 4, 2024 16:45
@sikersten
Copy link
Member

I'm wondering about the meaning of the 'amplitude' normalization for complex time signals.
A real-valued tones, it shows the amplitude of the tones in terms in the correct "implied unit" (see Ahrens et al., 2020) by compensating for the number of samples.
What does is mean in the context of complex signals? For example, is the concept of "complex tones" (=power signals) meaningful? Or is the 'amplitude' normalization just to the seen as compensation for the number of samples?

@sikersten
Copy link
Member

sikersten commented Apr 12, 2024

Maybe cos(2*pi*f*t)+j*sin(2*pi*f*t) is a meaningful example. It results in a spectrum with 1 at +/- the frequency with amplitude normalization, so compensating for the number of samples is quite intuitive in this case. I'll approve :)

if self._complex and fft_norm in ["rms", "power"]:
raise ValueError((f"'{fft_norm}' normalization is not valid "
if self._complex and fft_norm in ["rms", "power", "psd"]:
raise ValueError((f"'{fft_norm} normalization is not valid "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets maybe give a full list of non-valid norms. Otherwise one might change the norm to get the same error again:
'The rms, power, and psd FFT normalizations are not valid for complex signals'

# check fft norm if complex flag was set
if self._complex:
if self.fft_norm in ["rms", "power", "psd"]:
raise ValueError((f"'{self.fft_norm}' normalization is not "
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

@@ -957,7 +962,7 @@ def fft_norm(self, value):
raise ValueError(("Invalid FFT normalization. Has to be "
f"{', '.join(self._VALID_FFT_NORMS)}, but found "
f"'{value}'"))
if self._complex and value in ["rms", "power"]:
if self._complex and value in ["rms", "power", "psd"]:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See above

pyfar/dsp/dsp.py Outdated
@@ -2261,6 +2261,10 @@ def normalize(signal, reference_method='max', domain='time',
raise ValueError((
f"domain is '{domain}' and signal is type '{signal.__class__}'"
" but must be of type 'Signal' or 'FrequencyData'."))
if isinstance(signal, (pyfar.TimeData, pyfar.Signal)):
if signal.complex and reference_method in ['energy', 'power', 'rms']:
raise ValueError(f'{reference_method} is not implemented for '
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets maybe give a full list of non-valid methods. Otherwise one might change the norm to get the same error again:
'The energy, power, and rms reference methods are not implemented for complex signals'

implement more detailed value error messages
@tluebeck tluebeck merged commit 8117822 into develop_complex_signals Apr 15, 2024
8 checks passed
@tluebeck tluebeck deleted the complex_normalization branch April 15, 2024 04:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants