Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Feature: initial time for Signal class #195

Description

@FRidh

Activity

  1. FRidh commented on Oct 21, 2015

    @FRidh
    MemberAuthor

    @e-sr

    So you have two datasets, which differ in sample frequency. That's a problem which I occasionally face as well.

    If we would add a reference time to Signal, then at least you can compare the outputs as you want to do now.

    However, it still does not allow putting signals with different sample frequencies in the same Signal. Which is a pity. Also, should it be necessary that the different channels in Signal all have the same starting time or not? Pandas would solve both issues, but would introduce others. And I don't see a pandas based Signal appear anytime soon though.

    I understand your point, and am slowly getting more convinced :-)
    It's a small change, with no impact for users who wouldn't use the feature, but a change which does have some nice benefits.

  2. e-sr commented on Oct 21, 2015

    @e-sr

    About you question on multi or single t0

    I can guess that implementing initial time will need some changes in the following methods depending if multi or single initial time is implemented fot multichannels Signals.

    I am a little confused; but maybe I can give you some inputs:

    • all np indexing and methods like reshape, flatten could lead to some inconsistent results depending on starting time implementation, but this is maybe an issue in the actual acoustic too; for example:
    s = Signal([0,1,2,3,4,5,6,7,8,9],10)
    s2 = s[[0,2,4,6,8]] 
    print(s.fs == s2.fs)

    s2 is of class Signal with same sampling rate as s1. This could be seen as inconsistency.
    Whath to do for the attribute t0?
    Maybe the easier solution is not to allow indexing on signals (or return np arrays)

    • A multi starting time implementation coul lead to interesting usages (moving windows with time reference) if consistent with reshape.
    • othe methods like correlate or pick will need some improvement

    I have given a look how pd.Series handle reshape and it return a np array and can't handle multiminesional data

    At least i feel that the simplest solution (single t0) will lead to less problems.

  3. FRidh commented on Oct 21, 2015

    @FRidh
    MemberAuthor

    The example you show above is indeed a limitation which we will have to live with as long as a numpy array is used. When pandas is used this would not be an issue, since each sample would have a specific time, and from that you could derive the actual sample frequency.

    I agree that in cases like that it should either return an array, or a Signal with the proper sample frequency, #196

    Pandas is column based. The idea is that a single signal is represented by a Series, and that multiple signal channels can be represented by a DataFrame.

    A multi starting time implementation coul lead to interesting usages (moving windows with time reference) if consistent with reshape.

    This is exactly where pandas is good at. Each signal is considered separately within the DataFrame, but you still have a common index.

    The t0 attribute

    I think I will add the t0 attribute. It will have the same limitation as the sample frequency, i.e., it's the same for all channels.
    @felipeacsi do you have any view on this?

  4. felipeacsi commented on Oct 21, 2015

    @felipeacsi
    Member

    Thanks for the mention @FRidh .

    Hello @e-sr ! Good to read that you are using this package. I have some comments about your changes.

    Have you considered to use oversampling to obtain the signals with the same frequency? Do you have any complaint about it? I think is the simplest solution.

    Regarding t0, if Freddy doesn't anything against it I'm ok. IMHO the plot methods would be better as functions in imaging.py and then imported in signal but I don't know if there are issues about cython or other things and I'm giving my opinion without understand all the internals.

  5. e-sr commented on Oct 22, 2015

    @e-sr

    Hi @felipeacsi,

    I don't understand correctly what you mean, but If you think oversampling at measurement is no more possible. I didn't do the measurements (next time I will require it). If you think by interpolation i don't think will be easier.

    As you point out the plots methods have to be revisted My changes are something quick to get results without understandig the full package structure (I didnt' do a pull request beacuse of that).

  6. felipeacsi commented on Oct 22, 2015

    @felipeacsi
    Member

    It's not necessary to do new measurements. The oversampling should be to do as a post measurement processing to prepare the data. In audio often you have signals with sample frequency 44.1 kHz and 48 kHz. So, if you need to have the same frequency you need to perform oversampling to the first signal (sample frequency 44.1 kHz). Of course, you can downsample the 48 kHz signal too. I'm far from being an expert but I think the downsampling could lead to errors (aliasing and such things) if it's not performed in a good way.

    Have you checked scipy.signal.resample? I found this link in the amazing python-audio guide which collects a lot of information around this topic. Specifically, the link is listed under interpolation section. Also, this post is listed and the author do the trick through a script that he shares. Take a look at comments 6 and 7. Maybe is not what you are looking for but you can get the point. It seems there is a better way through scikits.samplerate but the package is abandoned since 2009.

    I hope this can help you.

    TL;DR: Try scipy.signal.resample

  7. FRidh commented on Oct 22, 2015

    @FRidh
    MemberAuthor

    Thanks for the links @felipeacsi

    You're right about those plotting methods. It just naturally grew this way. I prefer to have most Signal methods available as functions as well, so it's on the list :-)

    Resampling is an option when you absolutely need the same sample rate. I wouldn't advice doing that unless absolutely necessary since it always comes with additional errors.

    In this case it's basically just about being able to put two signals with different sample frequencies next to each other, and when making a selection in time, you get the appropriate samples of each signal.

    As I mentioned before this is exactly what pandas is great for. However, since a Signal based on pandas won't come anytime soon, I think we can add a t0 attribute. It's not perfect - neither is fs - but it does solve certain issues without really creating any problems.

  8. e-sr commented on Oct 22, 2015

    @e-sr

    Thanks for the links @felipeacsi
    A ton of interesting things to read!

  9. felipeacsi commented on Oct 22, 2015

    @felipeacsi
    Member

    You're right about those plotting methods. It just naturally grew this way. I prefer to have most Signal methods available as functions as well, so it's on the list :-)

    Sure, no problem. I think it's good to develop a software like this to speed up your work and don't care much about doing the perfect library™ which for me is hard (and with matplotlib, the perfect dream :D).

    Resampling is an option when you absolutely need the same sample rate. I wouldn't advice doing that unless absolutely necessary since it always comes with additional errors.

    Yes, I'm aware of that especially in downsampling. Please @e-sr take this into account to your case.

    As I mentioned before this is exactly what pandas is great for. However, since a Signal based on pandas won't come anytime soon, I think we can add a t0 attribute. It's not perfect - neither is fs - but it does solve certain issues without really creating any problems.

    Sorry, I forgot to mention about pandas in other posts. I agree that is an excellent option to avoid things like this and I'm aware the complexity this could introduce to adapt the existing code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions