{
  "id": 358835,
  "title": "Anyone tried to invert the spectrograms back into waveforms?",
  "url": "/competitions/g2net-detecting-continuous-gravitational-waves/discussion/358835",
  "author_name": "Will Rice",
  "post_date": "2022-10-09T18:14:18.246000",
  "votes": 18,
  "comment_count": 10,
  "views": 0,
  "content": "<p>My question is about using istft on the h1 and l1 amplitudes. Since the imaginary part is still intact, I thought this would be the equivalent of inverting a spectrogram back into the waveform. This would allow us to use wave-unet-like architectures which have worked well for me on waveform classification tasks.</p>",
  "messages": [
    {
      "id": 1979817,
      "postDate": "2022-10-09T18:14:18.247Z",
      "content": "<p>My question is about using istft on the h1 and l1 amplitudes. Since the imaginary part is still intact, I thought this would be the equivalent of inverting a spectrogram back into the waveform. This would allow us to use wave-unet-like architectures which have worked well for me on waveform classification tasks.</p>",
      "rawMarkdown": "My question is about using istft on the h1 and l1 amplitudes. Since the imaginary part is still intact, I thought this would be the equivalent of inverting a spectrogram back into the waveform. This would allow us to use wave-unet-like architectures which have worked well for me on waveform classification tasks.",
      "votes": 18
    },
    {
      "id": 2012727,
      "postDate": "2022-11-01T11:18:58.757Z",
      "content": "<p>Hi Will,</p>\n<p>Great question, I wanted to use WaveNet-like model based on some very good results I had on a classification task for time signals. Of course inconsistency in time sampling is an issue but there's probable a way to reconstruct a \"good enough\" time signal. As for noise, I worked with time signals with a large amount of noise and WaveNet would still clearly outperform other NN architectures.</p>\n<p>According to me the biggest challenge would be the size of input data. A representative sample would have a SFT shape (4000, 360) and <code>Tsft = 1800</code>. This means the duration of the raw signal is around 83 days. With a typical frequency <code>F0 = 100Hz</code>, and 20 points per wavelength to properly describe <code>F0</code>, it gives a signal of 14 billion points. </p>\n<p>So the real question is: can we convert the spectrogram information to a waveform keeping a reasonable input data size? Does it make sense to \"normalize\" Tsft? But using <code>Tsft = 1</code> still gives 8 million points with the above parameters.</p>\n<p>I'm curious to hear what are your ideas about this!</p>",
      "rawMarkdown": "Hi Will,\n\nGreat question, I wanted to use WaveNet-like model based on some very good results I had on a classification task for time signals. Of course inconsistency in time sampling is an issue but there's probable a way to reconstruct a \"good enough\" time signal. As for noise, I worked with time signals with a large amount of noise and WaveNet would still clearly outperform other NN architectures.\n\nAccording to me the biggest challenge would be the size of input data. A representative sample would have a SFT shape (4000, 360) and `Tsft = 1800`. This means the duration of the raw signal is around 83 days. With a typical frequency `F0 = 100Hz`, and 20 points per wavelength to properly describe `F0`, it gives a signal of 14 billion points. \n\nSo the real question is: can we convert the spectrogram information to a waveform keeping a reasonable input data size? Does it make sense to \"normalize\" Tsft? But using `Tsft = 1` still gives 8 million points with the above parameters.\n\nI'm curious to hear what are your ideas about this!",
      "votes": 1
    },
    {
      "id": 1997387,
      "postDate": "2022-10-20T20:26:19.710Z",
      "content": "<ul>\n<li>The main problem is that there is inconsistency in time sampling. </li>\n<li>Also, there is too much noise in data, and thus inverting will also lead to noisy waves.</li>\n</ul>",
      "rawMarkdown": "- The main problem is that there is inconsistency in time sampling. \n- Also, there is too much noise in data, and thus inverting will also lead to noisy waves.",
      "votes": 1
    },
    {
      "id": 1980059,
      "postDate": "2022-10-10T01:22:26.503Z",
      "content": "<p>Thanks! Seems like it may be worth a try.</p>",
      "rawMarkdown": "Thanks! Seems like it may be worth a try.",
      "votes": 1
    },
    {
      "id": 1980029,
      "postDate": "2022-10-10T00:30:02.583Z",
      "content": "<p>You may try scipy.singal.isfts, and I guess it's what you need. But it's still hard to tell the difference between target zeros and ones.</p>",
      "rawMarkdown": "You may try scipy.singal.isfts, and I guess it's what you need. But it's still hard to tell the difference between target zeros and ones.",
      "votes": 1
    },
    {
      "id": 1979946,
      "postDate": "2022-10-09T20:41:50.840Z",
      "content": "<p>You can represent a complex number in polar form with magnitude and angle, so you can treat the signal like a electromagnetic waveform. You can see more info <a href=\"https://www.translatorscafe.com/unit-converter/en-US/calculator/complex-phasor/\" target=\"_blank\">here</a>. I hope this help 🙂</p>",
      "rawMarkdown": "You can represent a complex number in polar form with magnitude and angle, so you can treat the signal like a electromagnetic waveform. You can see more info [here](https://www.translatorscafe.com/unit-converter/en-US/calculator/complex-phasor/). I hope this help 🙂",
      "votes": 1
    },
    {
      "id": 1991015,
      "postDate": "2022-10-16T22:18:28.480Z",
      "content": "<p>Hello, I've tried recreating this in this notebook, check it out 😄: <a href=\"https://www.kaggle.com/viktorcikojevic/waveform-from-sfft\" target=\"_blank\">https://www.kaggle.com/viktorcikojevic/waveform-from-sfft</a></p>",
      "rawMarkdown": "Hello, I've tried recreating this in this notebook, check it out 😄: https://www.kaggle.com/viktorcikojevic/waveform-from-sfft",
      "votes": 2,
      "replies": [
        {
          "id": 1991426,
          "postDate": "2022-10-17T06:31:37.967Z",
          "content": "<p>You are not accounting for irregular sampling. Without it the reconstruction is incorrect.</p>",
          "rawMarkdown": "You are not accounting for irregular sampling. Without it the reconstruction is incorrect."
        },
        {
          "id": 1991457,
          "postDate": "2022-10-17T07:00:49.367Z",
          "content": "<p>Oh, I see what you mean, thanks for the note!<br>\nI'll post an update when I correct for that 🙂</p>",
          "rawMarkdown": "Oh, I see what you mean, thanks for the note!\nI'll post an update when I correct for that 🙂"
        },
        {
          "id": 2026466,
          "postDate": "2022-11-12T05:53:39.867Z",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/sakvaua\" target=\"_blank\">@sakvaua</a>, do you think <a href=\"https://www.kaggle.com/cristojv\" target=\"_blank\">@cristojv</a> 's opinion on irregular sampling is correct?</p>\n<blockquote>\n  <p>I came to your notebook just to tell you that the irregular sampling does not have to be considered. It is assumed that in each window of 1800 seconds, 30 minutes (each timestamp), the detector sampling is perfectly regular.<br>\n  What is not regular are the acquisition of these time windows. There are times when it is not possible to ensure a regular sampling to be able to apply the STFTs transformation. For this reason the window is discarded until another 30 minutes are correctly obtained.</p>\n</blockquote>",
          "rawMarkdown": "Hi @sakvaua, do you think @cristojv 's opinion on irregular sampling is correct?\n\n> I came to your notebook just to tell you that the irregular sampling does not have to be considered. It is assumed that in each window of 1800 seconds, 30 minutes (each timestamp), the detector sampling is perfectly regular.\nWhat is not regular are the acquisition of these time windows. There are times when it is not possible to ensure a regular sampling to be able to apply the STFTs transformation. For this reason the window is discarded until another 30 minutes are correctly obtained."
        },
        {
          "id": 2026499,
          "postDate": "2022-11-12T06:50:35.033Z",
          "content": "<p>Good point! I used confusing/incorrect terminology when referring to \"window sampling\". Of course d detector sampling is perfectly regular. For a single STFS nothing prevents you from reconstructing that 1800 second interval. The problem arises if you convert STFS with the help of istft function disregarding timestamps. The difference between the neighboring stfts can be as low as one and as up to 50000 or something. So just feeding all those stfs into the function will not allow you to reconstruct the initial signal (which may be not important at all). </p>",
          "rawMarkdown": "Good point! I used confusing/incorrect terminology when referring to \"window sampling\". Of course d detector sampling is perfectly regular. For a single STFS nothing prevents you from reconstructing that 1800 second interval. The problem arises if you convert STFS with the help of istft function disregarding timestamps. The difference between the neighboring stfts can be as low as one and as up to 50000 or something. So just feeding all those stfs into the function will not allow you to reconstruct the initial signal (which may be not important at all). ",
          "votes": 1
        }
      ]
    }
  ],
  "comments": [
    {
      "id": 2012727,
      "author_name": "Quentin R",
      "author_url": "",
      "post_date": "2022-11-01T11:18:58.757000",
      "content": "<p>Hi Will,</p>\n<p>Great question, I wanted to use WaveNet-like model based on some very good results I had on a classification task for time signals. Of course inconsistency in time sampling is an issue but there's probable a way to reconstruct a \"good enough\" time signal. As for noise, I worked with time signals with a large amount of noise and WaveNet would still clearly outperform other NN architectures.</p>\n<p>According to me the biggest challenge would be the size of input data. A representative sample would have a SFT shape (4000, 360) and <code>Tsft = 1800</code>. This means the duration of the raw signal is around 83 days. With a typical frequency <code>F0 = 100Hz</code>, and 20 points per wavelength to properly describe <code>F0</code>, it gives a signal of 14 billion points. </p>\n<p>So the real question is: can we convert the spectrogram information to a waveform keeping a reasonable input data size? Does it make sense to \"normalize\" Tsft? But using <code>Tsft = 1</code> still gives 8 million points with the above parameters.</p>\n<p>I'm curious to hear what are your ideas about this!</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1997387,
      "author_name": "",
      "author_url": "",
      "post_date": "2022-10-20T20:26:19.710000",
      "content": "<ul>\n<li>The main problem is that there is inconsistency in time sampling. </li>\n<li>Also, there is too much noise in data, and thus inverting will also lead to noisy waves.</li>\n</ul>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1980059,
      "author_name": "Will Rice",
      "author_url": "",
      "post_date": "2022-10-10T01:22:26.503000",
      "content": "<p>Thanks! Seems like it may be worth a try.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1980029,
      "author_name": "zzzc18",
      "author_url": "",
      "post_date": "2022-10-10T00:30:02.583000",
      "content": "<p>You may try scipy.singal.isfts, and I guess it's what you need. But it's still hard to tell the difference between target zeros and ones.</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1979946,
      "author_name": "Zollkron",
      "author_url": "",
      "post_date": "2022-10-09T20:41:50.840000",
      "content": "<p>You can represent a complex number in polar form with magnitude and angle, so you can treat the signal like a electromagnetic waveform. You can see more info <a href=\"https://www.translatorscafe.com/unit-converter/en-US/calculator/complex-phasor/\" target=\"_blank\">here</a>. I hope this help 🙂</p>",
      "votes": 1,
      "replies": []
    },
    {
      "id": 1991015,
      "author_name": "Viktor Cikojevic",
      "author_url": "",
      "post_date": "2022-10-16T22:18:28.480000",
      "content": "<p>Hello, I've tried recreating this in this notebook, check it out 😄: <a href=\"https://www.kaggle.com/viktorcikojevic/waveform-from-sfft\" target=\"_blank\">https://www.kaggle.com/viktorcikojevic/waveform-from-sfft</a></p>",
      "votes": 2,
      "replies": [
        {
          "id": 1991426,
          "author_name": "DennisSakva",
          "author_url": "",
          "post_date": "2022-10-17T06:31:37.967000",
          "content": "<p>You are not accounting for irregular sampling. Without it the reconstruction is incorrect.</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 1991457,
          "author_name": "Viktor Cikojevic",
          "author_url": "",
          "post_date": "2022-10-17T07:00:49.367000",
          "content": "<p>Oh, I see what you mean, thanks for the note!<br>\nI'll post an update when I correct for that 🙂</p>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 2026466,
          "author_name": "Bingliang Li",
          "author_url": "",
          "post_date": "2022-11-12T05:53:39.867000",
          "content": "<p>Hi <a href=\"https://www.kaggle.com/sakvaua\" target=\"_blank\">@sakvaua</a>, do you think <a href=\"https://www.kaggle.com/cristojv\" target=\"_blank\">@cristojv</a> 's opinion on irregular sampling is correct?</p>\n<blockquote>\n  <p>I came to your notebook just to tell you that the irregular sampling does not have to be considered. It is assumed that in each window of 1800 seconds, 30 minutes (each timestamp), the detector sampling is perfectly regular.<br>\n  What is not regular are the acquisition of these time windows. There are times when it is not possible to ensure a regular sampling to be able to apply the STFTs transformation. For this reason the window is discarded until another 30 minutes are correctly obtained.</p>\n</blockquote>",
          "votes": 0,
          "replies": []
        },
        {
          "id": 2026499,
          "author_name": "DennisSakva",
          "author_url": "",
          "post_date": "2022-11-12T06:50:35.033000",
          "content": "<p>Good point! I used confusing/incorrect terminology when referring to \"window sampling\". Of course d detector sampling is perfectly regular. For a single STFS nothing prevents you from reconstructing that 1800 second interval. The problem arises if you convert STFS with the help of istft function disregarding timestamps. The difference between the neighboring stfts can be as low as one and as up to 50000 or something. So just feeding all those stfs into the function will not allow you to reconstruct the initial signal (which may be not important at all). </p>",
          "votes": 1,
          "replies": []
        }
      ]
    }
  ],
  "raw_markdown_by_id": {
    "1979817": "My question is about using istft on the h1 and l1 amplitudes. Since the imaginary part is still intact, I thought this would be the equivalent of inverting a spectrogram back into the waveform. This would allow us to use wave-unet-like architectures which have worked well for me on waveform classification tasks.",
    "2012727": "Hi Will,\n\nGreat question, I wanted to use WaveNet-like model based on some very good results I had on a classification task for time signals. Of course inconsistency in time sampling is an issue but there's probable a way to reconstruct a \"good enough\" time signal. As for noise, I worked with time signals with a large amount of noise and WaveNet would still clearly outperform other NN architectures.\n\nAccording to me the biggest challenge would be the size of input data. A representative sample would have a SFT shape (4000, 360) and `Tsft = 1800`. This means the duration of the raw signal is around 83 days. With a typical frequency `F0 = 100Hz`, and 20 points per wavelength to properly describe `F0`, it gives a signal of 14 billion points. \n\nSo the real question is: can we convert the spectrogram information to a waveform keeping a reasonable input data size? Does it make sense to \"normalize\" Tsft? But using `Tsft = 1` still gives 8 million points with the above parameters.\n\nI'm curious to hear what are your ideas about this!",
    "1997387": "- The main problem is that there is inconsistency in time sampling. \n- Also, there is too much noise in data, and thus inverting will also lead to noisy waves.",
    "1980059": "Thanks! Seems like it may be worth a try.",
    "1980029": "You may try scipy.singal.isfts, and I guess it's what you need. But it's still hard to tell the difference between target zeros and ones.",
    "1979946": "You can represent a complex number in polar form with magnitude and angle, so you can treat the signal like a electromagnetic waveform. You can see more info [here](https://www.translatorscafe.com/unit-converter/en-US/calculator/complex-phasor/). I hope this help 🙂",
    "1991015": "Hello, I've tried recreating this in this notebook, check it out 😄: https://www.kaggle.com/viktorcikojevic/waveform-from-sfft"
  }
}