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

HMM pre-processing fails if sampling rate is not a multiple of 51.2 #59

Closed
AKuederle opened this issue Feb 28, 2024 · 7 comments
Closed

Comments

@AKuederle
Copy link
Member

The "naive" upsampling implemnted here does not work with samplingrates that are not a even multiple

def inverse_transform_state_sequence(self, state_sequence: np.ndarray, *, sampling_rate_hz: float) -> np.ndarray:
"""Inverse transform a state sequence to the original sampling rate.
Parameters
----------
state_sequence
The state sequence to be transformed back to the original sampling rate.
This is done by repeating each state for the number of samples it was downsampled to.
sampling_rate_hz
The sampling rate of the original data in Hz
Returns
-------
The state sequence in the original sampling rate
"""
return np.repeat(state_sequence, sampling_rate_hz / self.sampling_rate_feature_space_hz)

We should use proper interpolation using "nearest"

@HaMora @Aksei Jelena wanted to fix this I think? Any updates? And if she does not have time, could one of you have a look at that?

@Aksei
Copy link
Collaborator

Aksei commented Mar 21, 2024

I could take care of it. I am not 100% on this topic; never used the HMMs so far. My naive approach would be to use the script.signal.resample functionality instead of the np.repeat function.

@AKuederle @HaMora what di you think?

@AKuederle
Copy link
Member Author

Seems reasonable. Does resample support a "nearest" option? Otherwise interpolate might do the job

@Aksei
Copy link
Collaborator

Aksei commented Mar 21, 2024

What do you mean with "nearest"?
The green signal is the one that needs to be resampled, isn't it?

Unbenannt

@AKuederle
Copy link
Member Author

I mean as a resample method. Because we need discrete values. With normal resample you would get float/in-between values

@AKuederle
Copy link
Member Author

And yes, the green signal is the one that needs resampling

@HaMora
Copy link
Collaborator

HaMora commented Mar 22, 2024

Sorry for the late reply,
I read your comments and followed your conversation. I think, as @AKuederle mentioned, if we do resampling, we might need to do some aligning to match the two signals. But I think if we give the length of the original signal instead of the len(downsampled) * target_sampling_rate/actual_sampling_rate
(sort of interpolation) might be effective.

@AKuederle
Copy link
Member Author

Resolved by #62

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants