{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"markdown","source":"<h1 style=\"font-family:verdana;\"> <center>🚀 G2Net Getting Started 🚀</center> </h1>\n\n***","metadata":{}},{"cell_type":"markdown","source":"<div style=\"color:white;\n           display:fill;\n           border-radius:5px;\n           background-color:#0daae3;\n           font-size:110%;\n           font-family:Verdana;\n           letter-spacing:0.5px\">\n        <p style=\"padding: 10px;\n              color:white;\">\n            Hopefully this notebook will give you a basic understanding of the task and data involved in this competition. Please give an upvote if you find it useful 👍\n        </p>\n    </div>\n    \n<div align = 'center'><img src= \"https://www.g2net.eu/wp-content/uploads/2019/07/2ndconference_V2-1170x600.jpg\" alt =\"Space\" style='width: 1000px;height 500px'>","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:40:27.984824Z","iopub.execute_input":"2022-10-26T21:40:27.985434Z","iopub.status.idle":"2022-10-26T21:40:27.991296Z","shell.execute_reply.started":"2022-10-26T21:40:27.985381Z","shell.execute_reply":"2022-10-26T21:40:27.990178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import seaborn as sns","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:40:27.993471Z","iopub.execute_input":"2022-10-26T21:40:27.99385Z","iopub.status.idle":"2022-10-26T21:40:28.002319Z","shell.execute_reply.started":"2022-10-26T21:40:27.993804Z","shell.execute_reply":"2022-10-26T21:40:28.001316Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### <span style=\"font-family:verdana; word-spacing:1.5px;\"> Contents:\n[Load in the data ⏳](#first-bullet)\n\n[What is HDF5 🤔](#second-bullet)\n    \n[Plotting Spectograms 📊](#third-bullet)   \n\n[What do the real and imaginary parts of a Short-time Fourier Transforms mean? 👻](#fourth-bullet)   \n\n[Timestamp analysis ⏱](#fith-bullet)\n\n[Generating more data ⚙️](#sixth-bullet)   \n\n[Baseline 📈](#seventh-bullry)","metadata":{"execution":{"iopub.status.busy":"2022-10-06T22:32:53.944249Z","iopub.execute_input":"2022-10-06T22:32:53.944766Z","iopub.status.idle":"2022-10-06T22:32:53.95639Z","shell.execute_reply.started":"2022-10-06T22:32:53.944726Z","shell.execute_reply":"2022-10-06T22:32:53.954342Z"}}},{"cell_type":"markdown","source":"### <span style=\"font-family:verdana; word-spacing:1.5px;\">  Task overview\n\n<span style=\"font-family:verdana; word-spacing:1.5px;\"> The goal of this competition is to find continuous gravitational-wave signals. You will develop a model sensitive enough to detect weak yet long-lasting signals emitted by rapidly-spinning neutron stars within noisy data. \n\n<span style=\"font-family:verdana; word-spacing:1.5px;\"> Each sample is comprised of a set of Short-time Fourier Transforms (SFTs) and corresponding time stamps for each interferometer. The SFTs are not always contiguous in time, since the interferometers are not continuously online.\n\n<span style=\"font-family:verdana; word-spacing:1.5px;\"> Each data sample contains either  <span style=\"color:#159364;\">real or simulated noise</span> and possibly <span style=\"color:#159364;\">a simulated continuous gravitational-wave signal (CW) </span>. The task is to <span style=\"color:#159364;\"> identify when a signal is present </span> in the data (target=1).\n","metadata":{}},{"cell_type":"markdown","source":"\n### Continuous gravitational waves\nContinuous gravitational waves are produced by systems that have a __fairly constant and well-defined frequency__. Examples of these are binary sytems of stars or __black holes orbiting each other__ (long before merger), or a __single star swiftly rotating about its axis__ with a large mountain or other irregularity on it. These sources are expected to produce comparatively weak gravitational waves since they evolve over longer periods of time and are usually less catastrophic than sources producing inspiral or burst gravitational waves. The sound these gravitational waves would produce is a continuous tone since their frequency is nearly constant.\n> https://www.ligo.org/science/GW-Continuous.php\n\n<table align='left'>\n<tr>\n<td><img src='https://cdn.spacetelescope.org/archives/images/screen/heic0515a.jpg' width='2100' height='1100'/></td>\n<td>The Crab Nebula (catalogue designations M1, NGC 1952, Taurus A) is a supernova remnant and pulsar wind nebula in the constellation of Taurus. The common name comes from William Parsons, 3rd Earl of Rosse, who observed the object in 1842 using a 36-inch (91 cm) telescope and produced a drawing that looked somewhat like a crab. The nebula was discovered by English astronomer John Bevis in 1731, and it corresponds with a bright supernova recorded by Chinese astronomers in 1054. The nebula was the first astronomical object identified that corresponds with a historical supernova explosion.</td>\n</tr> \n<tr>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/a/af/Crab_Nebula_pulsar_x-ray.jpg' width='900' height='700'/></td>\n<td>First searches for gravitational waves from r-modes of the Crab pulsar...  We did not find any evidence of gravitational waves. Our best 90% confidence upper limits on gravitational wave intrinsic strain were 1.5e-25 for the first run, 1.3e-25 for the first stretch of the second run, and 1.1e-25 for the second stretch of the second run... https://arxiv.org/abs/2101.00714 </td>\n</tr> \n\n<tr>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/c/c9/Chandra-crab.jpg' width='900' height='700'/></td> <td>While LIGO and similar experiments detect objects in the final seconds before they merge, pulsar timing arrays are sensitive to gravitational wave signals from supermassive black holes that are spiraling toward each other and will not combine for millions of years. That's because galaxies merge hundreds of millions of years before the central black holes they host combine to make one giant supermassive black hole....\n     \"A difference between when the pulsar signals should arrive, and when they do arrive, can signal a gravitational wave,\" Mingarelli said. \"And since the pulsars we study are about 3,000 light-years away, they act as a galactic-scale gravitational-wave detector.\" https://www.nasa.gov/feature/jpl/listening-for-gravitational-waves-using-pulsars</td>\n</tr>     \n    \n</table>\n\n> When stars at least eight times as massive as our Sun run out of nuclear fuel, their lives end in supernovae. These explosions bring forth new cosmic objects: neutron stars. Because of their strong magnetic fields and fast rotation, neutron stars emit beamed radio waves and gamma rays like a cosmic lighthouse. And just like a sailor will see flashes of light from the lighthouse, terrestrials will see the neutron star as a pulsating radio or gamma-ray source: a pulsar.\n> Cosmic lighthouses born in supernova explosions\n> \n> Tiny bumps on neutron stars\n> Because of their strong gravity, neutron stars are expected to be almost perfectly spherical – every mountain would be flattened because regular matter cannot withstand the strong gravitational force at the surface. Perfectly round spheres isolated in space will not emit gravitational waves, no matter how fast they spin. If, however, a spinning neutron star is non-axisymmetrically deformed, it will emit gravitational waves.\n> \n> Those deformations can come into existence because the crystalline crust is anything but regular matter. It is 20 times as hard as steel and could thus support small “bumps” on the neutron star surface that are a few centimeters high. They could form in the turbulent aftermath of the supernova or when matter from a stellar companion piles up on the neutron star’s surface. The magnitude of neutron star deformations is usually measured as an “ellipticity”, which describes how much the neutron star deviates from a perfect sphere. In case of those bumps, the ellipticity can be as large as 10-6. Other deformations could result from the neutron star’s magnetic field – it is one billion times as strong as the Earth’s. Simulations of these magnetic deformations show that they can induce smaller ellipticities as large as 10-8.\n> \n> Independently of what causes the deformations: for as long they are there, a spinning neutron star will emit gravitational waves at __twice its rotation frequency__. This is similar to binary systems, where gravitational waves are emitted at twice the orbital frequency. About a fifth of the known neutron stars (which have been observed as pulsars) spin at frequencies of more than __5 Hertz (and up to 700 Hertz)__. Their expected gravitational-wave emission will therefore be in the frequency band observed by ground-based detectors such as LIGO.\n\n","metadata":{}},{"cell_type":"markdown","source":"### **Create clean GW signal (chirp)**\nmost algoritms study very short gravitational-wave signals, produced in the final seconds of black hole and neutron star coalescences. __This is not a continous \"ON\" gravitational wave.__\n\n> Strong and transient versus faint and continuous\n> So far, all gravitational-wave events observed by the LIGO and Virgo detectors came from merging compact binary systems. They observed the inspiral and merger of several dozens of black holes and/or neutron stars in binary systems. The gravitational waves emitted from these compact binary mergers are transient: They are in the LIGO/Virgo frequency band for fractions of a second to up to more than a minute before they end.\nIn contrast, the gravitational waves emitted by rapidly spinning neutron stars are continuous and much fainter than the transient signals from compact binary systems – at least __by a factor of 10,000__. On the positive side, __they are continuous, and the signal is simple__. By analyzing long stretches of data, even very faint signals can be pulled out of noisy detector data. Once a signal has been identified, it can be repeatedly observed as detectors and analysis methods improve. But the search is computationally very demanding.\n\n> https://www.einstein-online.info/en/spotlight/continuousGW/\n\nReverse engineering: Create clean GW signals -GEIR DRANGE\nRiroriro: Simulating gravitational waves and evaluating their detectability in Python\nRiroriro is a Python package to simulate the gravitational waveforms of __binary mergers\nof black holes and/or neutron stars__, and calculate several properties of these mergers and\nwaveforms, specifically relating to their observability by gravitational wave detectors.","metadata":{}},{"cell_type":"code","source":"!pip install riroriro","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:40:28.003521Z","iopub.execute_input":"2022-10-26T21:40:28.004347Z","iopub.status.idle":"2022-10-26T21:41:06.363019Z","shell.execute_reply.started":"2022-10-26T21:40:28.004299Z","shell.execute_reply":"2022-10-26T21:41:06.361127Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import riroriro.inspiralfuns as ins\nimport riroriro.mergerfirstfuns as me1\nimport riroriro.matchingfuns as mat\nimport riroriro.mergersecondfuns as me2\nimport librosa\nimport librosa.display","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:41:06.366348Z","iopub.execute_input":"2022-10-26T21:41:06.366808Z","iopub.status.idle":"2022-10-26T21:41:07.071227Z","shell.execute_reply.started":"2022-10-26T21:41:06.36676Z","shell.execute_reply":"2022-10-26T21:41:07.069729Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import math\nimport os\nimport matplotlib.pyplot as plt\nfrom ipywidgets import interact, fixed, FloatSlider\nimport IPython.display as ipd\n%matplotlib inline","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:41:07.073855Z","iopub.execute_input":"2022-10-26T21:41:07.074789Z","iopub.status.idle":"2022-10-26T21:41:07.085636Z","shell.execute_reply.started":"2022-10-26T21:41:07.074716Z","shell.execute_reply":"2022-10-26T21:41:07.083888Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Parameters:\n# logMC: system mass (0.0-2.0)\n# q: mass ratio (0.1-1.0)\n# D: distance (Mpc)\n# merger_type: 'BH'=binary black hole merger, 'NS'=binary neutron star merger\n# flow: low frequency (Hz) \ndef gen_gw(logMc=1.4, q=0.8, D=100.0, flow=10.0, merger_type='BH'):\n    M, eta = ins.get_M_and_eta(logMc=logMc,q=q)\n    start_x = ins.startx(M,flow)\n    end_x = ins.endx(eta,merger_type)\n    x, xtimes, dt = ins.PN_parameter_integration(start_x,end_x,M,eta)\n    realtimes = ins.inspiral_time_conversion(xtimes,M)\n    i_phase, omega, freq = ins.inspiral_phase_freq_integration(x,dt,M)\n    r, rdot = ins.radius_calculation(x,M,eta)\n    A1, A2 = ins.a1_a2_calculation(r,rdot,omega,D,M,eta)\n    i_Aorth, i_Adiag = ins.inspiral_strain_polarisations(A1,A2,i_phase)\n    i_amp = ins.inspiral_strain_amplitude(i_Aorth,i_Adiag)\n    i_time = realtimes\n    i_omega = omega\n    sfin, wqnm = me1.quasi_normal_modes(eta)\n    alpha, b, C, kappa = me1.gIRS_coefficients(eta,sfin)\n    fhat, m_omega = me1.merger_freq_calculation(wqnm,b,C,kappa)\n    fhatdot = me1.fhat_differentiation(fhat)\n    m_time = me1.merger_time_conversion(M)\n    min_switch_ind = mat.min_switch_ind_finder(i_time,i_omega,m_time,m_omega)\n    final_i_index = mat.final_i_index_finder(min_switch_ind,i_omega,m_omega)\n    time_offset = mat.time_offset_finder(min_switch_ind,final_i_index,i_time,m_time)\n    i_m_time, i_m_omega = mat.time_frequency_stitching(min_switch_ind,final_i_index,time_offset,i_time,i_omega,m_time,m_omega)\n    i_m_freq = mat.frequency_SI_units(i_m_omega,M)\n    m_phase = me2.merger_phase_calculation(min_switch_ind,final_i_index,i_phase,m_omega)\n    i_m_phase = me2.phase_stitching(final_i_index,i_phase,m_phase)\n    m_amp = me2.merger_strain_amplitude(min_switch_ind,final_i_index,alpha,i_amp,m_omega,fhat,fhatdot)\n    i_m_amp = me2.amplitude_stitching(final_i_index,i_amp,m_amp)\n    m_Aorth, m_Adiag = me2.merger_polarisations(final_i_index,m_amp,m_phase,i_Aorth)\n    i_m_Aorth, i_m_Adiag = me2.polarisation_stitching(final_i_index,i_Aorth,i_Adiag,m_Aorth,m_Adiag)\n    return np.array(i_m_time), np.array(i_m_Aorth), np.array(i_m_Adiag), np.array(i_m_freq)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:41:07.087373Z","iopub.execute_input":"2022-10-26T21:41:07.087757Z","iopub.status.idle":"2022-10-26T21:41:07.103614Z","shell.execute_reply.started":"2022-10-26T21:41:07.087722Z","shell.execute_reply":"2022-10-26T21:41:07.102565Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The function returns two waves that represent orthogonal/diagonal waves. The output timescale that is returned is non-linear, so to convert these signals into uniform sampled signals as in the dataset, we need to resample. The function below will resample the gravitational wave signals to 2048Hz. It is crude though, based on nearest sample, but good enough for studying spectrums. Interpolation would be more proper","metadata":{}},{"cell_type":"code","source":"SR = 2048 # target sample rate (Hz)\n# Parameters:\n# dt: time series\n# amp: amplitude signal\n# seg: output sequence length (seconds)\ndef resample(dt, amp, seg=2.0):\n    end = dt[-1]\n    start = end - seg\n    d = np.zeros(int(SR*seg))\n    for i in range((int(SR*seg))):\n        t = start + i/SR\n        d[i] = amp[np.where(dt == dt[np.abs(dt-t).argmin()])[0][0]]\n    return d","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:41:07.105149Z","iopub.execute_input":"2022-10-26T21:41:07.105541Z","iopub.status.idle":"2022-10-26T21:41:07.12114Z","shell.execute_reply.started":"2022-10-26T21:41:07.105507Z","shell.execute_reply":"2022-10-26T21:41:07.119859Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Another helper function for plotting the last part of the GW signal (containing the chirp):","metadata":{}},{"cell_type":"code","source":"def plot_sig(dt, sig1, sig2=None, seg=2.0):\n    end = dt[-1]\n    start = end - seg\n    plt.figure(1)\n    plt.plot(dt, sig1)\n    peak = np.max(np.abs(sig1))\n    plt.axis([start,end,np.min(sig1)-peak/10,np.max(sig1)+peak/10])\n    if sig2 is not None:\n        plt.plot(dt, sig2)\n    plt.xlabel('Time (s)')\n    plt.ylabel('Strain amplitude')","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:41:07.122912Z","iopub.execute_input":"2022-10-26T21:41:07.123369Z","iopub.status.idle":"2022-10-26T21:41:07.132885Z","shell.execute_reply.started":"2022-10-26T21:41:07.12333Z","shell.execute_reply":"2022-10-26T21:41:07.131685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Test the signal generation¶\nNow, let's test the code by emulating the first GW detected (GW150914).","metadata":{}},{"cell_type":"code","source":"m_time, m_Aorth, m_Adiag, m_freq = gen_gw(logMc=1.4, q=0.2)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:41:07.134252Z","iopub.execute_input":"2022-10-26T21:41:07.134635Z","iopub.status.idle":"2022-10-26T21:42:44.779055Z","shell.execute_reply.started":"2022-10-26T21:41:07.134601Z","shell.execute_reply":"2022-10-26T21:42:44.777858Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(16,8))\nplt.subplot(2, 1, 1)\nplot_sig(m_time, m_Aorth, m_Adiag, seg=2)\nplt.subplot(2, 1, 2)\nplot_sig(m_time, m_Aorth, m_Adiag, seg=.1)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:42:44.785138Z","iopub.execute_input":"2022-10-26T21:42:44.785557Z","iopub.status.idle":"2022-10-26T21:42:45.682408Z","shell.execute_reply.started":"2022-10-26T21:42:44.785521Z","shell.execute_reply":"2022-10-26T21:42:45.681527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Changing parameters: \n* logMC: system mass (0.0-2.0)\n* q: mass ratio (0.1-1.0)\n* D: distance (Mpc)\n* merger_type: 'BH'=binary black hole merger, 'NS'=binary neutron star merger\n* flow: low frequency (Hz) \nsystem mass (0.0-2.0)\nmass =2\nmass ratio =1\n","metadata":{}},{"cell_type":"code","source":"m_time, m_Aorth, m_Adiag, m_freq = gen_gw(logMc=1.4, q=1.0)\nfig = plt.figure(figsize=(16,8))\nplt.subplot(2, 1, 1)\nplot_sig(m_time, m_Aorth, m_Adiag, seg=2)\nplt.subplot(2, 1, 2)\nplot_sig(m_time, m_Aorth, m_Adiag, seg=.1)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:42:45.683798Z","iopub.execute_input":"2022-10-26T21:42:45.684412Z","iopub.status.idle":"2022-10-26T21:44:38.833833Z","shell.execute_reply.started":"2022-10-26T21:42:45.684375Z","shell.execute_reply":"2022-10-26T21:44:38.832426Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"'NS'=binary neutron star merger\n\nFor binary neutron star and black hole–neutron star mergers, use 'NS'. For a 'NS' waveform, you should only simulate the inspiral portion (inspiralfuns) and not the merger/ringdown (as the mathematical equations used for the merger/ringdown are only valid for black holes and for neutron star mergers this phase would be beyond the detectable range of LIGO anyway),","metadata":{}},{"cell_type":"markdown","source":"\nIn practice, __the most important__ LIGO search targets for continuous gravitational waves __are neutron stars__ (ultra-compact stellar remnants) in our own Galaxy. Once we reach sufficient detector sensitivity to find such a signal, we expect we can observe it continuously for many months or years.\nOver short times, a continuous gravitational-wave signal from a Galactic neutron star will look almost perfectly constant in both frequency and amplitude, as seen in Fig. 1 for a 0.1 second interval. However, over longer durations, the frequency of the signal will slowly change, for two reasons. The first reason is that, as the neutron star emits gravitational and electromagnetic waves, it loses energy which causes it to rotate more slowly. The second reason is that the detector here on Earth is moving with respect to the neutron star, which changes the frequency of the gravitational waves observed in the detector. The manner in which the signal frequency changes is illustrated in Fig. 2.\n> https://www.ligo.org/science/GW-Continuous.php\n<table align='left'>\n<tr>\n<td><img src='https://www.ligo.org/science/GW-Overview/images/continuous.jpg' width='600' height='600'/></td>\n<td><img src='https://www.ligo.org/science/GW-Overview/images/cw_frequency.png' width='300' height='600'/></td>\n</tr>\n</table>\n","metadata":{}},{"cell_type":"markdown","source":"The top panel shows the frequency, in blue, changing with a daily cycle due to the rotation of the Earth. The middle panel zooms out to show the frequency, in red, changing on a year's time scale due to the orbit of the Earth around the Sun. The bottom panel zooms out further to show how the frequency, in green, slowly decreases due to the rotation of the neutron star itself slowing down over many years.\n\nTracking all possible frequency changes is what makes the detection of continuous gravitational waves a computational challenge.\n","metadata":{}},{"cell_type":"markdown","source":"Gravitational waves are ripples in the curvature of space-time and manifest themselves as fluctuating tidal forces on masses in the path of the wave. The first gravitational-wave detectors were based on the effect of these forces on the fundamental resonant mode of aluminium bars at room temperature. Initial instruments were constructed by Joseph Weber [310, 311] and subsequently developed by others.\nhttps://link.springer.com/article/10.12942/lrr-2011-5\n<table align='left'>\n<tr>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/3/3a/Weber_Memorial_Garden.jpg' width='400' height='400'/></td>\n<td><img src='https://www.researchgate.net/profile/Stefano-Gottardo/publication/315785619/figure/fig4/AS:668320529408002@1536351439285/Webers-bar-detector-Joseph-Weber-with-his-bar-detector-The-small-metallic-squares-on.ppm' width='400' height='600'/></td>\n</tr>\n</table>\n\nThese massive aluminium cylinders vibrated at a resonance frequency of 1660 hertz and were designed to be set in motion by gravitational waves predicted by Weber. Because these waves were supposed to be so weak, the cylinders had to be massive and the piezoelectric sensors had to be very sensitive, capable of detecting a change in the cylinders' lengths by about 10−16 meters.[1]\n\nHowever, the most promising design of gravitational-wave detectors, offering the possibility of very high sensitivities over a wide range of frequency, uses widely-separated test masses freely suspended as pendulums on Earth or in a drag-free craft in space; laser interferometry provides a means of sensing the motion of the masses produced as they interact with a gravitational wave.\n\nGravitational-wave detectors of long baseline have been built in a number of places around the world;\n\nDetection methods cover over 13 orders of magnitude in frequency (see Figure 1) equivalent to covering from radio waves to X-rays in the electromagnetic spectrum. This broadband coverage allows to probe a wide range of potential sources.\n\n<table align='left'>\n<tr>\n<td><img src='https://media.springernature.com/lw685/springer-static/image/art%3A10.12942%2Flrr-2011-5/MediaObjects/41114_2016_9061_Fig1.jpg?as=webp' width='700' height='400'/></td>\n</tr> \n</table>\n\n\n\n","metadata":{}},{"cell_type":"markdown","source":"\n\n","metadata":{}},{"cell_type":"markdown","source":"## Detection of Gravitational Waves\nGravitational waves are most simply thought of as ripples in the curvature of space-time, their effect being to change the separation of adjacent masses on Earth or in space; this tidal effect is the basis of all present detectors. Gravitational wave strengths are characterised by the gravitational-wave amplitude h, given by\n\n$$h = {{2\\Delta L} \\over L},$$\nwhere ΔL is the change in separation of two masses a distance L apart; for the strongest-allowed component of gravitational radiation, the value of h is proportional to the third time derivative of the quadrupole moment of the source of the radiation and inversely proportional to the distance to the source. The radiation field itself is quadrupole in nature and this shows up in the pattern of the interaction of the waves with matter.\n\nThe problem for the experimental physicist is that the predicted magnitudes of the amplitudes or strains in space in the vicinity of the Earth caused by gravitational waves even from the most violent astrophysical events are extremely small, of the order of 10−21 or lower.\n\nhttps://link.springer.com/article/10.12942/lrr-2011-5\n\nIndeed, current theoretical models on the event rate and strength of such events suggest that in order to detect a few events per year — from coalescing neutron-star binary systems, for example, an amplitude sensitivity close to 10−22 over timescales as short as a millisecond is required. If the Fourier transform of a likely signal is considered it is found that the energy of the signal is distributed over a frequency range or bandwidth, which is approximately equal to 1/timescale. For timescales of a millisecond the bandwidth is approximately 1000 Hz, and in this case the spectral density of the amplitude sensitivity is obtained by dividing 10−22 by the square root of 1000. Thus, detector noise levels must have an amplitude spectral density lower than ≃ 10−23 Hz−1/2 over the frequency range of the signal. Signal strengths at the Earth, integrated over appropriate time intervals, for a number of sources are shown in Figure 2.\n\n<table align='left'>\n<tr>\n<td><img src='https://media.springernature.com/full/springer-static/image/art%3A10.12942%2Flrr-2011-5/MediaObjects/41114_2016_9061_Fig2.jpg?as=webp' width='700' height='400'/></td>\n</tr> \n</table>\n\n<table align='left'>\n<tr>\n<td>\n    The sensitivity of an interferometric gravitational-wave detector is limited by noise from various sources. Taking this frequency-dependent noise floor into account, a design goal can be estimated for a particular detector design. For example, the design sensitivity for initial design of LIGO is show plotted alongside the achieved sensitivities of the three individual interferometers during the fifth science run. Such strain sensitivities are expected to allow a reasonable probability for detecting gravitational wave sources. However, in order to guarantee the observation of a full range of sources and to initiate gravitational-wave astronomy, a sensitivity or noise performance approximately ten times better in the mid-frequency range and several orders of magnitude better at 10 Hz, is desired. \n</td>\n</tr> \n</table>\n\n<table align='left'>\n<tr>\n<td><img src='https://media.springernature.com/full/springer-static/image/art%3A10.12942%2Flrr-2011-5/MediaObjects/41114_2016_9061_Fig4.jpg?as=webp' width='700' height='400'/></td>\n</tr> \n</table>\n","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"### Main Noise Sources\n#### Seismic noise\nSeismic noise at a reasonably quiet site on the Earth follows a spectrum in all three dimensions close to 10−7f−2 m/Hz1/2 (where here and elsewhere we measure f in Hz) and thus if the disturbance to each test mass must be less than 3 × 10−20 m/Hz1/2 at, for example, 30 Hz, then the reduction of seismic noise required at that frequency in the horizontal direction is greater than 10E9. \n#### Gravity gradient (Newtonian) noise\nGravity gradients, caused by direct gravitational coupling of mass density fluctuations to the suspended mirrors, were identified as a potential source of noise in ground-based gravitational-wave detectors in 1972\n#### Thermal noise\nThermal noise associated with the mirror masses and the last stage of their suspensions is the most significant noise source at the low frequency end of the operating range of initial long baseline gravitational wave detectors\n#### Quantum noise\nPhotoelectron shot noise\nFor gravitational-wave signals to be detected, the output of the interferometer must be held at one of a number of possible points on an interference fringe\n#### Radiation pressure noise\nAs the effective laser power in the arms is increased, another phenomenon becomes increasingly important arising from the effect on the test masses of fluctuations in the radiation pressure. One interpretation on the origin of this radiation pressure noise may be attributed to the statistical uncertainty in how the beamsplitter divides up the photons of laser light","metadata":{}},{"cell_type":"markdown","source":"### Gravitational-wave sensitivity curves\n> https://cplberry.com/2015/01/10/1408-0740/\n\n> When talking about gravitational-wave detectors, you normally use a sensitivity curve. This shows how sensitive it is at a given frequency: you plot a graph with the sensitivity curve on, and then plot the spectrum of the source you’re interested in on the same graph. If your source is above the sensitivity curve, you can detect it (yay), but if it lies below it, then you can’t pick it out from the noise (boo). Making a plot with lots of sensitivity curves on sounds simple: you look up the details for lots of detectors, draw them together and add a few sources.\n\n<table align='left'>\n<tr>\n<td><img src='https://christopherplberry.files.wordpress.com/2015/01/characteristic_strain.png' width='2100' height='1100'/></td>\n <td>Gravitational-wave sensitivity-curve plot using characteristic strain. The area between the detector’s curve and the top of the box for a source indicates how loud that signal would be.</td>\n</tr> \n    <tr>\n<td><img src='https://christopherplberry.files.wordpress.com/2015/01/asd.png' width='900' height='700'/></td>\n <td>Gravitational-wave sensitivity-curve plot using the square root of the power spectral density (the amplitude spectral density)</td>\n</tr> \n</tr> \n    <tr>\n<td><img src='https://christopherplberry.files.wordpress.com/2015/01/energy_density.png' width='900' height='700'/></td>\n <td>Gravitational-wave sensitivity-curve plot using the energy density that cosmologists love. The proper name of the plotted quantity is the critical energy density per logarithmic frequency interval multiplied by the reduced Hubble constant squared.)</td>\n</tr>     \n    \n</table>\n\nGravitational-wave sensitivity-curve plot using characteristic strain. The area between the detector’s curve and the top of the box for a source indicates how loud that signal would be.","metadata":{}},{"cell_type":"markdown","source":"### A milestone in the race to find the first continuous gravitational wave signal\n\n> https://www.aei.mpg.de/581560/a-milestone-in-the-race-to-find-the-first-continuous-gravitational-wave-signal\n\n> All so far observed gravitational-wave signals have been very short, produced in the final seconds of black hole and neutron star coalescences. There exist other signals, that are continously “ON”. Such continuous signals are much weaker than the short-lived ones but this drawback can be partially made up by utilizing more data and at the cost of a much greater algorithmic complexity of the search. One promising source of continuous gravitational waves are slightly deformed (non-axisymmetric) neutron stars. Our new results explore deformations smaller than 10 parts in a billion. This corresponds to star deformations as large as several widths of human hair! We find no signal candidates but identify a few outliers. Albeit it is unlikely that these candidates come from signals that precisely follow the assumed model, and may well come from coherent disturbances in the data, they will be explored very carefully as new data becomes available – something one can only do with continuous waves. Between the two papers, we search for signals from anywhere in the sky and with frequencies between 20 Hz and 1700 Hz.\n\nWe present the results of an all-sky search for continuous gravitational wave signals with frequencies in the __500-1700 Hz range__ targeting neutron stars with ellipticity of 1e-8. The search is done on LIGO O2 data using the Falcon analysis pipeline. The results presented here double the sensitivity over any other result on the same data. The search is capable of detecting low ellipticity sources up to 170 pc. We establish strict upper limits which hold for worst-case signal parameters. We list outliers uncovered by the search, including several which we cannot associate with any known instrumental cause.\n\n<table align='left'>\n<tr>\n<td><img src='https://www.aei.mpg.de/581610/original-1605258026.webp?t=eyJ3aWR0aCI6MTQwMCwiZmlsZV9leHRlbnNpb24iOiJ3ZWJwIiwicXVhbGl0eSI6ODYsIm9ial9pZCI6NTgxNjEwfQ%3D%3D--6570945434a55f303dbe5bab73d56c40ec76c31f' width='2100' height='1100'/></td>\n <td>Upper limits on the ellipticity of a source at a certain distance (black). We also show the recent upper limits from the low ellipticity all-sky search of Dergachev & Papa (2020). The dashed line is the spin-down ellipticity for the highest spin-down rate probed by each search.</td>\n</tr>     \n</table>\n","metadata":{}},{"cell_type":"markdown","source":"### Short-time Fourier Transforms (SFTs)\n*a wikipedia brief\nShort-time Fourier transform (STFT), is a Fourier-related transform used to determine the sinusoidal frequency and phase content of local sections of a signal as it changes over time.\n\nIn practice, the procedure for computing STFTs is to divide a longer time signal into shorter segments of equal length and then compute the Fourier transform separately on each shorter segment. This reveals the Fourier spectrum on each shorter segment. One then usually plots the changing spectra as a function of time, known as a spectrogram or waterfall plot, such as commonly used in software defined radio (SDR) based spectrum displays. \nFull bandwidth displays covering the whole range of an SDR commonly use fast Fourier transforms (FFTs) with 2^24 points on desktop computers.\n\nUsing the following sample signal $x(t)$that is composed of a set of four sinusoidal waveforms joined together in sequence. Each waveform is only composed of one of four frequencies (10, 25, 50, 100 Hz). The definition of $x(t)$ is:\n$$x(t)=\\begin{cases}\n\\cos (2 \\pi 10 t)  & 0\\,\\mathrm{s}  \\le t < 5  \\,\\mathrm{s} \\\\\n\\cos (2 \\pi 25 t)  & 5\\,\\mathrm{s}  \\le t < 10\\,\\mathrm{s} \\\\\n\\cos (2 \\pi 50 t)  & 10\\,\\mathrm{s} \\le t < 15\\,\\mathrm{s} \\\\\n\\cos (2 \\pi 100 t) & 15\\,\\mathrm{s} \\le t < 20\\,\\mathrm{s} \\\\\n\\end{cases}$$\n\nThen it is sampled at 400 Hz. The following spectrograms were produced:\n<table align='left'>\n<tr>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/0/0f/STFT_colored_spectrogram_25ms.png' width='400' height='200'/></td>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/e/e6/STFT_colored_spectrogram_125ms.png' width='400' height='200'/></td>\n</tr>\n<tr>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/3/30/STFT_colored_spectrogram_375ms.png' width='400' height='200'/></td>\n<td><img src='https://upload.wikimedia.org/wikipedia/commons/f/ff/STFT_colored_spectrogram_1000ms.png' width='400' height='200'/></td>\n</tr>\n</table>\n\n<table align='left'>\n    <tr>\n        <td>\n        The 25 ms window allows us to identify a precise time at which the signals change but the precise frequencies are difficult to identify. At the other end of the scale, the 1000 ms window allows the frequencies to be precisely seen but the time between frequency changes is blurred.\n        </td>\n    </tr>\n</table>\n    ","metadata":{}},{"cell_type":"markdown","source":"The Short Time Fourier Transform (STFT) is a special flavor of a Fourier transform where you can see how your frequencies in your signal change through time.  It works by slicing up your signal into many small segments and taking the fourier transform of each of these.  The result is usually a waterfall plot which shows frequency against time. \n\n<table align='left'>\n<tr>\n<td><img src='https://kevinsprojects.files.wordpress.com/2014/12/mike_annoying_spectrum.png' width='2100' height='1100'/></td>\n <td>s a spectrum of a whistle</td>\n</tr> \n    <tr>\n<td><img src='https://kevinsprojects.files.wordpress.com/2014/12/mike_chirp_spectrum.png' width='900' height='700'/></td>\n <td>Here is a picture of a whistle which increases in frequency over time.It goes from 880 Hz (A in the 5th octave) all the way up to 1760 Hz (A in the 6th octave). </td>\n</tr> \n      \n</table>","metadata":{}},{"cell_type":"markdown","source":"#### STFT Algorithm:\n\nSo, we understand what we’re trying to make – now we have to figure out how to make it.  The data flow we have to achieve is pretty simple, as we only need to do the following steps:\n\nPick out a short segment of data from the overall signal\nMultiply that segment against a half-cosine function\nPad the end of the segment with zeros\nTake the Fourier transform of that segment and normalize it into positive and negative frequencies\nCombine the energy from the positive and negative frequencies together, and display the one-sided spectrum\nScale the resulting spectrum into dB for easier viewing\nClip the signal to remove noise past the noise floor which we don’t care about\n\n* Step 1 – Pick segment: We need to find our current segment to process from the overall data set.  We use the concept of a ‘sliding window’ to help us visualize what’s happening.  The data inside the window is the current segment to be processed.\n\n\n<table align='left'>\n\n<tr>\n<td><img src='https://kevinsprojects.files.wordpress.com/2014/12/window.png?w=768&h=272' width='2300' height='1100'/></td>\n <td>The window’s length remains the same during the processing of the data, but the offset changes with each step of the algorithm.  Usually when processing the STFT, the change in offset will be less than one window length, meaning that the last window and the current window overlap.  If we define the window size, and the percentage of overlap, we know all the information we need about how the window moves throughout the processing.</td>\n</tr> \n    \n<tr>\n<td><img src='https://kevinsprojects.files.wordpress.com/2014/12/window_fcn.png?w=640&h=258' width='2300' height='1100'/></td>\n <td>Step 2– Multiply by half-cosine: This helps to alleviate a problem created by segmenting the data.  When the data is cut into pieces, the edges make a sharp transition that didn’t exist before.  Multiplying by a half cosine function helps to fade the signal in and out so that the transitions at the edges do not affect the Fourier transform of the data.\n\n.</td>\n</tr> \n    \n<tr>\n<td><img src='https://kevinsprojects.files.wordpress.com/2014/12/cosines.png?w=640&h=302' width='2300' height='1100'/></td>\n <td>There is an additional benefit to using a half cosine window.  It can be shown that with an overlap factor of 50%, the sum of the windows is a constant value of 1.  This means that multiplying our data by this particular function does not introduce differences in amplitude from the original signal.  This is mostly important if the waveform has some type of units attached to it [pascals] and we want the frequencies in the Fourier transform to correctly represent the energy content of each frequency in those units.</td>\n</tr> \n    \n<tr>\n<td></td>\n <td>Step 3 – Pad Data: We pad the end of the current segment with a number of zeros equal to the length of the window.  Or in other words, the new segment will be twice as long as the original segment.  The reason for this is explained later.\n\n.</td>\n</tr> \n <tr>\n<td></td>\n <td>Step 4 – Fourier Transform and Scale: This is where all the magic happens.  Everything up to this point was just preparing the data, but this step is the beating heart of the algorithm.  Here we finally take the Fourier transform of the data.  I’m not going to explain the Fourier transform here except to say that it takes a signal and extracts the frequency content from that signal.  There are a few other things that need to be remembered about the Fourier transform.\n\nThe number of samples of data in is equal to the number of frequency bins out\nThe maximum frequency that can be represented is the Nyquist frequency, or half the sampling frequency of the data.\nIn the the Discrete Fourier Transform (what we are using) the order of the frequency bins is 0 Hz (DC component), positive frequencies, Nyquist Frequency, negative frequencies\nThe data from the Fourier transform needs to be scaled by the number of samples in the transform to maintain equal energy (according to Parseval’s theorem)\n\n.</td>\n</tr> \n    \n <tr>\n<td></td>\n <td>Step 5 – Autopower: This is just more post processing to make the results more palatable to look at.  We find the autopower spectrum from the results of the Fourier transform.  The autopower spectrum is a one-sided spectrum (only contains positive frequencies) as opposed to the two-sided spectrum returned by the Fourier transform – so it’s more like the actual real world which does not contain negative frequencies.  The autopower spectrum is also scaled to represent the energy content that was in both the positive and negative frequencies of the Fourier transform.  This is important for the ‘correctness’ of the energy content of each frequency, but also has the handy benefit of suppressing lower energy content and dramatizing higher energy content.  Usually people only care about the higher energy content, so finding this transform typically makes the data much easier to look at.\n\n.</td>\n</tr> \n    \n <tr>\n<td></td>\n <td>Step 6 – Convert to DB: This is another transform to make the data easier to look at.  It turns out that peoples ears work on a logarithmic scale so that the ear can detect much finer changes in amplitude at low amplitudes than at high amplitudes.  We transform the data into decibels (dB) which is a logarithmic scale, so that we can see the energy content of a signal more how our ears would detect it.  Converting the data to decibels has the effect of stretching peaks downwards towards the average sound level, and bringing troughs upwards.  This allows us to compare content at all amplitude levels.  If we didn’t do this and we scaled the data so that the peaks were visible, it would be impossible to see any shape in the quieter values, vs if we looked at the quieter values, the peaks would explode off the top of the screen.\n\n.</td>\n</tr> \n    \n <tr>\n<td></td>\n <td>Step 7 – Clip Data: This also makes the data easier to look at.  We know from experience that everything below -40 dB is well below the noise floor and is probably just numerical error in the algorithm.  Therefore, we can clip the data so that everything below -40 dB is set to -40 dB exactly.  This gives us more color range to apply to significant portions of our data.\n.</td>\n</tr> \n</table>\n\n","metadata":{}},{"cell_type":"markdown","source":"> The Fourier transform yields frequency information that is averaged over the entire time domain. However, the information on when these frequencies occur is hidden in the transform. This phenomenon is illustrated by the following example.\n\n> https://www.audiolabs-erlangen.de/resources/MIR/FMP/C2/C2_STFT-Basic.html","metadata":{}},{"cell_type":"code","source":"\n\nFs = 128\nduration = 10\nomega1 = 1\nomega2 = 5\nN = int(duration * Fs)\nt = np.arange(N) / Fs\nt1 = t[:N//2]\nt2 = t[N//2:]\n\nx1 = 1.0 * np.sin(2 * np.pi * omega1 * t1)\nx2 = 0.7 * np.sin(2 * np.pi * omega2 * t2)\nx = np.concatenate((x1, x2))\n\nplt.figure(figsize=(8, 2))\nplt.subplot(1, 2, 1)\nplt.plot(t, x, c='k')\nplt.xlim([min(t), max(t)])\nplt.xlabel('Time (seconds)')\n\nplt.subplot(1, 2, 2)\nX = np.abs(np.fft.fft(x)) / Fs\nfreq = np.fft.fftfreq(N, d=1/Fs)\nX = X[:N//2]\nfreq = freq[:N//2]\nplt.plot(freq, X, c='k')\nplt.xlim([0, 7])\nplt.ylim([0, 3])\nplt.xlabel('Frequency (Hz)')\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:44:38.835529Z","iopub.execute_input":"2022-10-26T21:44:38.835944Z","iopub.status.idle":"2022-10-26T21:44:39.20123Z","shell.execute_reply.started":"2022-10-26T21:44:38.835904Z","shell.execute_reply":"2022-10-26T21:44:39.199836Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"\n> To recover the hidden time information, Dennis Gabor introduced in the year 1946 the short-time Fourier transform (STFT). Instead of considering the entire signal, the main idea of the STFT is to consider only a small section of the signal. To this end, one fixes a so-called window function, which is a function that is nonzero for only a short period of time (defining the considered section). The original signal is then multiplied with the window function to yield a windowed signal. To obtain frequency information at different time instances, one shifts the window function across time and computes a Fourier transform for each of the resulting windowed signals. This idea is illustrated by the next example.","metadata":{}},{"cell_type":"code","source":"def windowed_ft(t, x, Fs, w_pos_sec, w_len):\n    \n    N = len(x)\n    w_pos = int(Fs * w_pos_sec)\n    w_padded = np.zeros(N)\n    w_padded[w_pos:w_pos + w_len] = 1\n    x = x * w_padded    \n    plt.figure(figsize=(8, 2))\n\n    plt.subplot(1, 2, 1)\n    plt.plot(t, x, c='k')\n    plt.plot(t, w_padded, c='r')\n    plt.xlim([min(t), max(t)])\n    plt.ylim([-1.1, 1.1])\n    plt.xlabel('Time (seconds)')\n\n    plt.subplot(1, 2, 2)\n    X = np.abs(np.fft.fft(x)) / Fs\n    freq = np.fft.fftfreq(N, d=1/Fs)\n    X = X[:N//2]\n    freq = freq[:N//2]\n    plt.plot(freq, X, c='k')\n    plt.xlim([0, 7])\n    plt.ylim([0, 3])\n    plt.xlabel('Frequency (Hz)')\n    plt.tight_layout()\n    plt.show()\n    \nw_len = 4 * Fs\nwindowed_ft(t, x, Fs, w_pos_sec=1, w_len=w_len)\nwindowed_ft(t, x, Fs, w_pos_sec=3, w_len=w_len)\nwindowed_ft(t, x, Fs, w_pos_sec=5, w_len=w_len)\n\nprint('Interactive interface for experimenting with different window shifts:')\ninteract(windowed_ft,\n         w_pos_sec=FloatSlider(min=0, max=duration-(w_len/Fs), step=0.1, \n                continuous_update=False, value=1.7, description='Position'),\n                t=fixed(t), x=fixed(x), Fs=fixed(Fs), w_len=fixed(w_len));","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:44:39.202918Z","iopub.execute_input":"2022-10-26T21:44:39.203331Z","iopub.status.idle":"2022-10-26T21:44:40.48659Z","shell.execute_reply.started":"2022-10-26T21:44:39.203291Z","shell.execute_reply":"2022-10-26T21:44:40.485807Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> It is important to note that the STFT reflects not only the properties of the original signal but also those of the window function. First of all, the STFT depends on the length of the window, which determines the size of the section. Then, the STFT is influenced by the shape of the window. For example, the sharp edges of the rectangular window typically introduce \"ripple\" artifacts. We discuss such issues in more detail later.","metadata":{}},{"cell_type":"markdown","source":"<div class=\"text_cell_render border-box-sizing rendered_html\">\n<h2 id=\"Formal-Definition-of-the-Discrete-STFT\">Formal Definition of the Discrete STFT<a class=\"anchor-link\" href=\"#Formal-Definition-of-the-Discrete-STFT\">¶</a></h2><p>We now consider the discrete case of the STFT and specify the most important mathematical formulas as needed in practical applications. Let <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-1-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>x</mi><mo>:</mo><mo stretchy=&quot;false&quot;>[</mo><mn>0</mn><mo>:</mo><mi>L</mi><mo>&amp;#x2212;</mo><mn>1</mn><mo stretchy=&quot;false&quot;>]</mo><mo>:=</mo><mo fence=&quot;false&quot; stretchy=&quot;false&quot;>{</mo><mn>0</mn><mo>,</mo><mn>1</mn><mo>,</mo><mo>&amp;#x2026;</mo><mo>,</mo><mi>L</mi><mo>&amp;#x2212;</mo><mn>1</mn><mo fence=&quot;false&quot; stretchy=&quot;false&quot;>}</mo><mo stretchy=&quot;false&quot;>&amp;#x2192;</mo><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;double-struck&quot;>R</mi></mrow></mrow></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-1\" style=\"width: 20.36em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 16.967em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.551em, 1016.97em, 2.92em, -999.997em); top: -2.497em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-2\"><span class=\"mi\" id=\"MathJax-Span-3\" style=\"font-family: MathJax_Math-italic;\">x</span><span class=\"mo\" id=\"MathJax-Span-4\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mo\" id=\"MathJax-Span-5\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">[</span><span class=\"mn\" id=\"MathJax-Span-6\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-7\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mi\" id=\"MathJax-Span-8\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">L</span><span class=\"mo\" id=\"MathJax-Span-9\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">−</span><span class=\"mn\" id=\"MathJax-Span-10\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">1</span><span class=\"mo\" id=\"MathJax-Span-11\" style=\"font-family: MathJax_Main;\">]</span><span class=\"mo\" id=\"MathJax-Span-12\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:<span style=\"font-family: MathJax_Main;\">=</span></span><span class=\"mo\" id=\"MathJax-Span-13\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">{</span><span class=\"mn\" id=\"MathJax-Span-14\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-15\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mn\" id=\"MathJax-Span-16\" style=\"font-family: MathJax_Main; padding-left: 0.182em;\">1</span><span class=\"mo\" id=\"MathJax-Span-17\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mo\" id=\"MathJax-Span-18\" style=\"font-family: MathJax_Main; padding-left: 0.182em;\">…</span><span class=\"mo\" id=\"MathJax-Span-19\" style=\"font-family: MathJax_Main; padding-left: 0.182em;\">,</span><span class=\"mi\" id=\"MathJax-Span-20\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">L</span><span class=\"mo\" id=\"MathJax-Span-21\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">−</span><span class=\"mn\" id=\"MathJax-Span-22\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">1</span><span class=\"mo\" id=\"MathJax-Span-23\" style=\"font-family: MathJax_Main;\">}</span><span class=\"mo\" id=\"MathJax-Span-24\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">→</span><span class=\"texatom\" id=\"MathJax-Span-25\" style=\"padding-left: 0.301em;\"><span class=\"mrow\" id=\"MathJax-Span-26\"><span class=\"texatom\" id=\"MathJax-Span-27\"><span class=\"mrow\" id=\"MathJax-Span-28\"><span class=\"mi\" id=\"MathJax-Span-29\" style=\"font-family: MathJax_AMS;\">R</span></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.503em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>x</mi><mo>:</mo><mo stretchy=\"false\">[</mo><mn>0</mn><mo>:</mo><mi>L</mi><mo>−</mo><mn>1</mn><mo stretchy=\"false\">]</mo><mo>:=</mo><mo fence=\"false\" stretchy=\"false\">{</mo><mn>0</mn><mo>,</mo><mn>1</mn><mo>,</mo><mo>…</mo><mo>,</mo><mi>L</mi><mo>−</mo><mn>1</mn><mo fence=\"false\" stretchy=\"false\">}</mo><mo stretchy=\"false\">→</mo><mrow class=\"MJX-TeXAtom-ORD\"><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"double-struck\">R</mi></mrow></mrow></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-1\">x:[0:L-1]:=\\{0,1,\\ldots,L-1\\}\\to{\\mathbb R}</script> be a real-valued discrete-time (DT) signal of length <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-2-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>L</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-30\" style=\"width: 0.836em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.658em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1000.6em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-31\"><span class=\"mi\" id=\"MathJax-Span-32\" style=\"font-family: MathJax_Math-italic;\">L</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>L</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-2\">L</script> obtained by equidistant sampling with respect to a fixed sampling rate <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-3-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><msub><mi>F</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>s</mi></mrow></msub></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-33\" style=\"width: 1.253em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 1.015em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1001.01em, 2.562em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-34\"><span class=\"msubsup\" id=\"MathJax-Span-35\"><span style=\"display: inline-block; position: relative; width: 1.015em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.78em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-36\" style=\"font-family: MathJax_Math-italic;\">F<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.658em;\"><span class=\"texatom\" id=\"MathJax-Span-37\"><span class=\"mrow\" id=\"MathJax-Span-38\"><span class=\"mi\" id=\"MathJax-Span-39\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">s</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.282em; border-left: 0px solid; width: 0px; height: 1.146em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><msub><mi>F</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">s</mi></mrow></msub></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-3\">F_\\mathrm{s}</script> given in Hertz. Furthermore, let <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-4-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>w</mi><mo>:</mo><mo stretchy=&quot;false&quot;>[</mo><mn>0</mn><mo>:</mo><mi>N</mi><mo>&amp;#x2212;</mo><mn>1</mn><mo stretchy=&quot;false&quot;>]</mo><mo stretchy=&quot;false&quot;>&amp;#x2192;</mo><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;double-struck&quot;>R</mi></mrow></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-40\" style=\"width: 10.182em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 8.455em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.551em, 1008.46em, 2.92em, -999.997em); top: -2.497em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-41\"><span class=\"mi\" id=\"MathJax-Span-42\" style=\"font-family: MathJax_Math-italic;\">w</span><span class=\"mo\" id=\"MathJax-Span-43\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mo\" id=\"MathJax-Span-44\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">[</span><span class=\"mn\" id=\"MathJax-Span-45\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-46\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mi\" id=\"MathJax-Span-47\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-48\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">−</span><span class=\"mn\" id=\"MathJax-Span-49\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">1</span><span class=\"mo\" id=\"MathJax-Span-50\" style=\"font-family: MathJax_Main;\">]</span><span class=\"mo\" id=\"MathJax-Span-51\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">→</span><span class=\"texatom\" id=\"MathJax-Span-52\" style=\"padding-left: 0.301em;\"><span class=\"mrow\" id=\"MathJax-Span-53\"><span class=\"mi\" id=\"MathJax-Span-54\" style=\"font-family: MathJax_AMS;\">R</span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.503em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>w</mi><mo>:</mo><mo stretchy=\"false\">[</mo><mn>0</mn><mo>:</mo><mi>N</mi><mo>−</mo><mn>1</mn><mo stretchy=\"false\">]</mo><mo stretchy=\"false\">→</mo><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"double-struck\">R</mi></mrow></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-4\">w:[0:N-1]\\to\\mathbb{R}</script> be a sampled  window function of length <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-5-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>N</mi><mo>&amp;#x2208;</mo><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;double-struck&quot;>N</mi></mrow></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-55\" style=\"width: 3.455em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 2.86em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.67em, 1002.86em, 2.741em, -999.997em); top: -2.497em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-56\"><span class=\"mi\" id=\"MathJax-Span-57\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-58\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">∈</span><span class=\"texatom\" id=\"MathJax-Span-59\" style=\"padding-left: 0.301em;\"><span class=\"mrow\" id=\"MathJax-Span-60\"><span class=\"mi\" id=\"MathJax-Span-61\" style=\"font-family: MathJax_AMS;\">N</span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.503em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.139em; border-left: 0px solid; width: 0px; height: 1.004em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>N</mi><mo>∈</mo><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"double-struck\">N</mi></mrow></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-5\">N\\in\\mathbb{N}</script>. For example, in the case of a rectangular window one has <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-6-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>w</mi><mo stretchy=&quot;false&quot;>(</mo><mi>n</mi><mo stretchy=&quot;false&quot;>)</mo><mo>=</mo><mn>1</mn></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-62\" style=\"width: 4.824em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 3.991em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1003.93em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-63\"><span class=\"mi\" id=\"MathJax-Span-64\" style=\"font-family: MathJax_Math-italic;\">w</span><span class=\"mo\" id=\"MathJax-Span-65\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-66\" style=\"font-family: MathJax_Math-italic;\">n</span><span class=\"mo\" id=\"MathJax-Span-67\" style=\"font-family: MathJax_Main;\">)</span><span class=\"mo\" id=\"MathJax-Span-68\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">=</span><span class=\"mn\" id=\"MathJax-Span-69\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">1</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>w</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo stretchy=\"false\">)</mo><mo>=</mo><mn>1</mn></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-6\">w(n)=1</script> for <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-7-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>n</mi><mo>&amp;#x2208;</mo><mo stretchy=&quot;false&quot;>[</mo><mn>0</mn><mo>:</mo><mi>N</mi><mo>&amp;#x2212;</mo><mn>1</mn><mo stretchy=&quot;false&quot;>]</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-70\" style=\"width: 7.741em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 6.432em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1006.31em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-71\"><span class=\"mi\" id=\"MathJax-Span-72\" style=\"font-family: MathJax_Math-italic;\">n</span><span class=\"mo\" id=\"MathJax-Span-73\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">∈</span><span class=\"mo\" id=\"MathJax-Span-74\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">[</span><span class=\"mn\" id=\"MathJax-Span-75\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-76\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mi\" id=\"MathJax-Span-77\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-78\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">−</span><span class=\"mn\" id=\"MathJax-Span-79\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">1</span><span class=\"mo\" id=\"MathJax-Span-80\" style=\"font-family: MathJax_Main;\">]</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>n</mi><mo>∈</mo><mo stretchy=\"false\">[</mo><mn>0</mn><mo>:</mo><mi>N</mi><mo>−</mo><mn>1</mn><mo stretchy=\"false\">]</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-7\">n\\in[0:N-1]</script>. The length parameter <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-8-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>N</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-81\" style=\"width: 1.074em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.896em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1000.9em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-82\"><span class=\"mi\" id=\"MathJax-Span-83\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>N</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-8\">N</script> determines the duration of the considered sections, which amounts to <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-9-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>N</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mo>/</mo></mrow><msub><mi>F</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>s</mi></mrow></msub></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-84\" style=\"width: 2.86em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 2.384em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1002.38em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-85\"><span class=\"mi\" id=\"MathJax-Span-86\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"texatom\" id=\"MathJax-Span-87\"><span class=\"mrow\" id=\"MathJax-Span-88\"><span class=\"mo\" id=\"MathJax-Span-89\" style=\"font-family: MathJax_Main;\">/</span></span></span><span class=\"msubsup\" id=\"MathJax-Span-90\"><span style=\"display: inline-block; position: relative; width: 1.015em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.78em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-91\" style=\"font-family: MathJax_Math-italic;\">F<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.658em;\"><span class=\"texatom\" id=\"MathJax-Span-92\"><span class=\"mrow\" id=\"MathJax-Span-93\"><span class=\"mi\" id=\"MathJax-Span-94\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">s</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>N</mi><mrow class=\"MJX-TeXAtom-ORD\"><mo>/</mo></mrow><msub><mi>F</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">s</mi></mrow></msub></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-9\">N/F_\\mathrm{s}</script> seconds. One also introduces an additional parameter <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-10-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>H</mi><mo>&amp;#x2208;</mo><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;double-struck&quot;>N</mi></mrow></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-95\" style=\"width: 3.455em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 2.86em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.67em, 1002.86em, 2.741em, -999.997em); top: -2.497em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-96\"><span class=\"mi\" id=\"MathJax-Span-97\" style=\"font-family: MathJax_Math-italic;\">H<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-98\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">∈</span><span class=\"texatom\" id=\"MathJax-Span-99\" style=\"padding-left: 0.301em;\"><span class=\"mrow\" id=\"MathJax-Span-100\"><span class=\"mi\" id=\"MathJax-Span-101\" style=\"font-family: MathJax_AMS;\">N</span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.503em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.139em; border-left: 0px solid; width: 0px; height: 1.004em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>H</mi><mo>∈</mo><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"double-struck\">N</mi></mrow></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-10\">H\\in\\mathbb{N}</script>, which is referred to as the <strong>hop size</strong>.  The hop size parameter is specified in samples and determines the step size in which the window is to be shifted across the signal. With regard to these parameters, the <strong>discrete STFT</strong> <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-11-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi class=&quot;MJX-tex-caligraphic&quot; mathvariant=&quot;script&quot;>X</mi></mrow></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-102\" style=\"width: 1.015em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.836em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1000.84em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-103\"><span class=\"texatom\" id=\"MathJax-Span-104\"><span class=\"mrow\" id=\"MathJax-Span-105\"><span class=\"mi\" id=\"MathJax-Span-106\" style=\"font-family: MathJax_Caligraphic;\">X<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow class=\"MJX-TeXAtom-ORD\"><mi class=\"MJX-tex-caligraphic\" mathvariant=\"script\">X</mi></mrow></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-11\">\\mathcal{X}</script> of the signal <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-12-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>x</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-107\" style=\"width: 0.717em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.598em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.61em, 1000.54em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-108\"><span class=\"mi\" id=\"MathJax-Span-109\" style=\"font-family: MathJax_Math-italic;\">x</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.718em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>x</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-12\">x</script> is given by</p>\n<span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><div class=\"MathJax_Display\" style=\"text-align: center;\"><span class=\"MathJax\" id=\"MathJax-Element-13-Frame\" tabindex=\"0\" style=\"text-align: center; position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;><mtable columnalign=&quot;right center left&quot; rowspacing=&quot;3pt&quot; columnspacing=&quot;0 thickmathspace&quot; displaystyle=&quot;true&quot;><mtr><mtd><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi class=&quot;MJX-tex-caligraphic&quot; mathvariant=&quot;script&quot;>X</mi></mrow><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=&quot;false&quot;>)</mo><mo>:=</mo><munderover><mo>&amp;#x2211;</mo><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi>N</mi><mo>&amp;#x2212;</mo><mn>1</mn></mrow></munderover><mi>x</mi><mo stretchy=&quot;false&quot;>(</mo><mi>n</mi><mo>+</mo><mi>m</mi><mi>H</mi><mo stretchy=&quot;false&quot;>)</mo><mi>w</mi><mo stretchy=&quot;false&quot;>(</mo><mi>n</mi><mo stretchy=&quot;false&quot;>)</mo><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>e</mi><mi mathvariant=&quot;normal&quot;>x</mi><mi mathvariant=&quot;normal&quot;>p</mi></mrow><mo stretchy=&quot;false&quot;>(</mo><mo>&amp;#x2212;</mo><mn>2</mn><mi>&amp;#x03C0;</mi><mi>i</mi><mi>k</mi><mi>n</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mo>/</mo></mrow><mi>N</mi><mo stretchy=&quot;false&quot;>)</mo></mtd></mtr></mtable></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-110\" style=\"width: 25.539em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 21.253em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(0.301em, 1021.13em, 3.574em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-111\"><span class=\"mtable\" id=\"MathJax-Span-112\"><span style=\"display: inline-block; position: relative; width: 20.896em; height: 0px; margin-right: 0.182em; margin-left: 0.182em;\"><span style=\"position: absolute; clip: rect(2.086em, 1020.78em, 5.36em, -999.997em); top: -3.985em; left: 0em;\"><span style=\"display: inline-block; position: relative; width: 20.896em; height: 0px;\"><span style=\"position: absolute; clip: rect(2.086em, 1020.78em, 5.36em, -999.997em); top: -3.985em; right: 0em;\"><span class=\"mtd\" id=\"MathJax-Span-113\"><span class=\"mrow\" id=\"MathJax-Span-114\"><span class=\"texatom\" id=\"MathJax-Span-115\"><span class=\"mrow\" id=\"MathJax-Span-116\"><span class=\"mi\" id=\"MathJax-Span-117\" style=\"font-family: MathJax_Caligraphic;\">X<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-118\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-119\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-120\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mi\" id=\"MathJax-Span-121\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">k</span><span class=\"mo\" id=\"MathJax-Span-122\" style=\"font-family: MathJax_Main;\">)</span><span class=\"mo\" id=\"MathJax-Span-123\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:<span style=\"font-family: MathJax_Main;\">=</span></span><span class=\"munderover\" id=\"MathJax-Span-124\" style=\"padding-left: 0.301em;\"><span style=\"display: inline-block; position: relative; width: 1.551em; height: 0px;\"><span style=\"position: absolute; clip: rect(2.86em, 1001.37em, 4.646em, -999.997em); top: -3.985em; left: 0.063em;\"><span class=\"mo\" id=\"MathJax-Span-125\" style=\"font-family: MathJax_Size2; vertical-align: 0em;\">∑</span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(3.336em, 1001.31em, 4.289em, -999.997em); top: -2.914em; left: 0.122em;\"><span class=\"texatom\" id=\"MathJax-Span-126\"><span class=\"mrow\" id=\"MathJax-Span-127\"><span class=\"mi\" id=\"MathJax-Span-128\" style=\"font-size: 70.7%; font-family: MathJax_Math-italic;\">n</span><span class=\"mo\" id=\"MathJax-Span-129\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">=</span><span class=\"mn\" id=\"MathJax-Span-130\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">0</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(3.217em, 1001.49em, 4.229em, -999.997em); top: -5.116em; left: 0em;\"><span class=\"texatom\" id=\"MathJax-Span-131\"><span class=\"mrow\" id=\"MathJax-Span-132\"><span class=\"mi\" id=\"MathJax-Span-133\" style=\"font-size: 70.7%; font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-134\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">−</span><span class=\"mn\" id=\"MathJax-Span-135\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">1</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span><span class=\"mi\" id=\"MathJax-Span-136\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">x</span><span class=\"mo\" id=\"MathJax-Span-137\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-138\" style=\"font-family: MathJax_Math-italic;\">n</span><span class=\"mo\" id=\"MathJax-Span-139\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">+</span><span class=\"mi\" id=\"MathJax-Span-140\" style=\"font-family: MathJax_Math-italic; padding-left: 0.241em;\">m</span><span class=\"mi\" id=\"MathJax-Span-141\" style=\"font-family: MathJax_Math-italic;\">H<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-142\" style=\"font-family: MathJax_Main;\">)</span><span class=\"mi\" id=\"MathJax-Span-143\" style=\"font-family: MathJax_Math-italic;\">w</span><span class=\"mo\" id=\"MathJax-Span-144\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-145\" style=\"font-family: MathJax_Math-italic;\">n</span><span class=\"mo\" id=\"MathJax-Span-146\" style=\"font-family: MathJax_Main;\">)</span><span class=\"texatom\" id=\"MathJax-Span-147\"><span class=\"mrow\" id=\"MathJax-Span-148\"><span class=\"mi\" id=\"MathJax-Span-149\" style=\"font-family: MathJax_Main;\">e</span><span class=\"mi\" id=\"MathJax-Span-150\" style=\"font-family: MathJax_Main;\">x</span><span class=\"mi\" id=\"MathJax-Span-151\" style=\"font-family: MathJax_Main;\">p</span></span></span><span class=\"mo\" id=\"MathJax-Span-152\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mo\" id=\"MathJax-Span-153\" style=\"font-family: MathJax_Main;\">−</span><span class=\"mn\" id=\"MathJax-Span-154\" style=\"font-family: MathJax_Main;\">2</span><span class=\"mi\" id=\"MathJax-Span-155\" style=\"font-family: MathJax_Math-italic;\">π<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.003em;\"></span></span><span class=\"mi\" id=\"MathJax-Span-156\" style=\"font-family: MathJax_Math-italic;\">i</span><span class=\"mi\" id=\"MathJax-Span-157\" style=\"font-family: MathJax_Math-italic;\">k</span><span class=\"mi\" id=\"MathJax-Span-158\" style=\"font-family: MathJax_Math-italic;\">n</span><span class=\"texatom\" id=\"MathJax-Span-159\"><span class=\"mrow\" id=\"MathJax-Span-160\"><span class=\"mo\" id=\"MathJax-Span-161\" style=\"font-family: MathJax_Main;\">/</span></span></span><span class=\"mi\" id=\"MathJax-Span-162\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-163\" style=\"font-family: MathJax_Main;\">)</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -1.496em; border-left: 0px solid; width: 0px; height: 3.646em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML MJX_Assistive_MathML_Block\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><mtable columnalign=\"right center left\" rowspacing=\"3pt\" columnspacing=\"0 thickmathspace\" displaystyle=\"true\"><mtr><mtd><mrow class=\"MJX-TeXAtom-ORD\"><mi class=\"MJX-tex-caligraphic\" mathvariant=\"script\">X</mi></mrow><mo stretchy=\"false\">(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=\"false\">)</mo><mo>:=</mo><munderover><mo>∑</mo><mrow class=\"MJX-TeXAtom-ORD\"><mi>n</mi><mo>=</mo><mn>0</mn></mrow><mrow class=\"MJX-TeXAtom-ORD\"><mi>N</mi><mo>−</mo><mn>1</mn></mrow></munderover><mi>x</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo>+</mo><mi>m</mi><mi>H</mi><mo stretchy=\"false\">)</mo><mi>w</mi><mo stretchy=\"false\">(</mo><mi>n</mi><mo stretchy=\"false\">)</mo><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">e</mi><mi mathvariant=\"normal\">x</mi><mi mathvariant=\"normal\">p</mi></mrow><mo stretchy=\"false\">(</mo><mo>−</mo><mn>2</mn><mi>π</mi><mi>i</mi><mi>k</mi><mi>n</mi><mrow class=\"MJX-TeXAtom-ORD\"><mo>/</mo></mrow><mi>N</mi><mo stretchy=\"false\">)</mo></mtd></mtr></mtable></math></span></span></div><script type=\"math/tex; mode=display\" id=\"MathJax-Element-13\">\\begin{eqnarray}\n   \\mathcal{X}(m,k):= \\sum_{n=0}^{N-1} x(n+mH)w(n)\\mathrm{exp}(-2\\pi ikn/N)\n\\end{eqnarray}</script><p></p>\n<p>with <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-14-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>m</mi><mo>&amp;#x2208;</mo><mo stretchy=&quot;false&quot;>[</mo><mn>0</mn><mo>:</mo><mi>M</mi><mo stretchy=&quot;false&quot;>]</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-164\" style=\"width: 6.193em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 5.122em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1005em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-165\"><span class=\"mi\" id=\"MathJax-Span-166\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-167\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">∈</span><span class=\"mo\" id=\"MathJax-Span-168\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">[</span><span class=\"mn\" id=\"MathJax-Span-169\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-170\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mi\" id=\"MathJax-Span-171\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">M<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-172\" style=\"font-family: MathJax_Main;\">]</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>m</mi><mo>∈</mo><mo stretchy=\"false\">[</mo><mn>0</mn><mo>:</mo><mi>M</mi><mo stretchy=\"false\">]</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-14\">m\\in[0:M]</script> and <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-15-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>k</mi><mo>&amp;#x2208;</mo><mo stretchy=&quot;false&quot;>[</mo><mn>0</mn><mo>:</mo><mi>K</mi><mo stretchy=&quot;false&quot;>]</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-173\" style=\"width: 5.598em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 4.646em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1004.53em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-174\"><span class=\"mi\" id=\"MathJax-Span-175\" style=\"font-family: MathJax_Math-italic;\">k</span><span class=\"mo\" id=\"MathJax-Span-176\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">∈</span><span class=\"mo\" id=\"MathJax-Span-177\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">[</span><span class=\"mn\" id=\"MathJax-Span-178\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-179\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mi\" id=\"MathJax-Span-180\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">K<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-181\" style=\"font-family: MathJax_Main;\">]</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>k</mi><mo>∈</mo><mo stretchy=\"false\">[</mo><mn>0</mn><mo>:</mo><mi>K</mi><mo stretchy=\"false\">]</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-15\">k\\in[0:K]</script>. The number <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-16-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>M</mi><mo>:=</mo><mo fence=&quot;false&quot; stretchy=&quot;false&quot;>&amp;#x230A;</mo><mfrac><mrow><mi>L</mi><mo>&amp;#x2212;</mo><mi>N</mi></mrow><mi>H</mi></mfrac><mo fence=&quot;false&quot; stretchy=&quot;false&quot;>&amp;#x230B;</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-182\" style=\"width: 6.729em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 5.598em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.074em, 1005.42em, 2.801em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-183\"><span class=\"mi\" id=\"MathJax-Span-184\" style=\"font-family: MathJax_Math-italic;\">M<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-185\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:<span style=\"font-family: MathJax_Main;\">=</span></span><span class=\"mo\" id=\"MathJax-Span-186\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">⌊</span><span class=\"mfrac\" id=\"MathJax-Span-187\"><span style=\"display: inline-block; position: relative; width: 1.789em; height: 0px; margin-right: 0.122em; margin-left: 0.122em;\"><span style=\"position: absolute; clip: rect(3.336em, 1001.67em, 4.229em, -999.997em); top: -4.461em; left: 50%; margin-left: -0.83em;\"><span class=\"mrow\" id=\"MathJax-Span-188\"><span class=\"mi\" id=\"MathJax-Span-189\" style=\"font-size: 70.7%; font-family: MathJax_Math-italic;\">L</span><span class=\"mo\" id=\"MathJax-Span-190\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">−</span><span class=\"mi\" id=\"MathJax-Span-191\" style=\"font-size: 70.7%; font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(3.336em, 1000.66em, 4.17em, -999.997em); top: -3.568em; left: 50%; margin-left: -0.295em;\"><span class=\"mi\" id=\"MathJax-Span-192\" style=\"font-size: 70.7%; font-family: MathJax_Math-italic;\">H<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(0.836em, 1001.79em, 1.253em, -999.997em); top: -1.307em; left: 0em;\"><span style=\"display: inline-block; overflow: hidden; vertical-align: 0em; border-top: 1.3px solid; width: 1.789em; height: 0px;\"></span><span style=\"display: inline-block; width: 0px; height: 1.074em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-193\" style=\"font-family: MathJax_Main;\">⌋</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.568em; border-left: 0px solid; width: 0px; height: 1.789em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>M</mi><mo>:=</mo><mo fence=\"false\" stretchy=\"false\">⌊</mo><mfrac><mrow><mi>L</mi><mo>−</mo><mi>N</mi></mrow><mi>H</mi></mfrac><mo fence=\"false\" stretchy=\"false\">⌋</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-16\">M:=\\lfloor \\frac{L-N}{H} \\rfloor</script> is the maximal frame index such that the window's time range is fully contained in the signal's time range. (We will see later some variants using padding strategies.) Furthermore, <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-17-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>K</mi><mo>=</mo><mi>N</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mo>/</mo></mrow><mn>2</mn></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-194\" style=\"width: 5.003em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 4.17em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1004.11em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-195\"><span class=\"mi\" id=\"MathJax-Span-196\" style=\"font-family: MathJax_Math-italic;\">K<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-197\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">=</span><span class=\"mi\" id=\"MathJax-Span-198\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"texatom\" id=\"MathJax-Span-199\"><span class=\"mrow\" id=\"MathJax-Span-200\"><span class=\"mo\" id=\"MathJax-Span-201\" style=\"font-family: MathJax_Main;\">/</span></span></span><span class=\"mn\" id=\"MathJax-Span-202\" style=\"font-family: MathJax_Main;\">2</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>K</mi><mo>=</mo><mi>N</mi><mrow class=\"MJX-TeXAtom-ORD\"><mo>/</mo></mrow><mn>2</mn></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-17\">K=N/2</script> (assuming that <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-18-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>N</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-203\" style=\"width: 1.074em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.896em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1000.9em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-204\"><span class=\"mi\" id=\"MathJax-Span-205\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>N</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-18\">N</script> is even) is the frequency index corresponding to the Nyquist frequency. The complex number <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-19-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi class=&quot;MJX-tex-caligraphic&quot; mathvariant=&quot;script&quot;>X</mi></mrow><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=&quot;false&quot;>)</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-206\" style=\"width: 4.17em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 3.455em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1003.34em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-207\"><span class=\"texatom\" id=\"MathJax-Span-208\"><span class=\"mrow\" id=\"MathJax-Span-209\"><span class=\"mi\" id=\"MathJax-Span-210\" style=\"font-family: MathJax_Caligraphic;\">X<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-211\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-212\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-213\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mi\" id=\"MathJax-Span-214\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">k</span><span class=\"mo\" id=\"MathJax-Span-215\" style=\"font-family: MathJax_Main;\">)</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow class=\"MJX-TeXAtom-ORD\"><mi class=\"MJX-tex-caligraphic\" mathvariant=\"script\">X</mi></mrow><mo stretchy=\"false\">(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=\"false\">)</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-19\"> \\mathcal{X}(m,k)</script> denotes the <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-20-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><msup><mi>k</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>t</mi><mi mathvariant=&quot;normal&quot;>h</mi></mrow></mrow></msup></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-216\" style=\"width: 1.551em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 1.253em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.193em, 1001.25em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-217\"><span class=\"msubsup\" id=\"MathJax-Span-218\"><span style=\"display: inline-block; position: relative; width: 1.253em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.098em, 1000.48em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-219\" style=\"font-family: MathJax_Math-italic;\">k</span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -4.342em; left: 0.539em;\"><span class=\"texatom\" id=\"MathJax-Span-220\"><span class=\"mrow\" id=\"MathJax-Span-221\"><span class=\"texatom\" id=\"MathJax-Span-222\"><span class=\"mrow\" id=\"MathJax-Span-223\"><span class=\"mi\" id=\"MathJax-Span-224\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">t</span><span class=\"mi\" id=\"MathJax-Span-225\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">h</span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 1.218em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><msup><mi>k</mi><mrow class=\"MJX-TeXAtom-ORD\"><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">t</mi><mi mathvariant=\"normal\">h</mi></mrow></mrow></msup></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-20\">k^{\\mathrm{th}}</script> Fourier coefficient for the <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-21-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><msup><mi>m</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>t</mi><mi mathvariant=&quot;normal&quot;>h</mi></mrow></mrow></msup></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-226\" style=\"width: 1.967em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 1.61em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.193em, 1001.61em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-227\"><span class=\"msubsup\" id=\"MathJax-Span-228\"><span style=\"display: inline-block; position: relative; width: 1.61em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.396em, 1000.84em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-229\" style=\"font-family: MathJax_Math-italic;\">m</span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -4.342em; left: 0.896em;\"><span class=\"texatom\" id=\"MathJax-Span-230\"><span class=\"mrow\" id=\"MathJax-Span-231\"><span class=\"texatom\" id=\"MathJax-Span-232\"><span class=\"mrow\" id=\"MathJax-Span-233\"><span class=\"mi\" id=\"MathJax-Span-234\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">t</span><span class=\"mi\" id=\"MathJax-Span-235\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">h</span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 1.218em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><msup><mi>m</mi><mrow class=\"MJX-TeXAtom-ORD\"><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">t</mi><mi mathvariant=\"normal\">h</mi></mrow></mrow></msup></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-21\">m^{\\mathrm{th}}</script> time frame.  Note that for each fixed time frame <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-22-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>m</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-236\" style=\"width: 1.074em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.896em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.61em, 1000.9em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-237\"><span class=\"mi\" id=\"MathJax-Span-238\" style=\"font-family: MathJax_Math-italic;\">m</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.718em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>m</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-22\">m</script>, one obtains a <strong>spectral vector</strong> of size <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-23-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>K</mi><mo>+</mo><mn>1</mn></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-239\" style=\"width: 3.217em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 2.682em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1002.62em, 2.443em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-240\"><span class=\"mi\" id=\"MathJax-Span-241\" style=\"font-family: MathJax_Math-italic;\">K<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-242\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">+</span><span class=\"mn\" id=\"MathJax-Span-243\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">1</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.139em; border-left: 0px solid; width: 0px; height: 1.075em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>K</mi><mo>+</mo><mn>1</mn></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-23\">K+1</script> given by the coefficients <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-24-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi class=&quot;MJX-tex-caligraphic&quot; mathvariant=&quot;script&quot;>X</mi></mrow><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=&quot;false&quot;>)</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-244\" style=\"width: 4.17em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 3.455em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1003.34em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-245\"><span class=\"texatom\" id=\"MathJax-Span-246\"><span class=\"mrow\" id=\"MathJax-Span-247\"><span class=\"mi\" id=\"MathJax-Span-248\" style=\"font-family: MathJax_Caligraphic;\">X<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-249\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-250\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-251\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mi\" id=\"MathJax-Span-252\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">k</span><span class=\"mo\" id=\"MathJax-Span-253\" style=\"font-family: MathJax_Main;\">)</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow class=\"MJX-TeXAtom-ORD\"><mi class=\"MJX-tex-caligraphic\" mathvariant=\"script\">X</mi></mrow><mo stretchy=\"false\">(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=\"false\">)</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-24\">\\mathcal{X}(m,k)</script> for <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-25-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>k</mi><mo>&amp;#x2208;</mo><mo stretchy=&quot;false&quot;>[</mo><mn>0</mn><mo>:</mo><mi>K</mi><mo stretchy=&quot;false&quot;>]</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-254\" style=\"width: 5.598em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 4.646em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1004.53em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-255\"><span class=\"mi\" id=\"MathJax-Span-256\" style=\"font-family: MathJax_Math-italic;\">k</span><span class=\"mo\" id=\"MathJax-Span-257\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">∈</span><span class=\"mo\" id=\"MathJax-Span-258\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">[</span><span class=\"mn\" id=\"MathJax-Span-259\" style=\"font-family: MathJax_Main;\">0</span><span class=\"mo\" id=\"MathJax-Span-260\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:</span><span class=\"mi\" id=\"MathJax-Span-261\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">K<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-262\" style=\"font-family: MathJax_Main;\">]</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>k</mi><mo>∈</mo><mo stretchy=\"false\">[</mo><mn>0</mn><mo>:</mo><mi>K</mi><mo stretchy=\"false\">]</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-25\">k\\in[0:K]</script>. The computation of each such spectral vector amounts to a DFT of size <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-26-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>N</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-263\" style=\"width: 1.074em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.896em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1000.9em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-264\"><span class=\"mi\" id=\"MathJax-Span-265\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>N</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-26\">N</script>, which can be done efficiently using the FFT (see <a href=\"../C2/C2_DFT-FFT.html\">the FMP notebook on the FFT)</a>.</p>\n\n</div>","metadata":{}},{"cell_type":"markdown","source":"Spectrogram\nThe spectrogram is a two-dimensional representation of the squared magnitude of the STFT","metadata":{}},{"cell_type":"code","source":"def stft_basic(x, w, H=8, only_positive_frequencies=False):\n    \"\"\"Compute a basic version of the discrete short-time Fourier transform (STFT)\n\n    Notebook: C2/C2_STFT-Basic.ipynb\n\n    Args:\n        x (np.ndarray): Signal to be transformed\n        w (np.ndarray): Window function\n        H (int): Hopsize (Default value = 8)\n        only_positive_frequencies (bool): Return only positive frequency part of spectrum (non-invertible)\n            (Default value = False)\n\n    Returns:\n        X (np.ndarray): The discrete short-time Fourier transform\n    \"\"\"\n    N = len(w)\n    L = len(x)\n    M = np.floor((L - N) / H).astype(int) + 1\n    X = np.zeros((N, M), dtype='complex')\n    for m in range(M):\n        x_win = x[m * H:m * H + N] * w\n        X_win = np.fft.fft(x_win)\n        X[:, m] = X_win\n\n    if only_positive_frequencies:\n        K = 1 + N // 2\n        X = X[0:K, :]\n    return X\n\nH = 8\nN = 128\nw = np.ones(N)\nX = stft_basic(x, w, H, only_positive_frequencies=True)\nY = np.abs(X) ** 2\n\nplt.figure(figsize=(8, 2))\nplt.subplot(1, 2, 1)\nplt.plot(np.arange(len(t)), x, c='k')\nplt.xlim([0, len(t)])\nplt.xlabel('Index (samples)')\nplt.subplot(1, 2, 2)\nplt.imshow(Y, origin='lower', aspect='auto', cmap='gray_r')\nplt.xlabel('Index (frames)')\nplt.ylabel('Index (frequency)')\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:44:40.48772Z","iopub.execute_input":"2022-10-26T21:44:40.488251Z","iopub.status.idle":"2022-10-26T21:44:40.860639Z","shell.execute_reply.started":"2022-10-26T21:44:40.488216Z","shell.execute_reply":"2022-10-26T21:44:40.859375Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<div class=\"cell border-box-sizing text_cell rendered\"><div class=\"prompt input_prompt\">\n</div><div class=\"inner_cell\">\n<div class=\"text_cell_render border-box-sizing rendered_html\">\n<h2 id=\"Interpretation-of-Time-and-Frequency-Indices\">Interpretation of Time and Frequency Indices<a class=\"anchor-link\" href=\"#Interpretation-of-Time-and-Frequency-Indices\">¶</a></h2><p>As for the temporal dimension, each Fourier coefficient <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-32-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi class=&quot;MJX-tex-caligraphic&quot; mathvariant=&quot;script&quot;>X</mi></mrow><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=&quot;false&quot;>)</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-320\" style=\"width: 4.17em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 3.455em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1003.34em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-321\"><span class=\"texatom\" id=\"MathJax-Span-322\"><span class=\"mrow\" id=\"MathJax-Span-323\"><span class=\"mi\" id=\"MathJax-Span-324\" style=\"font-family: MathJax_Caligraphic;\">X<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-325\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-326\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-327\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mi\" id=\"MathJax-Span-328\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">k</span><span class=\"mo\" id=\"MathJax-Span-329\" style=\"font-family: MathJax_Main;\">)</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow class=\"MJX-TeXAtom-ORD\"><mi class=\"MJX-tex-caligraphic\" mathvariant=\"script\">X</mi></mrow><mo stretchy=\"false\">(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=\"false\">)</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-32\">\\mathcal{X}(m,k)</script> is associated with the physical time position</p>\n<span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><div class=\"MathJax_Display\" style=\"text-align: center;\"><span class=\"MathJax\" id=\"MathJax-Element-33-Frame\" tabindex=\"0\" style=\"text-align: center; position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;><msub><mi>T</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>c</mi><mi mathvariant=&quot;normal&quot;>o</mi><mi mathvariant=&quot;normal&quot;>e</mi><mi mathvariant=&quot;normal&quot;>f</mi></mrow></msub><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo stretchy=&quot;false&quot;>)</mo><mo>:=</mo><mfrac><mrow><mi>m</mi><mo>&amp;#x22C5;</mo><mi>H</mi></mrow><msub><mi>F</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>s</mi></mrow></msub></mfrac></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-330\" style=\"width: 9.765em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 8.098em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(0.658em, 1008.1em, 3.217em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-331\"><span class=\"msubsup\" id=\"MathJax-Span-332\"><span style=\"display: inline-block; position: relative; width: 1.908em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.72em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-333\" style=\"font-family: MathJax_Math-italic;\">T<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.598em;\"><span class=\"texatom\" id=\"MathJax-Span-334\"><span class=\"mrow\" id=\"MathJax-Span-335\"><span class=\"mi\" id=\"MathJax-Span-336\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">c</span><span class=\"mi\" id=\"MathJax-Span-337\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">o</span><span class=\"mi\" id=\"MathJax-Span-338\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">e</span><span class=\"mi\" id=\"MathJax-Span-339\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">f<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-340\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-341\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-342\" style=\"font-family: MathJax_Main;\">)</span><span class=\"mo\" id=\"MathJax-Span-343\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:<span style=\"font-family: MathJax_Main;\">=</span></span><span class=\"mfrac\" id=\"MathJax-Span-344\" style=\"padding-left: 0.301em;\"><span style=\"display: inline-block; position: relative; width: 2.622em; height: 0px; margin-right: 0.122em; margin-left: 0.122em;\"><span style=\"position: absolute; clip: rect(3.158em, 1002.5em, 4.17em, -999.997em); top: -4.64em; left: 50%; margin-left: -1.247em;\"><span class=\"mrow\" id=\"MathJax-Span-345\"><span class=\"mi\" id=\"MathJax-Span-346\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-347\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">⋅</span><span class=\"mi\" id=\"MathJax-Span-348\" style=\"font-family: MathJax_Math-italic; padding-left: 0.241em;\">H<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(3.158em, 1001.01em, 4.348em, -999.997em); top: -3.271em; left: 50%; margin-left: -0.473em;\"><span class=\"msubsup\" id=\"MathJax-Span-349\"><span style=\"display: inline-block; position: relative; width: 1.015em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.78em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-350\" style=\"font-family: MathJax_Math-italic;\">F<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.658em;\"><span class=\"texatom\" id=\"MathJax-Span-351\"><span class=\"mrow\" id=\"MathJax-Span-352\"><span class=\"mi\" id=\"MathJax-Span-353\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">s</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(0.836em, 1002.62em, 1.253em, -999.997em); top: -1.307em; left: 0em;\"><span style=\"display: inline-block; overflow: hidden; vertical-align: 0em; border-top: 1.3px solid; width: 2.622em; height: 0px;\"></span><span style=\"display: inline-block; width: 0px; height: 1.074em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -1.068em; border-left: 0px solid; width: 0px; height: 2.789em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML MJX_Assistive_MathML_Block\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><msub><mi>T</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">c</mi><mi mathvariant=\"normal\">o</mi><mi mathvariant=\"normal\">e</mi><mi mathvariant=\"normal\">f</mi></mrow></msub><mo stretchy=\"false\">(</mo><mi>m</mi><mo stretchy=\"false\">)</mo><mo>:=</mo><mfrac><mrow><mi>m</mi><mo>⋅</mo><mi>H</mi></mrow><msub><mi>F</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">s</mi></mrow></msub></mfrac></math></span></span></div><script type=\"math/tex; mode=display\" id=\"MathJax-Element-33\">\\begin{equation}\n         T_\\mathrm{coef}(m) := \\frac{m\\cdot H}{F_\\mathrm{s}}\n\\end{equation}</script><p>given in seconds. For example, for the smallest possible hop size <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-34-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>H</mi><mo>=</mo><mn>1</mn></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-354\" style=\"width: 3.396em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 2.801em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1002.74em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-355\"><span class=\"mi\" id=\"MathJax-Span-356\" style=\"font-family: MathJax_Math-italic;\">H<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-357\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">=</span><span class=\"mn\" id=\"MathJax-Span-358\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">1</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>H</mi><mo>=</mo><mn>1</mn></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-34\">H=1</script>, one obtains <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-35-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><msub><mi>T</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>c</mi><mi mathvariant=&quot;normal&quot;>o</mi><mi mathvariant=&quot;normal&quot;>e</mi><mi mathvariant=&quot;normal&quot;>f</mi></mrow></msub><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo stretchy=&quot;false&quot;>)</mo><mo>=</mo><mi>m</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mo>/</mo></mrow><msub><mi>F</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>s</mi></mrow></msub><mo>=</mo><mi>m</mi><mo>&amp;#x22C5;</mo><mi>T</mi><mtext>&amp;#xA0;</mtext><mi>sec</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-359\" style=\"width: 15.36em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 12.801em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1012.8em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-360\"><span class=\"msubsup\" id=\"MathJax-Span-361\"><span style=\"display: inline-block; position: relative; width: 1.908em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.72em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-362\" style=\"font-family: MathJax_Math-italic;\">T<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.598em;\"><span class=\"texatom\" id=\"MathJax-Span-363\"><span class=\"mrow\" id=\"MathJax-Span-364\"><span class=\"mi\" id=\"MathJax-Span-365\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">c</span><span class=\"mi\" id=\"MathJax-Span-366\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">o</span><span class=\"mi\" id=\"MathJax-Span-367\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">e</span><span class=\"mi\" id=\"MathJax-Span-368\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">f<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-369\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-370\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-371\" style=\"font-family: MathJax_Main;\">)</span><span class=\"mo\" id=\"MathJax-Span-372\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">=</span><span class=\"mi\" id=\"MathJax-Span-373\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">m</span><span class=\"texatom\" id=\"MathJax-Span-374\"><span class=\"mrow\" id=\"MathJax-Span-375\"><span class=\"mo\" id=\"MathJax-Span-376\" style=\"font-family: MathJax_Main;\">/</span></span></span><span class=\"msubsup\" id=\"MathJax-Span-377\"><span style=\"display: inline-block; position: relative; width: 1.015em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.78em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-378\" style=\"font-family: MathJax_Math-italic;\">F<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.658em;\"><span class=\"texatom\" id=\"MathJax-Span-379\"><span class=\"mrow\" id=\"MathJax-Span-380\"><span class=\"mi\" id=\"MathJax-Span-381\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">s</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-382\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">=</span><span class=\"mi\" id=\"MathJax-Span-383\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">m</span><span class=\"mo\" id=\"MathJax-Span-384\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">⋅</span><span class=\"mi\" id=\"MathJax-Span-385\" style=\"font-family: MathJax_Math-italic; padding-left: 0.241em;\">T<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span class=\"mtext\" id=\"MathJax-Span-386\" style=\"font-family: MathJax_Main;\">&nbsp;</span><span class=\"mi\" id=\"MathJax-Span-387\" style=\"font-family: MathJax_Main; padding-left: 0.182em;\">sec</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><msub><mi>T</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">c</mi><mi mathvariant=\"normal\">o</mi><mi mathvariant=\"normal\">e</mi><mi mathvariant=\"normal\">f</mi></mrow></msub><mo stretchy=\"false\">(</mo><mi>m</mi><mo stretchy=\"false\">)</mo><mo>=</mo><mi>m</mi><mrow class=\"MJX-TeXAtom-ORD\"><mo>/</mo></mrow><msub><mi>F</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">s</mi></mrow></msub><mo>=</mo><mi>m</mi><mo>⋅</mo><mi>T</mi><mtext>&nbsp;</mtext><mi>sec</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-35\">T_\\mathrm{coef}(m)=m/F_\\mathrm{s}=m\\cdot T~\\sec</script>. In this case, one obtains a spectral vector for each sample of the DT-signal <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-36-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>x</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-388\" style=\"width: 0.717em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.598em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.61em, 1000.54em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-389\"><span class=\"mi\" id=\"MathJax-Span-390\" style=\"font-family: MathJax_Math-italic;\">x</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.718em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>x</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-36\">x</script>, which results in a huge increase in data volume. Furthermore, considering sections that are only shifted by one sample generally yields very similar spectral vectors. To reduce this type of redundancy, one typically relates the hop size to the length <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-37-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>N</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-391\" style=\"width: 1.074em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.896em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.372em, 1000.9em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-392\"><span class=\"mi\" id=\"MathJax-Span-393\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 0.932em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>N</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-37\">N</script> of the window. For example, one often chooses <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-38-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>H</mi><mo>=</mo><mi>N</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mo>/</mo></mrow><mn>2</mn></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-394\" style=\"width: 5.003em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 4.17em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1004.11em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-395\"><span class=\"mi\" id=\"MathJax-Span-396\" style=\"font-family: MathJax_Math-italic;\">H<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"mo\" id=\"MathJax-Span-397\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">=</span><span class=\"mi\" id=\"MathJax-Span-398\" style=\"font-family: MathJax_Math-italic; padding-left: 0.301em;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span class=\"texatom\" id=\"MathJax-Span-399\"><span class=\"mrow\" id=\"MathJax-Span-400\"><span class=\"mo\" id=\"MathJax-Span-401\" style=\"font-family: MathJax_Main;\">/</span></span></span><span class=\"mn\" id=\"MathJax-Span-402\" style=\"font-family: MathJax_Main;\">2</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>H</mi><mo>=</mo><mi>N</mi><mrow class=\"MJX-TeXAtom-ORD\"><mo>/</mo></mrow><mn>2</mn></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-38\">H=N/2</script>, which constitutes a good trade-off between a reasonable temporal resolution and the data volume comprising all generated spectral coefficients. As for the frequency dimension, the index <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-39-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mi>k</mi></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-403\" style=\"width: 0.658em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 0.539em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.313em, 1000.54em, 2.384em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-404\"><span class=\"mi\" id=\"MathJax-Span-405\" style=\"font-family: MathJax_Math-italic;\">k</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.068em; border-left: 0px solid; width: 0px; height: 1.004em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mi>k</mi></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-39\">k</script> of <span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><span class=\"MathJax\" id=\"MathJax-Element-40-Frame\" tabindex=\"0\" style=\"position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot;><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi class=&quot;MJX-tex-caligraphic&quot; mathvariant=&quot;script&quot;>X</mi></mrow><mo stretchy=&quot;false&quot;>(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=&quot;false&quot;>)</mo></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-406\" style=\"width: 4.17em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 3.455em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(1.253em, 1003.34em, 2.622em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-407\"><span class=\"texatom\" id=\"MathJax-Span-408\"><span class=\"mrow\" id=\"MathJax-Span-409\"><span class=\"mi\" id=\"MathJax-Span-410\" style=\"font-family: MathJax_Caligraphic;\">X<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-411\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-412\" style=\"font-family: MathJax_Math-italic;\">m</span><span class=\"mo\" id=\"MathJax-Span-413\" style=\"font-family: MathJax_Main;\">,</span><span class=\"mi\" id=\"MathJax-Span-414\" style=\"font-family: MathJax_Math-italic; padding-left: 0.182em;\">k</span><span class=\"mo\" id=\"MathJax-Span-415\" style=\"font-family: MathJax_Main;\">)</span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.354em; border-left: 0px solid; width: 0px; height: 1.361em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\"><mrow class=\"MJX-TeXAtom-ORD\"><mi class=\"MJX-tex-caligraphic\" mathvariant=\"script\">X</mi></mrow><mo stretchy=\"false\">(</mo><mi>m</mi><mo>,</mo><mi>k</mi><mo stretchy=\"false\">)</mo></math></span></span><script type=\"math/tex\" id=\"MathJax-Element-40\">\\mathcal{X}(m,k)</script> corresponds to the physical frequency</p>\n<span class=\"MathJax_Preview\" style=\"color: inherit;\"></span><div class=\"MathJax_Display\" style=\"text-align: center;\"><span class=\"MathJax\" id=\"MathJax-Element-41-Frame\" tabindex=\"0\" style=\"text-align: center; position: relative;\" data-mathml=\"<math xmlns=&quot;http://www.w3.org/1998/Math/MathML&quot; display=&quot;block&quot;><msub><mi>F</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>c</mi><mi mathvariant=&quot;normal&quot;>o</mi><mi mathvariant=&quot;normal&quot;>e</mi><mi mathvariant=&quot;normal&quot;>f</mi></mrow></msub><mo stretchy=&quot;false&quot;>(</mo><mi>k</mi><mo stretchy=&quot;false&quot;>)</mo><mo>:=</mo><mfrac><mrow><mi>k</mi><mo>&amp;#x22C5;</mo><msub><mi>F</mi><mrow class=&quot;MJX-TeXAtom-ORD&quot;><mi mathvariant=&quot;normal&quot;>s</mi></mrow></msub></mrow><mi>N</mi></mfrac></math>\" role=\"presentation\"><nobr aria-hidden=\"true\"><span class=\"math\" id=\"MathJax-Span-416\" style=\"width: 9.11em; display: inline-block;\"><span style=\"display: inline-block; position: relative; width: 7.562em; height: 0px; font-size: 120%;\"><span style=\"position: absolute; clip: rect(0.658em, 1007.56em, 3.098em, -999.997em); top: -2.199em; left: 0em;\"><span class=\"mrow\" id=\"MathJax-Span-417\"><span class=\"msubsup\" id=\"MathJax-Span-418\"><span style=\"display: inline-block; position: relative; width: 1.967em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.78em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-419\" style=\"font-family: MathJax_Math-italic;\">F<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.658em;\"><span class=\"texatom\" id=\"MathJax-Span-420\"><span class=\"mrow\" id=\"MathJax-Span-421\"><span class=\"mi\" id=\"MathJax-Span-422\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">c</span><span class=\"mi\" id=\"MathJax-Span-423\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">o</span><span class=\"mi\" id=\"MathJax-Span-424\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">e</span><span class=\"mi\" id=\"MathJax-Span-425\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">f<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span><span class=\"mo\" id=\"MathJax-Span-426\" style=\"font-family: MathJax_Main;\">(</span><span class=\"mi\" id=\"MathJax-Span-427\" style=\"font-family: MathJax_Math-italic;\">k</span><span class=\"mo\" id=\"MathJax-Span-428\" style=\"font-family: MathJax_Main;\">)</span><span class=\"mo\" id=\"MathJax-Span-429\" style=\"font-family: MathJax_Main; padding-left: 0.301em;\">:<span style=\"font-family: MathJax_Main;\">=</span></span><span class=\"mfrac\" id=\"MathJax-Span-430\" style=\"padding-left: 0.301em;\"><span style=\"display: inline-block; position: relative; width: 2.384em; height: 0px; margin-right: 0.122em; margin-left: 0.122em;\"><span style=\"position: absolute; clip: rect(3.098em, 1002.26em, 4.348em, -999.997em); top: -4.64em; left: 50%; margin-left: -1.128em;\"><span class=\"mrow\" id=\"MathJax-Span-431\"><span class=\"mi\" id=\"MathJax-Span-432\" style=\"font-family: MathJax_Math-italic;\">k</span><span class=\"mo\" id=\"MathJax-Span-433\" style=\"font-family: MathJax_Main; padding-left: 0.241em;\">⋅</span><span class=\"msubsup\" id=\"MathJax-Span-434\" style=\"padding-left: 0.241em;\"><span style=\"display: inline-block; position: relative; width: 1.015em; height: 0px;\"><span style=\"position: absolute; clip: rect(3.158em, 1000.78em, 4.17em, -999.997em); top: -3.985em; left: 0em;\"><span class=\"mi\" id=\"MathJax-Span-435\" style=\"font-family: MathJax_Math-italic;\">F<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.122em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; top: -3.807em; left: 0.658em;\"><span class=\"texatom\" id=\"MathJax-Span-436\"><span class=\"mrow\" id=\"MathJax-Span-437\"><span class=\"mi\" id=\"MathJax-Span-438\" style=\"font-size: 70.7%; font-family: MathJax_Main;\">s</span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(3.158em, 1000.9em, 4.17em, -999.997em); top: -3.271em; left: 50%; margin-left: -0.414em;\"><span class=\"mi\" id=\"MathJax-Span-439\" style=\"font-family: MathJax_Math-italic;\">N<span style=\"display: inline-block; overflow: hidden; height: 1px; width: 0.063em;\"></span></span><span style=\"display: inline-block; width: 0px; height: 3.991em;\"></span></span><span style=\"position: absolute; clip: rect(0.836em, 1002.38em, 1.253em, -999.997em); top: -1.307em; left: 0em;\"><span style=\"display: inline-block; overflow: hidden; vertical-align: 0em; border-top: 1.3px solid; width: 2.384em; height: 0px;\"></span><span style=\"display: inline-block; width: 0px; height: 1.074em;\"></span></span></span></span></span><span style=\"display: inline-block; width: 0px; height: 2.205em;\"></span></span></span><span style=\"display: inline-block; overflow: hidden; vertical-align: -0.925em; border-left: 0px solid; width: 0px; height: 2.646em;\"></span></span></nobr><span class=\"MJX_Assistive_MathML MJX_Assistive_MathML_Block\" role=\"presentation\"><math xmlns=\"http://www.w3.org/1998/Math/MathML\" display=\"block\"><msub><mi>F</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">c</mi><mi mathvariant=\"normal\">o</mi><mi mathvariant=\"normal\">e</mi><mi mathvariant=\"normal\">f</mi></mrow></msub><mo stretchy=\"false\">(</mo><mi>k</mi><mo stretchy=\"false\">)</mo><mo>:=</mo><mfrac><mrow><mi>k</mi><mo>⋅</mo><msub><mi>F</mi><mrow class=\"MJX-TeXAtom-ORD\"><mi mathvariant=\"normal\">s</mi></mrow></msub></mrow><mi>N</mi></mfrac></math></span></span></div><script type=\"math/tex; mode=display\" id=\"MathJax-Element-41\">\\begin{equation}\n         F_\\mathrm{coef}(k) := \\frac{k\\cdot F_\\mathrm{s}}{N} \n\\end{equation}</script><p>given in Hertz.</p>\n<!-- <img src=\"../data/C2/FMP_C2_F09d.png\" width=\"300px\" align=\"middle\" alt=\"C0\"> -->\n</div>\n</div>\n</div>\ngiven in Hertz.","metadata":{}},{"cell_type":"markdown","source":"\n\n","metadata":{}},{"cell_type":"code","source":"T_coef = np.arange(X.shape[1]) * H / Fs\nF_coef = np.arange(X.shape[0]) * Fs / N\n\nplt.figure(figsize=(8, 2))\n\nplt.subplot(1, 2, 1)\nplt.plot(t, x, c='k')\nplt.xlim([min(t), max(t)])\nplt.xlabel('Time (seconds)')\n\nplt.subplot(1, 2, 2)\nleft = min(T_coef)\nright = max(T_coef) + N / Fs\nlower = min(F_coef)\nupper = max(F_coef)\nplt.imshow(Y, origin='lower', aspect='auto', cmap='gray_r', \n           extent=[left, right, lower, upper])\nplt.xlabel('Time (seconds)')\nplt.ylabel('Frequency (Hz)')\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:44:40.862553Z","iopub.execute_input":"2022-10-26T21:44:40.862901Z","iopub.status.idle":"2022-10-26T21:44:41.213291Z","shell.execute_reply.started":"2022-10-26T21:44:40.862869Z","shell.execute_reply":"2022-10-26T21:44:41.21223Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"https://www.audiolabs-erlangen.de/resources/MIR/FMP/C2/C2_STFT-Basic.html\nAcknowledgment: This Chapter was created by Meinard Müller and Frank Zalkow.\nhttps://www.audiolabs-erlangen.de/fau/professor/mueller\nhttps://www.audiolabs-erlangen.de/fau/assistant/zalkow","metadata":{}},{"cell_type":"markdown","source":"#### Audio File test","metadata":{}},{"cell_type":"code","source":"import matplotlib\n#fn_wav = os.path.join('..', 'data', 'C2', 'FMP_C2_F10.wav')\n\n#fn_wav =\"../input/piano-triads-wavset/piano_triads/A_min_4_0.wav\"\n#fn_wav =\"../input/emergency-vehicle-siren-sounds/sounds/ambulance/sound_106.wav\"\nfn_wav =\"../input/sample-wav-audio-files/Beethoven_Diabelli_Variation_No._13.wav\"\n\n\nx, Fs = librosa.load(fn_wav)\n\nH = 1024\nN = 2048\nw = np.hanning(N)\nX = stft_basic(x, w, H)\nY = np.abs(X) ** 2\neps = np.finfo(float).eps\nY_db = 10 * np.log10(Y + eps)\n\nT_coef = np.arange(X.shape[1]) * H / Fs\nF_coef = np.arange(X.shape[0]) * Fs / N\n\n\nfig = plt.figure(figsize=(8, 5))\n\ngs = matplotlib.gridspec.GridSpec(3, 2, height_ratios=[1, 2, 2], width_ratios=[100, 2])\nax1, ax2, ax3, ax4, ax5, ax6 = [plt.subplot(gs[i]) for i in range(6)]\n\nt = np.arange(len(x)) / Fs\nax1.plot(t, x, c='gray')\nax1.set_xlim([min(t), max(t)])\n\nax2.set_visible(False)\n\nleft = min(T_coef)\nright = max(T_coef) + N / Fs\nlower = min(F_coef)\nupper = max(F_coef)\n\nim1 = ax3.imshow(Y, origin='lower', aspect='auto', cmap='gray_r', \n                 extent=[left, right, lower, upper])\nim1.set_clim([0, 1000])\nax3.set_ylim([0, 5000])\nax3.set_ylabel('Frequency (Hz)')\ncbar = fig.colorbar(im1, cax=ax4)\nax4.set_ylabel('Magnitude (linear)', rotation=90)\n\nim2 = ax5.imshow(Y_db, origin='lower', aspect='auto', cmap='gray_r', \n                 extent=[left, right, lower, upper])\nim2.set_clim([-30, 20])\nax5.set_ylim([0, 5000])\nax5.set_xlabel('Time (seconds)')\nax5.set_ylabel('Frequency (Hz)')\ncbar = fig.colorbar(im2, cax=ax6)\nax6.set_ylabel('Magnitude (dB)', rotation=90)\n\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:44:41.214992Z","iopub.execute_input":"2022-10-26T21:44:41.21568Z","iopub.status.idle":"2022-10-26T21:44:44.414802Z","shell.execute_reply.started":"2022-10-26T21:44:41.215642Z","shell.execute_reply":"2022-10-26T21:44:44.413344Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Custom python STFT  library __libfmp__\nThis implementation also includes padding options and realizes the centric view as used in the FMP notebooks. For details and similar options, we refer to the FMP notebook on conventions and implementations and the documentation of librosa. In the following code cell, we call the libfmp function.","metadata":{}},{"cell_type":"code","source":"pip install libfmp","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:44:44.416973Z","iopub.execute_input":"2022-10-26T21:44:44.418004Z","iopub.status.idle":"2022-10-26T21:45:26.803787Z","shell.execute_reply.started":"2022-10-26T21:44:44.417941Z","shell.execute_reply":"2022-10-26T21:45:26.802259Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sys\nsys.path.append('..')\nimport libfmp.c2\n\n#fn_wav = os.path.join('..', 'data', 'C2', 'FMP_C2_F10.wav')\n#fn_wav = os.path.join('..', 'data', 'C2', 'FMP_C2_F10.wav')\n\n#fn_wav =\"../input/piano-triads-wavset/piano_triads/A_min_4_0.wav\"\nfn_wav =\"../input/sample-wav-audio-files/Mozart_from_Piano_Sonata_K310_first_movement.wav\"\n\n\nx, Fs = librosa.load(fn_wav)\n\nH = 1024\nN = 2048\nw = np.hanning(N)\nX = libfmp.c2.stft(x, w, H)\nY = np.abs(X) ** 2\neps = np.finfo(float).eps\nY_db = 10 * np.log10(Y + eps)\n\nT_coef = np.arange(X.shape[1]) * H / Fs\nF_coef = np.arange(X.shape[0]) * Fs / N\n\n\nfig = plt.figure(figsize=(8, 3))\n\ngs = matplotlib.gridspec.GridSpec(2, 2, height_ratios=[1, 2], width_ratios=[100, 2])\n\nax1, ax2, ax3, ax4 = [plt.subplot(gs[i]) for i in range(4)]\n\nt = np.arange(len(x)) / Fs\nax1.plot(t, x, c='gray')\nax1.set_xlim([min(t), max(t)])\n\nax2.set_visible(False)\n\nleft = min(T_coef)\nright = max(T_coef) + N / Fs\nlower = min(F_coef)\nupper = max(F_coef)\n\nim = ax3.imshow(Y_db, origin='lower', aspect='auto', cmap='gray_r', \n                 extent=[left, right, lower, upper])\nim.set_clim([-30, 20])\nax3.set_ylim([0, 5000])\nax3.set_xlabel('Time (seconds)')\nax3.set_ylabel('Frequency (Hz)')\ncbar = fig.colorbar(im, cax=ax4)\nax4.set_ylabel('Magnitude (dB)', rotation=90)\n\nplt.tight_layout()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:26.805518Z","iopub.execute_input":"2022-10-26T21:45:26.805937Z","iopub.status.idle":"2022-10-26T21:45:33.787953Z","shell.execute_reply.started":"2022-10-26T21:45:26.805892Z","shell.execute_reply":"2022-10-26T21:45:33.78659Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## [G2Net] Understand the Data\nby AYUSH THAKUR \n> https://www.kaggle.com/code/ayuraj/g2net-understand-the-data","metadata":{}},{"cell_type":"code","source":"!pip -qq install git+https://github.com/PyFstat/PyFstat@python37","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:33.789826Z","iopub.execute_input":"2022-10-26T21:45:33.791032Z","iopub.status.idle":"2022-10-26T21:45:51.792543Z","shell.execute_reply.started":"2022-10-26T21:45:33.790961Z","shell.execute_reply":"2022-10-26T21:45:51.790401Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# To create graitational waves\nimport pyfstat\nfrom pyfstat.utils import get_sft_as_arrays","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:51.795488Z","iopub.execute_input":"2022-10-26T21:45:51.796129Z","iopub.status.idle":"2022-10-26T21:45:51.80518Z","shell.execute_reply.started":"2022-10-26T21:45:51.796042Z","shell.execute_reply":"2022-10-26T21:45:51.803204Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ROOT_DIR = '../input/g2net-detecting-continuous-gravitational-waves'\nos.path.isdir(ROOT_DIR)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:51.806471Z","iopub.execute_input":"2022-10-26T21:45:51.806924Z","iopub.status.idle":"2022-10-26T21:45:51.92848Z","shell.execute_reply.started":"2022-10-26T21:45:51.806887Z","shell.execute_reply":"2022-10-26T21:45:51.926982Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv(f\"{ROOT_DIR}/train_labels.csv\")\ndf.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:51.93085Z","iopub.execute_input":"2022-10-26T21:45:51.932783Z","iopub.status.idle":"2022-10-26T21:45:51.97623Z","shell.execute_reply.started":"2022-10-26T21:45:51.932722Z","shell.execute_reply":"2022-10-26T21:45:51.974548Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.target.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:51.977992Z","iopub.execute_input":"2022-10-26T21:45:51.978747Z","iopub.status.idle":"2022-10-26T21:45:52.01072Z","shell.execute_reply.started":"2022-10-26T21:45:51.978697Z","shell.execute_reply":"2022-10-26T21:45:52.009447Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Read HDF5 File","metadata":{}},{"cell_type":"code","source":"from glob import glob\nfrom pathlib import Path\nimport h5py","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:52.012264Z","iopub.execute_input":"2022-10-26T21:45:52.012666Z","iopub.status.idle":"2022-10-26T21:45:52.06607Z","shell.execute_reply.started":"2022-10-26T21:45:52.01263Z","shell.execute_reply":"2022-10-26T21:45:52.064054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_files = glob(f\"{ROOT_DIR}/train/*.hdf5\")\ntest_files = glob(f\"{ROOT_DIR}/test/*.hdf5\")\ntrain_files[:5]","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:52.068366Z","iopub.execute_input":"2022-10-26T21:45:52.069244Z","iopub.status.idle":"2022-10-26T21:45:52.151574Z","shell.execute_reply.started":"2022-10-26T21:45:52.0692Z","shell.execute_reply":"2022-10-26T21:45:52.150683Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_IDX = 0","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:52.152924Z","iopub.execute_input":"2022-10-26T21:45:52.153552Z","iopub.status.idle":"2022-10-26T21:45:52.161655Z","shell.execute_reply.started":"2022-10-26T21:45:52.153515Z","shell.execute_reply":"2022-10-26T21:45:52.16019Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"file = Path(train_files[DATA_IDX])\nwith h5py.File(file, \"r\") as f:\n    # Print all root level object names (aka keys) \n    # these can be group or dataset names \n    print(\"Top level Keys: %s\" % f.keys())\n    key = list(f.keys())[0]\n    print(\"This is the name of the file \\n\")\n    # get the object type for a_group_key: usually group or dataset\n    print(f\"Type of the data accessed using {key}: {type(f[key])}\")\n    print(\"The type can be either Group or Dataset. Group has more keys while we can get numpy array from Dataset directly.\\n\")\n    # If a_group_key is a group name, \n    # this gets the object names in the group and returns as a list\n    f = f[key]\n    data_keys = list(f)\n    print(\"These are the keys for the underlying group: \", data_keys, \"\\n\")\n    # get type of each data_keys\n    print(type(f[data_keys[0]])) # Group\n    print(type(f[data_keys[1]])) # Group\n    print(type(f[data_keys[2]])) # Dataset\n    print(\"The underlying data type for each key are Group, Group and Dataset. We thus need to go one level deep to access the data from Group. \\n\")\n    # H1\n    h1 = f[data_keys[0]]\n    h1_keys = list(h1)\n    print(\"These are the keys for the Group accessed uisng H1 key: \", h1_keys, \"\\n\")\n    # L1\n    l1 = f[data_keys[1]]\n    l1_keys = list(l1)\n    print(\"These are the keys for the Group accessed uisng L1 key: \", l1_keys, \"\\n\")\n    # frequency_Hz\n    freq_hz = f[data_keys[2]]\n    freq_hz = list(freq_hz)\n    print(\"Since the type accessed using frequency_hz key was Dataset, we can get the array directly. The length of the array is: \", len(freq_hz), \"\\n\")\n    # H1 data\n    h1_stft = h1[\"SFTs\"][()]\n    h1_timestamp = h1[\"timestamps_GPS\"][()]\n    print(\"The H1 SFTs data shape: \", h1_stft.shape)\n    print(\"The H1 timestamp data shape: \", h1_timestamp.shape, \"\\n\")\n    # H2 data\n    l1_stft = l1[\"SFTs\"][()]\n    l1_timestamp = l1[\"timestamps_GPS\"][()]\n    print(\"The L1 SFTs data shape: \", l1_stft.shape)\n    print(\"The L1 timestamp data shape: \", l1_timestamp.shape, \"\\n\")\n    print(\"We have time on the x-axis while frequency on the y-axis. \\n\")\n    \n    print(\"Label: \", df.loc[DATA_IDX].target)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:52.163619Z","iopub.execute_input":"2022-10-26T21:45:52.164145Z","iopub.status.idle":"2022-10-26T21:45:52.677344Z","shell.execute_reply.started":"2022-10-26T21:45:52.164073Z","shell.execute_reply":"2022-10-26T21:45:52.676034Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Utility to read hdf5 file","metadata":{}},{"cell_type":"code","source":"# Utility to read hdf5 file\ndef read_data(file: Path):\n    with h5py.File(file, \"r\") as f:\n        filename = file.stem\n        f = f[filename]\n        h1 = f[\"H1\"]\n        l1 = f[\"L1\"]\n        freq_hz = list(f[\"frequency_Hz\"])\n        \n        h1_stft = h1[\"SFTs\"][()]\n        h1_timestamp = h1[\"timestamps_GPS\"][()]\n        # H2 data\n        l1_stft = l1[\"SFTs\"][()]\n        l1_timestamp = l1[\"timestamps_GPS\"][()]\n        \n        return {\n            \"H1\": [h1_stft, h1_timestamp],\n            \"L1\": [l1_stft, l1_timestamp],\n            \"freq_hz\": freq_hz\n        }","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:52.686849Z","iopub.execute_input":"2022-10-26T21:45:52.688038Z","iopub.status.idle":"2022-10-26T21:45:52.700931Z","shell.execute_reply.started":"2022-10-26T21:45:52.687985Z","shell.execute_reply":"2022-10-26T21:45:52.694976Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shapes","metadata":{}},{"cell_type":"code","source":"filename=Path(train_files[1])\ndata = read_data(filename)\nh1_sft, h1_ts = data[\"H1\"]\nl1_sft, l1_ts = data[\"L1\"]\nfreq_hz = data[\"freq_hz\"]\nprint(h1_sft.shape, h1_ts.shape, len(freq_hz))","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:53.232362Z","iopub.execute_input":"2022-10-26T21:45:53.232848Z","iopub.status.idle":"2022-10-26T21:45:53.426869Z","shell.execute_reply.started":"2022-10-26T21:45:53.232795Z","shell.execute_reply":"2022-10-26T21:45:53.4252Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_shapes=pd.read_csv(\"../input/g2net-datashape/train_features.csv\")\ndf_shapes.tail()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:53.436241Z","iopub.execute_input":"2022-10-26T21:45:53.436911Z","iopub.status.idle":"2022-10-26T21:45:53.473628Z","shell.execute_reply.started":"2022-10-26T21:45:53.436874Z","shell.execute_reply":"2022-10-26T21:45:53.472677Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"df_shapes.describe()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:53.475445Z","iopub.execute_input":"2022-10-26T21:45:53.476303Z","iopub.status.idle":"2022-10-26T21:45:53.514383Z","shell.execute_reply.started":"2022-10-26T21:45:53.476259Z","shell.execute_reply":"2022-10-26T21:45:53.513163Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" #### Outliers in trainset\nThere are some data points that differs significantly from other observations. An outlier may be due to variability in the measurement or it may indicate experimental error; the latter are sometimes excluded from the data set. An outlier can cause serious problems in statistical analyses.","metadata":{}},{"cell_type":"markdown","source":" ###### LIGO Hanford Observatory observations","metadata":{}},{"cell_type":"code","source":"sns.displot(df_shapes, x=\"h1_ts\", bins=20)\nplt.figure(figsize=(4,3))","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:45:53.516139Z","iopub.execute_input":"2022-10-26T21:45:53.516501Z","iopub.status.idle":"2022-10-26T21:45:53.954056Z","shell.execute_reply.started":"2022-10-26T21:45:53.516467Z","shell.execute_reply":"2022-10-26T21:45:53.952685Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"###### LIGO Livingston","metadata":{}},{"cell_type":"code","source":"df_shapeL=pd.read_csv(\"../input/g2net-datashape/Ltrain_features.csv\")\n","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:20.257734Z","iopub.execute_input":"2022-10-26T21:46:20.258265Z","iopub.status.idle":"2022-10-26T21:46:20.26858Z","shell.execute_reply.started":"2022-10-26T21:46:20.258223Z","shell.execute_reply":"2022-10-26T21:46:20.267147Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(df_shapeL, x=\"h1_ts\", bins=20)\nplt.figure(figsize=(4,3))","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:21.458602Z","iopub.execute_input":"2022-10-26T21:46:21.459127Z","iopub.status.idle":"2022-10-26T21:46:21.825162Z","shell.execute_reply.started":"2022-10-26T21:46:21.459068Z","shell.execute_reply":"2022-10-26T21:46:21.823991Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Outliers in testset","metadata":{}},{"cell_type":"code","source":"df_shapes_test=pd.read_csv(\"../input/g2net-datashape/test_features.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:34.087963Z","iopub.execute_input":"2022-10-26T21:46:34.088492Z","iopub.status.idle":"2022-10-26T21:46:34.131792Z","shell.execute_reply.started":"2022-10-26T21:46:34.088444Z","shell.execute_reply":"2022-10-26T21:46:34.130563Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.displot(df_shapes_test, x=\"h1_ts\", bins=20)\nplt.figure(figsize=(4,3))","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:35.390313Z","iopub.execute_input":"2022-10-26T21:46:35.391455Z","iopub.status.idle":"2022-10-26T21:46:35.776084Z","shell.execute_reply.started":"2022-10-26T21:46:35.391408Z","shell.execute_reply":"2022-10-26T21:46:35.775021Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(df_shapes_test[['h1_ts']], hist=False, rug=True)\nsns.distplot(df_shapes[['h1_ts']], hist=False, rug=True)\nsns.distplot(df_shapesL[['h1_ts']], hist=False, rug=True)\n\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:35.777961Z","iopub.execute_input":"2022-10-26T21:46:35.77856Z","iopub.status.idle":"2022-10-26T21:46:36.18502Z","shell.execute_reply.started":"2022-10-26T21:46:35.77852Z","shell.execute_reply":"2022-10-26T21:46:36.184142Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.distplot(df_shapes_test[['h1_ts']], hist=False, rug=True).set_xlim(4200,4900)\nsns.distplot(df_shapes[['h1_ts']], hist=False, rug=True).set_xlim(4200,4900)\nsns.distplot(df_shapesL[['h1_ts']], hist=False, rug=True).set_xlim(4200,4900)\nplt.show()\n","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:36.186644Z","iopub.execute_input":"2022-10-26T21:46:36.18721Z","iopub.status.idle":"2022-10-26T21:46:36.747423Z","shell.execute_reply.started":"2022-10-26T21:46:36.187174Z","shell.execute_reply":"2022-10-26T21:46:36.746144Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_shapes_test.to_csv(\"test_features.csv\")\n#df_shapes.to_csv(\"train_features.csv\")","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:36.749632Z","iopub.execute_input":"2022-10-26T21:46:36.750288Z","iopub.status.idle":"2022-10-26T21:46:36.790578Z","shell.execute_reply.started":"2022-10-26T21:46:36.750242Z","shell.execute_reply":"2022-10-26T21:46:36.788903Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"del df_shapes_test\ndel df_shapes","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:37.3732Z","iopub.execute_input":"2022-10-26T21:46:37.374276Z","iopub.status.idle":"2022-10-26T21:46:37.380537Z","shell.execute_reply.started":"2022-10-26T21:46:37.374221Z","shell.execute_reply":"2022-10-26T21:46:37.379184Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### H1: LIGO Hanford","metadata":{}},{"cell_type":"code","source":"from datetime import datetime\nprint(datetime.utcfromtimestamp(h1_ts[0]).strftime('%Y-%m-%d %H:%M:%S'))","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:38.040893Z","iopub.execute_input":"2022-10-26T21:46:38.042512Z","iopub.status.idle":"2022-10-26T21:46:38.050761Z","shell.execute_reply.started":"2022-10-26T21:46:38.042454Z","shell.execute_reply":"2022-10-26T21:46:38.049105Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### STFT LIGO Hanford\nShort time fourier transform computes the fourier transform of the signal at shorter duration of signals given by a window size. The DFT (discrete fourier transform) or FFT (fast fourier transform) are computed by taking the entire duration of the signal into consideration.\n\nNote that the plots generated below are not considering the gaps in the timestamp and considers the data as a single continuous SFT","metadata":{}},{"cell_type":"code","source":"fig, ax = plt.subplots(2, 2, figsize=(16, 10))\nfig.suptitle(f\"Filename Id: {file.stem}\")\n\nfor d_ind, detector in enumerate([\"H1\", \"L1\"]):\n    ax[d_ind][0].set(xlabel=\"Timestamps [GPS]\",\n                     ylabel=\"Frequency [Hz]\",\n                     title=f\"{detector} - Real part\")\n    ax[d_ind][1].set(xlabel=\"Timestamps [GPS]\",\n                     ylabel=\"Frequency [Hz]\",\n                     title=f\"{detector} - Imaginary part\")\n\n    c0 = ax[d_ind][0].pcolormesh(data[detector][1], data[\"freq_hz\"], \n                                 data[detector][0].real)\n    c1 = ax[d_ind][1].pcolormesh(data[detector][1], data[\"freq_hz\"], \n                                 data[detector][0].imag)\n\n    fig.colorbar(c0, ax=ax[d_ind][0])\n    fig.colorbar(c1, ax=ax[d_ind][1])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:38.949694Z","iopub.execute_input":"2022-10-26T21:46:38.950176Z","iopub.status.idle":"2022-10-26T21:46:43.588651Z","shell.execute_reply.started":"2022-10-26T21:46:38.950136Z","shell.execute_reply":"2022-10-26T21:46:43.587475Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### Understanding By Generating","metadata":{}},{"cell_type":"markdown","source":"The data can better be understood if we generate the data and see how different parameters contribute to the SFTs. This section is based on the awesome tutorials provided by the host of this competition. You can find the tutorials here. The following is a distilled information in an attemp to better understand the data.","metadata":{}},{"cell_type":"markdown","source":"Understanding By Generating\nThe data can better be understood if we generate the data and see how different parameters contribute to the SFTs. This section is based on the awesome tutorials provided by the host of this competition. You can find the tutorials here. The following is a distilled information in an attemp to better understand the data.\n\nTLDR;\nThe SFTs generated with h0 parameter equal to 0 have target/label as 0. The SFTs generated with h0 parameter equal to 1, thus having SNR (signal to noise ratio) > 0 have it's target/label as 1. The competition hosts were kind enough to clarify this here.\n\nThe main piece of code to generate the data is writer = pyfstat.Writer(**writer_kwargs, **signal_parameters). If you don't pass **signal_parameter you will get data corresponding to 0 and so on. You can check the Writer class here.","metadata":{}},{"cell_type":"markdown","source":"#### CW wave properties\nThe CW wave has the following properties:\n\n__Quasi-monochromatic__: \"Wave in which most of the energy is confined to a single wavelength or a very narrow waveband\". However, gravitational continuous waves are not completely monochromatic. (source)\n**Long-standing**: The standing waves are stationary (not a travelling wave). The disturbance does not travel in any direction. Standing waves have points of zero amplitude called nodes and points of maximum amplitude called the antinodes.\n**Produced by non-axisymmetric rapidly-spinning neutron stars**\n**Produce narrow-banded signals** - that's why the y axis (Freq in Hz) in the spectrogram lies in **a narrow band of 1-2 Hz**.\nThe waves are **doppler-modulated** due to the motion of the detector in the Solar system.\nIt's a common practice to use short time fourier transform to analyze these waves. These are Fourier transforms of short data segments (**typically around 30 minutes or 1800 seconds**).","metadata":{}},{"cell_type":"markdown","source":"#### Generate Gausian Noise","metadata":{}},{"cell_type":"code","source":"# Setup Writer\nwriter_kwargs = {\n    \"label\": \"single_detector_gaussian_noise\",\n    \"outdir\": \"PyFstat_example_data\",\n    \"tstart\": 1238166018,  # Starting time of the observation [GPS time]\n    \"duration\": 5 * 86400,  # Duration [seconds]\n    \"detectors\": \"H1\",  # Detector to simulate, in this case LIGO Hanford\n    \"F0\": 100.0,  # Central frequency of the band to be generated [Hz]\n    \"Band\": 1.0,  # Frequency band-width around F0 [Hz]\n    \"sqrtSX\": 1e-23,  # Single-sided Amplitude Spectral Density of the noise\n    \"Tsft\": 1800,  # Fourier transform time duration\n    \"SFTWindowType\": \"tukey\",  # Window function to compute short Fourier transforms\n    \"SFTWindowBeta\": 0.01,  # Parameter associated to the window function\n}\nwriter = pyfstat.Writer(**writer_kwargs)\n\n# Create SFTs\nwriter.make_data()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:43.590638Z","iopub.execute_input":"2022-10-26T21:46:43.59108Z","iopub.status.idle":"2022-10-26T21:46:45.221597Z","shell.execute_reply.started":"2022-10-26T21:46:43.591047Z","shell.execute_reply":"2022-10-26T21:46:45.219857Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Note:** \"*As a side note, the path where the SFTs are created is stored in the sftfilepath attribute of Writer **(mind that it gets overwritten every time make_data is called!)**.\" (source)*","metadata":{}},{"cell_type":"code","source":"frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:45.223696Z","iopub.execute_input":"2022-10-26T21:46:45.224179Z","iopub.status.idle":"2022-10-26T21:46:45.249692Z","shell.execute_reply.started":"2022-10-26T21:46:45.224125Z","shell.execute_reply":"2022-10-26T21:46:45.248366Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"frequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:45.252981Z","iopub.execute_input":"2022-10-26T21:46:45.254394Z","iopub.status.idle":"2022-10-26T21:46:45.274983Z","shell.execute_reply.started":"2022-10-26T21:46:45.254348Z","shell.execute_reply":"2022-10-26T21:46:45.273444Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The shape of H1 SFT is: (1800, 240) while that of it's time stamp is: (240,)\nThe shape of frequency Hz is: (1800,)\nWhy the shape of time stamp is (240,)?\n\nThere are three time related parameters:\n> * \"tstart\": 1238166018,  # Starting time of the observation [GPS time]\n> * \"duration\": 5 * 86400,  # Duration [seconds]\n> * \"Tsft\": 1800,  # Fourier transform time duration","metadata":{}},{"cell_type":"code","source":"print(f\"Total duration is : {5*86400}; time segments for SFT computation: {1800}; total timestamps: {(5*86400)/1800}\")","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:45.276934Z","iopub.execute_input":"2022-10-26T21:46:45.277374Z","iopub.status.idle":"2022-10-26T21:46:45.286241Z","shell.execute_reply.started":"2022-10-26T21:46:45.277334Z","shell.execute_reply":"2022-10-26T21:46:45.284813Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\"\"\"\nUtils\n=====\n\nUtility functions to simplify tutorials.\n\"\"\"\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom matplotlib import colors\nfrom scipy import stats\n\nplt.rcParams[\"font.family\"] = \"serif\"\nplt.rcParams[\"font.size\"] = 20\n\n\ndef plot_real_imag_spectrograms(timestamps, frequency, fourier_data):\n    \"uses simple plt.pcolormesh\"\n    fig, axs = plt.subplots(1, 2, figsize=(16, 10))\n\n    for ax in axs:\n        ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n\n    time_in_days = (timestamps - timestamps[0]) / 1800\n\n    axs[0].set_title(\"SFT Real part\")\n    c = axs[0].pcolormesh(\n        time_in_days,\n        frequency,\n        fourier_data.real,\n        norm=colors.CenteredNorm(),\n    )\n    fig.colorbar(c, ax=axs[0], orientation=\"horizontal\", label=\"Fourier Amplitude\")\n\n    axs[1].set_title(\"SFT Imaginary part\")\n    c = axs[1].pcolormesh(\n        time_in_days,\n        frequency,\n        fourier_data.imag,\n        norm=colors.CenteredNorm(),\n    )\n\n    fig.colorbar(c, ax=axs[1], orientation=\"horizontal\", label=\"Fourier Amplitude\")\n\n    return fig, axs\n\n\ndef plot_real_imag_spectrograms_with_gaps(timestamps, frequency, fourier_data, Tsft):\n\n    # Fill up gaps with Nans\n    gap_length = timestamps[1:] - (timestamps[:-1] + Tsft)\n\n    gap_data = [fourier_data[:, 0]]\n    gap_timestamps = [timestamps[0]]\n\n    for ind, gap in enumerate(gap_length):\n        if gap > 0:\n            gap_data.append(np.full_like(fourier_data[:, ind], np.nan + 1j * np.nan))\n            gap_timestamps.append(timestamps[ind] + Tsft)\n\n        gap_data.append(fourier_data[:, ind + 1])\n        gap_timestamps.append(timestamps[ind + 1])\n\n    return plot_real_imag_spectrograms(\n        np.hstack(gap_timestamps), frequency, np.vstack(gap_data).T\n    )\n\n\ndef plot_real_imag_histogram(fourier_data, theoretical_stdev=None):\n\n    fig, ax = plt.subplots(figsize=(16, 10))\n    ax.set(xlabel=\"SFT value\", ylabel=\"PDF\", yscale=\"log\")\n\n    ax.hist(\n        fourier_data.real.ravel(),\n        density=True,\n        bins=\"auto\",\n        histtype=\"step\",\n        lw=2,\n        label=\"Real part\",\n    )\n    ax.hist(\n        fourier_data.imag.ravel(),\n        density=True,\n        bins=\"auto\",\n        histtype=\"step\",\n        lw=2,\n        label=\"Imaginary part\",\n    )\n\n    if theoretical_stdev is not None:\n        x = np.linspace(-4 * theoretical_stdev, 4 * theoretical_stdev, 1000)\n        y = stats.norm(scale=theoretical_stdev).pdf(x)\n        ax.plot(x, y, color=\"black\", ls=\"--\", label=\"Gaussian distribution\")\n\n    ax.legend()\n\n    return fig, ax\n\n\ndef plot_amplitude_phase_spectrograms(timestamps, frequency, fourier_data):\n    fig, axs = plt.subplots(1, 2, figsize=(16, 10))\n\n    for ax in axs:\n        ax.set(xlabel=\"SFT index\", ylabel=\"Frequency [Hz]\")\n\n    time_in_days = (timestamps - timestamps[0]) / 1800\n\n    axs[0].set_title(\"SFT absolute value\")\n    c = axs[0].pcolorfast(\n        time_in_days, frequency, np.absolute(fourier_data), norm=colors.Normalize()\n    )\n    fig.colorbar(c, ax=axs[0], orientation=\"horizontal\", label=\"Value\")\n\n    axs[1].set_title(\"SFT phase\")\n    c = axs[1].pcolorfast(\n        time_in_days, frequency, np.angle(fourier_data), norm=colors.CenteredNorm()\n    )\n\n    fig.colorbar(c, ax=axs[1], orientation=\"horizontal\", label=\"Value\")\n\n    return fig, axs","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:45.288766Z","iopub.execute_input":"2022-10-26T21:46:45.28937Z","iopub.status.idle":"2022-10-26T21:46:45.319684Z","shell.execute_reply.started":"2022-10-26T21:46:45.289315Z","shell.execute_reply":"2022-10-26T21:46:45.31823Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plot_real_imag_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n);","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:45.321407Z","iopub.execute_input":"2022-10-26T21:46:45.322065Z","iopub.status.idle":"2022-10-26T21:46:46.931649Z","shell.execute_reply.started":"2022-10-26T21:46:45.322028Z","shell.execute_reply":"2022-10-26T21:46:46.930201Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**The SNR for such a signal is 0 since there are no signal. :P :P :)**\n\nLet's inspect the apmplitude and angle of the generate SFT.\nSince it's a gaussian noise, the power (amplitude) and angle in the SFT is random.","metadata":{}},{"cell_type":"code","source":"fig, ax = plot_amplitude_phase_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n);","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:46.933256Z","iopub.execute_input":"2022-10-26T21:46:46.934113Z","iopub.status.idle":"2022-10-26T21:46:47.705929Z","shell.execute_reply.started":"2022-10-26T21:46:46.934049Z","shell.execute_reply":"2022-10-26T21:46:47.704947Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#https://kevinsprojects.wordpress.com/2014/12/13/short-time-fourier-transform-using-python-and-numpy/","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:47.707168Z","iopub.execute_input":"2022-10-26T21:46:47.70823Z","iopub.status.idle":"2022-10-26T21:46:47.712466Z","shell.execute_reply.started":"2022-10-26T21:46:47.708189Z","shell.execute_reply":"2022-10-26T21:46:47.711429Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Generate CW Signal\n​\nThe CW waves are primarily dependent on: `amplitude` and `Doppler` parameters.\n​\n- the `amplitide` parameter depends on nominal CW amplitude $h0$, the cosine of the source inclination angle with respect to the line of sight $cos(ι)$ (cosi), the polarization angle $\\psi{}$ (psi) and the initial phase of the wave $\\phi{}$ (phi). Depending on the emission mechanism, $h0$ can be further described using further physical quantities such as the source's frequency, ellipticity, or distance to the detector.\n​\n- the `doppler` parameter describe the relationship between the source of emmission (and it's motion) and the detectors. The parameter depends on gravitational wave frequency $f0$, spindown $f1$and sky position $\\hat{n}$, which we will parametrize using the right ascension $\\alpha{}$ and declination $\\delta{}$ angles.","metadata":{}},{"cell_type":"markdown","source":"**In this case the signal is really clear and thus SNR should be high.**","metadata":{}},{"cell_type":"code","source":"# The same writer params are required to generate gaussian noise.\nwriter_kwargs = {\n    \"label\": \"single_detector_gaussian_noise\",\n    \"outdir\": \"PyFstat_example_data\",\n    \"tstart\": 1238166018,\n    \"duration\": 365 * 86400,\n    \"detectors\": \"H1\",\n    \"sqrtSX\": 1e-23,\n    \"Tsft\": 1800,\n    \"SFTWindowType\": \"tukey\",\n    \"SFTWindowBeta\": 0.01,\n}\n\n# These parameters determine the CW signal that we have to detect.\nsignal_parameters = {\n    \"F0\": 100.0,\n    \"F1\": -1e-9,\n    \"Alpha\": 0.0,\n    \"Delta\": 0.0,\n    \"h0\": 1e-22, # this parameter in particular determines if a signal exist in the generated SFT.\n    \"cosi\": 1,\n    \"psi\": 0.0,\n    \"phi\": 0.0,\n    \"tref\": writer_kwargs[\"tstart\"],\n}\n\nwriter = pyfstat.Writer(**writer_kwargs, **signal_parameters)\nwriter.make_data()\nfrequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\nplot_real_imag_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n);","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:46:47.715831Z","iopub.execute_input":"2022-10-26T21:46:47.716543Z","iopub.status.idle":"2022-10-26T21:47:01.480479Z","shell.execute_reply.started":"2022-10-26T21:46:47.716504Z","shell.execute_reply":"2022-10-26T21:47:01.479186Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The power and the angle component of the generate SFT is prominent.","metadata":{}},{"cell_type":"markdown","source":"Change the variables","metadata":{}},{"cell_type":"code","source":"# The same writer params are required to generate gaussian noise.\nwriter_kwargs = {\n    \"label\": \"single_detector_gaussian_noise\",\n    \"outdir\": \"PyFstat_example_data\",\n    \"tstart\": 1238166018,\n    \"duration\": 365 * 86400,\n    \"detectors\": \"H1\",\n    \"sqrtSX\": 1e-23,\n    \"Tsft\": 1800,\n    \"SFTWindowType\": \"tukey\",\n    \"SFTWindowBeta\": 0.01,\n}\n\n# These parameters determine the CW signal that we have to detect.\nsignal_parameters = {\n    \"F0\": 500.0,\n    \"F1\": -1e-27,\n    \"Alpha\": 3.,\n    \"Delta\": 0.5,\n    \"h0\": 1e-22, # this parameter in particular determines if a signal exist in the generated SFT. < \"sqrtSX\"\n    \"cosi\": 0.1,\n    \"psi\": 0.0,\n    \"phi\": 2.,\n    \"tref\": writer_kwargs[\"tstart\"],\n}\n\nwriter = pyfstat.Writer(**writer_kwargs, **signal_parameters)\nwriter.make_data()\nfrequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\nplot_real_imag_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n);","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:01.482679Z","iopub.execute_input":"2022-10-26T21:47:01.483663Z","iopub.status.idle":"2022-10-26T21:47:18.314813Z","shell.execute_reply.started":"2022-10-26T21:47:01.483606Z","shell.execute_reply":"2022-10-26T21:47:18.3138Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# SNR can be compute from a set of SFTs for a specific set\n# of parameters as follows:\nsnr = pyfstat.SignalToNoiseRatio.from_sfts(\n    F0=writer.F0, sftfilepath=writer.sftfilepath\n)\nsquared_snr = snr.compute_snr2(\n    Alpha=writer.Alpha, \n    Delta=writer.Delta,\n    psi=writer.psi,\n    phi=writer.phi, \n    h0=writer.h0,\n    cosi=writer.cosi\n)\nsqrt_snr = np.sqrt(squared_snr)\nprint(f\"Signal - SNR: {sqrt_snr}\")","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:18.316498Z","iopub.execute_input":"2022-10-26T21:47:18.317437Z","iopub.status.idle":"2022-10-26T21:47:20.505267Z","shell.execute_reply.started":"2022-10-26T21:47:18.31739Z","shell.execute_reply":"2022-10-26T21:47:20.503877Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> The data of interest (real data) should have such high SNRs (there would be no point of this competition, if signal is easily detected).","metadata":{}},{"cell_type":"markdown","source":"### **SNR range of CW signal**\nLet's talk about the possible SNR range of CW signals. As per the tutorial shared by competition hosts, \"The presence of visible CW features in the spectrogram can be quantified using the so-called sensitivity depth, which is defined as the ratio between the noise and CW amplitude $D = \\sqrt{Sn}/h0$. Current searches for CW signals from unknown sources are able to detect a sensitivity depth ranging between 10 $Hz^{-0.5}$ and 50 $Hz^{-0.5}$. Visual features, however, tend to disappear around a depth of 20 $Hz^{-0.5}$.\"\n​\nLooking at the formula, $\\sqrt{Sn}$ is \"sqrtSX\" which in our case is `1e-23`. And we want to look at visual features where the sensitivity depth is 20 $Hz^{-0.5}$. Thus we will calculate $h0$.","metadata":{}},{"cell_type":"code","source":"# CW signal at a depth of 20\nsignal_parameters[\"h0\"] = writer_kwargs[\"sqrtSX\"] / 20.0\n\nwriter = pyfstat.Writer(**writer_kwargs, **signal_parameters)\n\n# Create SFTs\nwriter.make_data()\n\nfrequency, timestamps, fourier_data = get_sft_as_arrays(writer.sftfilepath)\n\nplot_real_imag_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n)\n\nplot_amplitude_phase_spectrograms(\n    timestamps[\"H1\"], frequency, fourier_data[\"H1\"]\n);","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:20.506975Z","iopub.execute_input":"2022-10-26T21:47:20.507534Z","iopub.status.idle":"2022-10-26T21:47:39.138714Z","shell.execute_reply.started":"2022-10-26T21:47:20.507482Z","shell.execute_reply":"2022-10-26T21:47:39.137156Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> We really can't see any visual feature in the spectrogram.","metadata":{}},{"cell_type":"code","source":"# SNR can be compute from a set of SFTs for a specific set\n# of parameters as follows:\nsnr = pyfstat.SignalToNoiseRatio.from_sfts(\n    F0=writer.F0, sftfilepath=writer.sftfilepath\n)\nsquared_snr = snr.compute_snr2(\n    Alpha=writer.Alpha,\n    Delta=writer.Delta,\n    psi=writer.psi,\n    phi=writer.phi,\n    h0=writer.h0,\n    cosi=writer.cosi\n)\nsqrt_snr = np.sqrt(squared_snr)\nprint(f\"Signal - SNR: {sqrt_snr}\")","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:39.140709Z","iopub.execute_input":"2022-10-26T21:47:39.14173Z","iopub.status.idle":"2022-10-26T21:47:41.342607Z","shell.execute_reply.started":"2022-10-26T21:47:39.14168Z","shell.execute_reply":"2022-10-26T21:47:41.341208Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**But the SNR > 0 indicates that our target signal (CW waves) is present and we need better system to predict them.**","metadata":{}},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"markdown","source":"## Imports 🗂","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"%%capture\n!pip install nexusformat","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:41.348595Z","iopub.execute_input":"2022-10-26T21:47:41.349206Z","iopub.status.idle":"2022-10-26T21:47:54.88574Z","shell.execute_reply.started":"2022-10-26T21:47:41.349149Z","shell.execute_reply":"2022-10-26T21:47:54.883842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import pandas as pd\nfrom pathlib import Path\nimport os\nimport random\nimport numpy as np\nfrom pprint import pprint\nfrom tqdm.notebook import tqdm\n\nimport seaborn as sns\nsns.set_theme()\n\nfrom scipy import signal\nfrom scipy.fft import fftshift\nimport matplotlib.pyplot as plt\n\nimport h5py\nimport nexusformat.nexus as nx\n\nimport warnings\nwarnings.filterwarnings('ignore')\n\nfrom IPython.display import HTML, display\ndisplay(HTML('<style>.font-family:verdana; word-spacing:1.5px;</style>'))","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:54.88797Z","iopub.execute_input":"2022-10-26T21:47:54.888447Z","iopub.status.idle":"2022-10-26T21:47:54.941813Z","shell.execute_reply.started":"2022-10-26T21:47:54.888397Z","shell.execute_reply":"2022-10-26T21:47:54.940585Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"DATA_PATH = Path('../input/g2net-detecting-continuous-gravitational-waves')\nTRAIN_PATH = DATA_PATH/'train'\nTEST_PATH = DATA_PATH/'test'\ntrain_example_with_signal_path = TRAIN_PATH/'cc561e4fc.hdf5'\ntrain_example_without_signal_path = TRAIN_PATH/'fb6db0d08.hdf5'","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:54.943361Z","iopub.execute_input":"2022-10-26T21:47:54.943759Z","iopub.status.idle":"2022-10-26T21:47:54.950838Z","shell.execute_reply.started":"2022-10-26T21:47:54.943716Z","shell.execute_reply":"2022-10-26T21:47:54.949396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# HDF5 🤔","metadata":{}},{"cell_type":"markdown","source":"<span style=\"font-family:verdana; word-spacing:1.5px;\"> The data is stored in HDF5 files. Hierarchical Data Format version 5 (HDF5), is an open source file format that supports large, complex, heterogeneous data. HDF5 uses a \"file directory\" like structure that allows you to organize data.\n\n<span style=\"font-family:verdana; word-spacing:1.5px;\"> HDF5 simplifies the file structure to include only two major types of object:\n- <span style=\"font-family:verdana; word-spacing:1.5px;\"> Datasets, which are typed multidimensional arrays\n- <span style=\"font-family:verdana; word-spacing:1.5px;\"> Groups, which are container structures that can hold datasets and other groups\n\n<span style=\"font-family:verdana; word-spacing:1.5px;\"> We can view the structure of our data with the nexusformat package.\n\n<span style=\"font-family:verdana; word-spacing:1.5px;\"> The `h5py` package is a thin, pythonic wrapper around HDF5 we can use it to quickly load our data.","metadata":{}},{"cell_type":"markdown","source":"<div align = 'center'><img src= \"https://cdn-images-1.medium.com/max/4984/1*BXG3eNq7xZGskaXmn53kvQ.png\" alt =\"Space\" style='width: 800px;height 400px'>","metadata":{}},{"cell_type":"markdown","source":"##  <span style=\"font-family:verdana; word-spacing:1.5px;\">  We can see the structure of the training and test data below:","metadata":{}},{"cell_type":"markdown","source":"- <span style=\"font-family:verdana; word-spacing:1.5px;\">  `ID` is the top group of the HDF5 file and links the datapoint to it's label in the `train_labels` csv  (group)\n\n- <span style=\"font-family:verdana; word-spacing:1.5px;\">  `frequency_Hz` contains the range frequencies measured by the dectors (dataset)\n\n\n- <span style=\"font-family:verdana; word-spacing:1.5px;\">  `H1` contains the data for the LIGO Hanford decector (group) \n    \n    - <span style=\"font-family:verdana; word-spacing:1.5px;\">  `SFTs` is the Short-time Fourier Transforms amplitudes for each timestamp at each frequency (dataset)\n    - <span style=\"font-family:verdana; word-spacing:1.5px;\">  `timestamps` contains the timestamps for the measurement (dataset)\n\n    \n- <span style=\"font-family:verdana; word-spacing:1.5px;\">  `L1` contains the data for the LIGO Livingston decector (group) \n    \n    - <span style=\"font-family:verdana; word-spacing:1.5px;\">  `SFTs` is the Short-time Fourier Transforms amplitudes for each timestamp at each frequency (dataset)\n    - <span style=\"font-family:verdana; word-spacing:1.5px;\">  `timestamps` contains the timestamps for the measurement (dataset)    \n    \n<span style=\"font-family:verdana; word-spacing:1.5px;\"> This structure can be visualised below 👇 ","metadata":{}},{"cell_type":"markdown","source":"![](https://i.imgur.com/M6xfOri.png)","metadata":{}},{"cell_type":"markdown","source":"##  <span style=\"font-family:verdana; word-spacing:1.5px;\"> Let's look at an example","metadata":{}},{"cell_type":"code","source":"with h5py.File(train_example_with_signal_path, \"r\") as f:\n    \n    # get first object name/key; this is the data point ID\n    ID_key = list(f.keys())[0]\n    print(f\"ID: {ID_key} \\n\")\n    \n    # Retrieve the Livingston decector data\n    print(f\"- {list(f[ID_key].keys())[1]}\")\n    L1_SFTs = f[ID_key]['L1']['SFTs']\n    print(f\"-- SFTs amplitudes: {L1_SFTs.shape}\")\n    L1_ts = f[ID_key]['L1']['timestamps_GPS']\n    print(f\"-- timestamps: {L1_ts.shape} \\n\")\n    \n    # Retrieve the Hanford decector data\n    print(f\"- {list(f[ID_key].keys())[0]}\")\n    H1_SFTs = f[ID_key]['H1']['SFTs']\n    print(f\"-- SFTs amplitudes: {H1_SFTs.shape}\")\n    H1_ts = f[ID_key]['H1']['timestamps_GPS']\n    print(f\"-- timestamps: {H1_ts.shape} \\n\")\n\n    # Retrieve the frequency data\n    freq_data = np.array(f[ID_key]['frequency_Hz'])\n    print(f\"- Frequency data: {freq_data.shape} \\n\")","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:54.952638Z","iopub.execute_input":"2022-10-26T21:47:54.953808Z","iopub.status.idle":"2022-10-26T21:47:54.990272Z","shell.execute_reply.started":"2022-10-26T21:47:54.953754Z","shell.execute_reply":"2022-10-26T21:47:54.989359Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Load in the meta data ⏳","metadata":{}},{"cell_type":"code","source":"train_labels = pd.read_csv(DATA_PATH/'train_labels.csv')\ntrain_labels.head()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:54.99138Z","iopub.execute_input":"2022-10-26T21:47:54.991722Z","iopub.status.idle":"2022-10-26T21:47:55.012873Z","shell.execute_reply.started":"2022-10-26T21:47:54.99169Z","shell.execute_reply":"2022-10-26T21:47:55.011543Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### Plot Train Test split ###\n\nplt.figure(figsize=(6,4))\nsns.barplot(['Train', 'Test'], [len(os.listdir(TRAIN_PATH)), len(os.listdir(TEST_PATH))]);\nplt.title(f'Train test split', fontsize=12)\nplt.ylabel('Count', fontsize=12)\nplt.xlabel('Category', fontsize=12)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:55.01449Z","iopub.execute_input":"2022-10-26T21:47:55.015252Z","iopub.status.idle":"2022-10-26T21:47:55.237571Z","shell.execute_reply.started":"2022-10-26T21:47:55.015209Z","shell.execute_reply":"2022-10-26T21:47:55.236607Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"<span style=\"font-family:verdana; word-spacing:1.5px;\">  This is a very unusual train test split for a kaggle competetion. Normally we would see at an 80:20 split, but here it is 1:16. The competition hosts are encouraging us to generate more data ourselves ([see discussion](https://www.kaggle.com/competitions/g2net-detecting-continuous-gravitational-waves/discussion/347052))","metadata":{}},{"cell_type":"markdown","source":"## <span style=\"font-family:verdana; word-spacing:1.5px;\">  Labels\n<span style=\"font-family:verdana; word-spacing:1.5px;\">  Each data sample contains either **real or simulated noise** and possibly a **simulated continuous gravitational-wave signal** (CW). The task is to identify when a signal is present in the data (target=1)\n\n<span style=\"font-family:verdana; word-spacing:1.5px;\">  The `target_labels.csv` is a file containing the target labels; 1 if the data contains the presence of a gravitational wave, 0 otherwise. (Please note the presence of a small number of files labeled -1. Physicists are currently unable to determine the status of these files.)","metadata":{}},{"cell_type":"code","source":"labels_df = pd.read_csv(DATA_PATH/'train_labels.csv')\nlabels_df.head(5)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:55.239261Z","iopub.execute_input":"2022-10-26T21:47:55.239881Z","iopub.status.idle":"2022-10-26T21:47:55.257Z","shell.execute_reply.started":"2022-10-26T21:47:55.239843Z","shell.execute_reply":"2022-10-26T21:47:55.255553Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"### Plot the distribution of labels ###\nlabel_count  = labels_df['target'].value_counts()\nplt.figure(figsize=(10,8))\nsns.barplot(label_count.index, label_count.values, alpha=0.7)\nplt.title(f'Frequency of labels in training data', fontsize=12)\nplt.ylabel('Count', fontsize=12)\nplt.xlabel('label', fontsize=12)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:55.259713Z","iopub.execute_input":"2022-10-26T21:47:55.261429Z","iopub.status.idle":"2022-10-26T21:47:55.471114Z","shell.execute_reply.started":"2022-10-26T21:47:55.261357Z","shell.execute_reply":"2022-10-26T21:47:55.469695Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"### Sample submission:\n`sample_submission.csv` - a sample submission file in the correct format; your task is, for each file in the test/ folder, to predict the probability between [0, 1] of it it containing a continuous gravitational wave signal.","metadata":{"execution":{"iopub.status.busy":"2022-10-04T17:02:30.474744Z","iopub.execute_input":"2022-10-04T17:02:30.475143Z","iopub.status.idle":"2022-10-04T17:02:30.482773Z","shell.execute_reply.started":"2022-10-04T17:02:30.475112Z","shell.execute_reply":"2022-10-04T17:02:30.481314Z"}}},{"cell_type":"code","source":"pd.read_csv(DATA_PATH/'sample_submission.csv').head()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:55.473081Z","iopub.execute_input":"2022-10-26T21:47:55.473637Z","iopub.status.idle":"2022-10-26T21:47:55.502864Z","shell.execute_reply.started":"2022-10-26T21:47:55.473587Z","shell.execute_reply":"2022-10-26T21:47:55.501351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Plotting Spectograms 📊","metadata":{}},{"cell_type":"code","source":"### Helper functions to extract data and plot spectograms ###\n\ndef extract_data_from_hdf5(path, labels):\n    '''\n    Extracts data from hdf5 file and puts it into a dict. It also adds the label\n    '''\n    \n    data = {}\n    \n    with h5py.File(path, \"r\") as f:\n\n        ID_key = list(f.keys())[0]\n\n        # Retrieve the frequency data\n        data['freq'] = np.array(f[ID_key]['frequency_Hz'])\n\n        # Retrieve the Livingston decector data\n        data['L1_SFTs_amplitudes'] = np.array(f[ID_key]['L1']['SFTs'])\n        data['L1_ts'] = np.array(f[ID_key]['L1']['timestamps_GPS'])\n\n        # Retrieve the Livingston decector data\n        data['H1_SFTs_amplitudes'] = np.array(f[ID_key]['H1']['SFTs'])\n        data['H1_ts'] = np.array(f[ID_key]['H1']['timestamps_GPS'])\n        \n        # Get label from training labels if in training set\n        data['label'] = labels.loc[labels.id==ID_key].target.item()\n        \n    return data\n    \ndef plot_spectograms(data):\n    '''\n    Shows the real and imaginary amplitudes of the SFTs as spectograms for both detectors\n    '''\n    \n    fig, ax = plt.subplots(2, 2, figsize=(16, 10))\n    fig.suptitle(f\"Label {data['label']}\")\n\n    for ind, detector in enumerate(['L1', 'H1']):\n        ax[ind][0].set(xlabel=\"Timestamps [GPS]\",\n                         ylabel=\"Frequency [Hz]\",\n                         title=f\"{detector} - Real part\")\n        ax[ind][1].set(xlabel=\"Timestamps [GPS]\",\n                         ylabel=\"Frequency [Hz]\",\n                         title=f\"{detector} - Imaginary part\")\n        \n        \n        c0 = ax[ind][0].pcolormesh(data[f\"{detector}_ts\"], data['freq'],\n                                     data[f\"{detector}_SFTs_amplitudes\"].real)\n        c1 = ax[ind][1].pcolormesh(data[f\"{detector}_ts\"], data['freq'],\n                                     data[f\"{detector}_SFTs_amplitudes\"].imag)\n    \n        fig.colorbar(c0, ax=ax[ind][0])\n        fig.colorbar(c1, ax=ax[ind][1])\n        \n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:55.505115Z","iopub.execute_input":"2022-10-26T21:47:55.50617Z","iopub.status.idle":"2022-10-26T21:47:55.52446Z","shell.execute_reply.started":"2022-10-26T21:47:55.506114Z","shell.execute_reply":"2022-10-26T21:47:55.522886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### <span style=\"font-family:verdana; word-spacing:1.5px;\"> Lets plot some spectograms. One with a simulated signal and one without!","metadata":{}},{"cell_type":"code","source":"sns.reset_orig() # Reset seaborn theme (otherwise these plots come out red 😅)\ndata = extract_data_from_hdf5(train_example_with_signal_path, labels_df)\nplot_spectograms(data)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:47:55.526034Z","iopub.execute_input":"2022-10-26T21:47:55.52646Z","iopub.status.idle":"2022-10-26T21:48:00.754122Z","shell.execute_reply.started":"2022-10-26T21:47:55.526424Z","shell.execute_reply":"2022-10-26T21:48:00.752351Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"data = extract_data_from_hdf5(train_example_without_signal_path, labels_df)\nplot_spectograms(data)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:00.755731Z","iopub.execute_input":"2022-10-26T21:48:00.756608Z","iopub.status.idle":"2022-10-26T21:48:05.818948Z","shell.execute_reply.started":"2022-10-26T21:48:00.756565Z","shell.execute_reply":"2022-10-26T21:48:05.817593Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"#### <span style=\"font-family:verdana; word-spacing:1.5px;\"> Very hard to notice any difference at all 🤔","metadata":{}},{"cell_type":"markdown","source":"# ","metadata":{}},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# What do the real and imaginary parts of a Short-time Fourier Transforms mean? 👻","metadata":{}},{"cell_type":"markdown","source":"## Plotting Spectograms\n\n## Basic spectrogram image classification \n    COPIED FROM 🐢 JUN KODA\n\n","metadata":{}},{"cell_type":"markdown","source":"Power spectrum is averaged over every N = 32 timesteps:\n\n$$ P(\\omega) = \\frac{1}{N} \\sum_n^N \\left|a(\\omega, t_n) \\right|^2 $$\n\nImage size becomes: 2 channels x 360 frequencies x 128 timesteps.\n\nThe run time is dominated by data loading but I am not optimizing for that.\n\nVersion 4: Fix output target value to [0, 1] with `y_pred.sigmoid()`.","metadata":{}},{"cell_type":"code","source":"def power_spectrogram(h1_sft):\n    img = np.empty((1,360, 128), dtype=np.float32)\n    a=h1_sft[:, :4096] * 1e23\n    p = a.real**2 + a.imag**2  # power\n    p /= np.mean(p)  # normalize\n    p = np.mean(p.reshape(360, 128, 32), axis=2)\n    img[0] = p\n    fig, (ax1, ax2) = plt.subplots(1, 2,figsize=(5, 5))\n    fig.suptitle('power density - and zoom of the zoom')\n    ax1.imshow(img[0])\n    ax2.imshow(img[0, 300:360])\n    fig.tight_layout()\ndef power_spectrogram2(h1_sft):\n    img = np.empty((1,360, 128), dtype=np.float32)\n    a=h1_sft[:, :4096] * 1e23\n    p = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) # power\n    p /= np.mean(p)  # normalize\n    p = np.mean(p.reshape(360, 128, 32), axis=2)\n    img[0] = p\n    fig, (ax1, ax2) = plt.subplots(1, 2,figsize=(5, 5))\n    fig.suptitle('power density - and zoom of the zoom')\n    ax1.imshow(img[0])\n    ax2.imshow(img[0, 300:360])\n    fig.tight_layout()\n","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:05.82083Z","iopub.execute_input":"2022-10-26T21:48:05.821305Z","iopub.status.idle":"2022-10-26T21:48:05.83526Z","shell.execute_reply.started":"2022-10-26T21:48:05.821255Z","shell.execute_reply":"2022-10-26T21:48:05.833816Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"> **Variant 1:   p = a.real\\*\\*2 + a.imag\\*\\*2  # power**","metadata":{}},{"cell_type":"code","source":"power_spectrogram(h1_sft)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:05.837279Z","iopub.execute_input":"2022-10-26T21:48:05.837723Z","iopub.status.idle":"2022-10-26T21:48:06.16814Z","shell.execute_reply.started":"2022-10-26T21:48:05.837684Z","shell.execute_reply":"2022-10-26T21:48:06.166765Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" >  **Variant 2:    2\\*(a.real\\*\\*2 + a.imag\\*\\*2)/(1800 \\* 1e24\\*\\* 2) # normalized power**","metadata":{}},{"cell_type":"code","source":"power_spectrogram2(h1_sft)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:06.173385Z","iopub.execute_input":"2022-10-26T21:48:06.173803Z","iopub.status.idle":"2022-10-26T21:48:06.563517Z","shell.execute_reply.started":"2022-10-26T21:48:06.173762Z","shell.execute_reply":"2022-10-26T21:48:06.56226Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## power 3D view","metadata":{}},{"cell_type":"code","source":"from mpl_toolkits.mplot3d import Axes3D\n#X = np.linspace(-20,20,100)\nX = np.linspace(0,360,num=360)\nY = np.linspace(0, 128, num=128)\nX, Y = np.meshgrid(X,Y)\nprint(X.shape,Y.shape)\na=h1_sft[:, :4096] * 1e24\np = np.absolute(a)+np.angle(a) # power\np /= np.mean(p)  # normalize\np = np.mean(p.reshape(360, 128, 32), axis=2)\np.shape\n#Z = 4*xx**2 + yy**2\nZ=p.T\nfig = plt.figure()\nax = fig.add_subplot(111, projection='3d')\nax.plot_surface(X, Y, Z, cmap=\"hsv\", linewidth=0, antialiased=False, alpha=0.3)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:06.565442Z","iopub.execute_input":"2022-10-26T21:48:06.565816Z","iopub.status.idle":"2022-10-26T21:48:07.216011Z","shell.execute_reply.started":"2022-10-26T21:48:06.56578Z","shell.execute_reply":"2022-10-26T21:48:07.215076Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"fig = plt.figure(figsize=(8,8))\nax = fig.add_subplot(111, projection='3d')\nax.plot_surface(X, Y, Z, cmap=\"plasma\", linewidth=0, antialiased=False, alpha=0.2)\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:50:28.752797Z","iopub.execute_input":"2022-10-26T21:50:28.753192Z","iopub.status.idle":"2022-10-26T21:50:29.567553Z","shell.execute_reply.started":"2022-10-26T21:50:28.753139Z","shell.execute_reply":"2022-10-26T21:50:29.566495Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"###  Alternatives partial compression\nTo compress or to augument more?","metadata":{}},{"cell_type":"code","source":"img = np.empty((3,360, 128), dtype=np.float32)\na=h1_sft[:, :4096] * 1e23\np = 2*(a.real**2 + a.imag**2)/(1800 * 1e24** 2) # power\np /= np.mean(p)  # normalize\np=p.reshape(360, 128, 32)\n#split the compression\np1=p[:,:,0:16]\np2=p[:,:,16:32]\np = np.mean(p, axis=2)\np1 = np.mean(p1, axis=2)\np2 = np.mean(p2, axis=2)\nimg[0] = p1\nimg[1] = p2\nimg[2] = p\nfig, (ax1, ax2,ax3) = plt.subplots(3, 1,figsize=(8, 8))\nplt.rcParams['image.cmap'] = 'BuPu'\nfig.suptitle('power density - and zoom of the zoom')\nax1.set_title(\"slice 0:16\")\nax2.set_title(\"slice 16:32\")\nax3.set_title(\"compressed 0:32\")\nax1.imshow(img[0, 300:360])\nax2.imshow(img[1, 300:360])\nax3.imshow(img[2, 300:360])\nfig.tight_layout()\n\n    \n    ","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:07.217595Z","iopub.execute_input":"2022-10-26T21:48:07.218473Z","iopub.status.idle":"2022-10-26T21:48:07.911232Z","shell.execute_reply.started":"2022-10-26T21:48:07.218432Z","shell.execute_reply":"2022-10-26T21:48:07.909887Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Timestamp analysis ⏱\n\nSince the continuous gravitational wave is simulated I am not sure how the length of it is determined (it seems to be hard coded in the [generating signals nb](https://github.com/PyFstat/PyFstat/blob/ec86602bb2f93238492a7242ad90995f6654eab7/examples/tutorials/1_generating_signals.ipynb)). As a result, I assume that the timestamp data is relatively meaningless... for completness I will include a few plots :)","metadata":{}},{"cell_type":"code","source":"### Extract timestamp data from training data ###\n\nH1_timestamps, L1_timestamps, start_diff, labels, freq = ([] for i in range(5))\n\nfor p in tqdm(os.listdir(TRAIN_PATH), total=len(os.listdir(TRAIN_PATH))):\n    id_ = p.split('.')[0]\n    labels.append(labels_df.loc[labels_df.id==id_].target.item())\n    data = extract_data_from_hdf5(DATA_PATH/'train'/p, labels_df)\n    L1_timestamps.append(data['L1_ts'])\n    H1_timestamps.append(data['H1_ts'])\n    start_diff.append(data['L1_ts'][0] - data['H1_ts'][0])\n    freq.append(data['freq'])","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:48:07.913188Z","iopub.execute_input":"2022-10-26T21:48:07.913606Z","iopub.status.idle":"2022-10-26T21:50:26.17159Z","shell.execute_reply.started":"2022-10-26T21:48:07.913565Z","shell.execute_reply":"2022-10-26T21:50:26.169221Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.DataFrame({'label':labels, 'L1_timestamp_length':[len(i) for i in L1_timestamps], 'H1_timestamp_length':[len(i) for i in H1_timestamps], 'Differnce in start time between detectors':start_diff})\ndf = df[df.label!=-1]","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:50:26.175845Z","iopub.execute_input":"2022-10-26T21:50:26.176343Z","iopub.status.idle":"2022-10-26T21:50:26.190544Z","shell.execute_reply.started":"2022-10-26T21:50:26.176294Z","shell.execute_reply":"2022-10-26T21:50:26.18919Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sns.set_theme()\n\nfig, ax = plt.subplots(1,3, figsize=(24,8))\nfig.suptitle(f\"In the plots the distribution of timestamps for both classes are shown; 1 indicates a simulated CW present and 0 not present\", fontsize=16)\nsns.histplot(\n        df, x=\"L1_timestamp_length\", hue=\"label\",\n        stat=\"density\", common_norm=False, bins=20, ax=ax[0], kde=True).set_title('Length of measurement for Livingston detector', fontsize=16);\n\nsns.histplot(\n        df, x=\"H1_timestamp_length\", hue=\"label\",\n        stat=\"density\", common_norm=False, bins=20, ax=ax[1], kde=True).set_title('Length of measurement for Hanford detector', fontsize=16);\n\nsns.histplot(\n        df, x=\"Differnce in start time between detectors\", hue=\"label\",\n        stat=\"density\", common_norm=False, bins=20, ax=ax[2], kde=True).set_title('Difference in starting timestamp between detectors', fontsize=16);","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:50:26.192398Z","iopub.execute_input":"2022-10-26T21:50:26.192763Z","iopub.status.idle":"2022-10-26T21:50:28.287025Z","shell.execute_reply.started":"2022-10-26T21:50:26.192731Z","shell.execute_reply":"2022-10-26T21:50:28.285701Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Frequency analysis 📳\n\nDo the detectors measure the same range of frequencies each time? No. The range varies but the minimum freq measured is ~50 Hz and the maximum is ~498 Hz","metadata":{}},{"cell_type":"code","source":"plt.figure(figsize=(14,6))\nsns.histplot(x=list(np.hstack(freq)), binwidth=20)\nplt.title('Histogram of the range of Frequencies detected');\nplt.xlabel('Frequency Hz')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:50:28.28884Z","iopub.execute_input":"2022-10-26T21:50:28.289373Z","iopub.status.idle":"2022-10-26T21:50:28.714128Z","shell.execute_reply.started":"2022-10-26T21:50:28.289332Z","shell.execute_reply":"2022-10-26T21:50:28.712733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Generating more data ⚙️","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Types of Noise\n- Non-stationary noise\n- Gaps\n- Narrow instrumental artifacts\n- Multiple detectors\n\nTypes of signal generation","metadata":{}},{"cell_type":"markdown","source":"# Baseline 📈","metadata":{}},{"cell_type":"markdown","source":"# Sample Submission","metadata":{}},{"cell_type":"code","source":"samp_sub = pd.read_csv(DATA_PATH/'sample_submission.csv')\nsamp_sub['target'] = 0.55\nsamp_sub.to_csv('submission.csv', index=False)","metadata":{"execution":{"iopub.status.busy":"2022-10-26T21:50:28.715611Z","iopub.execute_input":"2022-10-26T21:50:28.715939Z","iopub.status.idle":"2022-10-26T21:50:28.749561Z","shell.execute_reply.started":"2022-10-26T21:50:28.715908Z","shell.execute_reply":"2022-10-26T21:50:28.748442Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# WIP :)","metadata":{}},{"cell_type":"markdown","source":"#### Bibliography\n* https://kevinsprojects.wordpress.com/2014/12/13/short-time-fourier-transform-using-python-and-numpy/\n* https://www.ligo.org/science/GW-Continuous.php\n* https://link.springer.com/article/10.12942/lrr-2011-5\n* https://cplberry.com/2015/01/10/1408-0740/\n* https://www.aei.mpg.de/581560/a-milestone-in-the-race-to-find-the-first-continuous-gravitational-wave-signal\n* https://www.einstein-online.info/en/spotlight/continuousGW/","metadata":{}},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}