<p>There were a few mistakes in the treatment of my spectra before fourier transform in the first place. So missing steps were:</p>
<p>1.) The spectra should be averaged to 0 by subtracting the median.</p>
<p>2.) You should tap the spectra at the edges with a window function (e.g. np.blackman())</p>
<p>3.) Cut off pixels at both ends of spectra to avoid discontinuties</p>
<p>Then you recover the correct input LOSVD, using the simple division deconvolution method in fourier space.</p>

CC BY-SA 4.0
2021-06-23T01:51:14.720Z
Congratulations! It's always okay to answer your own question, and if say a week passes and no further answers show up (as is likely in this case) just go ahead and accept your own answer.
uhoh
CC BY-SA 4.0
2021-06-22T08:14:21.570Z
2021-06-22T08:14:21.570Z
trynerror
<p>I am trying to implement a programm, that derives the kinematics (specifically the kinematic parameters: mean rotation velocity, velocity, dispersion, hermite coefficients h3 and h4) from an elliptical galaxy spectrum. I know this has been implemented in many ways, the most common one in recent times beeing ppxf, but I want to do it for educational purposes.
I started by working with a spectrum(variablename = spec) of a K2III star (since they are quite common in early type galaxies), I removed the continuum of the spectrum and rebinned it to a logarithmic wavelength size. Then I created an artifical galaxy spectrum (variablename = spec_gal), by broadening my stellar spectrum with a gaussian losvd with a dispersion of 200 km/s. I therefore just calculated the convolution between the stellar spectrum and the losvd using np.convolve().</p>
<pre><code>spec_gal = np.convolve(losvd_gauss, spec, mode='same')
</code></pre>
<p><a href="https://i.sstatic.net/4Nl6E.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/4Nl6E.png" alt="enter image description here" /></a></p>
<p><a href="https://i.sstatic.net/RRCXH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RRCXH.png" alt="enter image description here" /></a>
Why do the flux values become so small when I convolve the losvd with the spectrum, it should just broaden the absorption lines, shouldn't it ? I suppose that is because I multiply small values of my losvd with the spectral values.</p>
<p>As a small test, I know wanted to obtain back my losvd from the synthetic galaxy spectrum using fourier transformation. Since convolution is multiplicative in fourier space I thought, I could just calculate the fourier transforms of my spectra using scipy.fft().</p>
<pre><code>spec_fourier = fft(spec)
spec_gal_fourier = fft(spec_gal)
</code></pre>
<p>And derive the losvd in fourier-space by dividing my galaxy spectrum in fourier space by the stellar spectrum.</p>
<pre><code> losvd_fourier = spec_gal_fourier/spec_fourier
</code></pre>
<p>I have plotted the np.abs() values of my fourier transformed spectra<a href="https://i.sstatic.net/PU20n.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/PU20n.png" alt="enter image description here" /></a>
I thought i could recover my losvd by just performing the inverse fourier transform using scipy.ifft().</p>
<pre><code>losvd = ifft(losvd_fourier)
</code></pre>
<p>Which is not giving me the correct result (see last plot below) and i would be grateful for remarks, comments and hints on possible errors in theory and implementation.<a href="https://i.sstatic.net/mfZQn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/mfZQn.png" alt="enter image description here" /></a></p>

CC BY-SA 4.0
2021-06-11T10:04:50.197Z
I'm sure you'll get an answer here, but just fyi there is also a [Scientific Computing SE](https://scicomp.stackexchange.com/questions) site as well which is great for numerical questions. By the way what happens if you first normalize your Gaussian convolution kernel to unit area? e.g. `g = g / g.sum()` I did a quick test on some simple data and that seems to be *at least close* to the right thing to do.
uhoh
CC BY-SA 4.0
2021-06-11T10:25:38.353Z
I am actually wondering why my gaussian kernel is not normalized in the first place since I have defined my gaussian losvd with the standard gauss normalization N = 1/sqrt(2pi*sigma^2). Your suggestion resolves the question with the tiny values for my synthetic galaxy spectrum, but the final problem still stands.
trynerror
CC BY-SA 4.0
2021-06-11T10:31:05.767Z
You may have accidentally just left the $\sigma^2$ outside of the square root. Anyway I am confident someone will be able to address your main question.
uhoh
<observational-astronomy><galaxy><spectra><python><kinematics>
Derive LOSVD from galaxy spectrum, using fourier method
trynerror
# Derive LOSVD from galaxy spectrum, using fourier method

(Asked by: username_0 on 2021-06-11)

I am trying to implement a programm, that derives the kinematics (specifically the kinematic parameters: mean rotation velocity, velocity, dispersion, hermite coefficients h3 and h4) from an elliptical galaxy spectrum. I know this has been implemented in many ways, the most common one in recent times beeing ppxf, but I want to do it for educational purposes.
I started by working with a spectrum(variablename = spec) of a K2III star (since they are quite common in early type galaxies), I removed the continuum of the spectrum and rebinned it to a logarithmic wavelength size. Then I created an artifical galaxy spectrum (variablename = spec\_gal), by broadening my stellar spectrum with a gaussian losvd with a dispersion of 200 km/s. I therefore just calculated the convolution between the stellar spectrum and the losvd using np.convolve().

```
spec_gal = np.convolve(losvd_gauss, spec, mode='same')

```

[![enter image description here](https://i.sstatic.net/4Nl6E.png)](https://i.sstatic.net/4Nl6E.png)

[![enter image description here](https://i.sstatic.net/RRCXH.png)](https://i.sstatic.net/RRCXH.png)
Why do the flux values become so small when I convolve the losvd with the spectrum, it should just broaden the absorption lines, shouldn't it ? I suppose that is because I multiply small values of my losvd with the spectral values.

As a small test, I know wanted to obtain back my losvd from the synthetic galaxy spectrum using fourier transformation. Since convolution is multiplicative in fourier space I thought, I could just calculate the fourier transforms of my spectra using scipy.fft().

```
spec_fourier = fft(spec)
spec_gal_fourier = fft(spec_gal)

```

And derive the losvd in fourier-space by dividing my galaxy spectrum in fourier space by the stellar spectrum.

```
 losvd_fourier = spec_gal_fourier/spec_fourier

```

I have plotted the np.abs() values of my fourier transformed spectra[![enter image description here](https://i.sstatic.net/PU20n.png)](https://i.sstatic.net/PU20n.png)
I thought i could recover my losvd by just performing the inverse fourier transform using scipy.ifft().

```
losvd = ifft(losvd_fourier)

```

Which is not giving me the correct result (see last plot below) and i would be grateful for remarks, comments and hints on possible errors in theory and implementation.[![enter image description here](https://i.sstatic.net/mfZQn.png)](https://i.sstatic.net/mfZQn.png)

**Tags:** observational-astronomy, galaxy, spectra, python, kinematics

> **Comments:**
> **username_1**: I'm sure you'll get an answer here, but just fyi there is also a [Scientific Computing SE](https://scicomp.stackexchange.com/questions) site as well which is great for numerical questions. By the way what happens if you first normalize your Gaussian convolution kernel to unit area? e.g. `g = g / g.sum()` I did a quick test on some simple data and that seems to be *at least close* to the right thing to do.  
> **username_0**: I am actually wondering why my gaussian kernel is not normalized in the first place since I have defined my gaussian losvd with the standard gauss normalization N = 1/sqrt(2pi*sigma^2). Your suggestion resolves the question with the tiny values for my synthetic galaxy spectrum, but the final problem still stands.  
> **username_1**: You may have accidentally just left the $\sigma^2$ outside of the square root. Anyway I am confident someone will be able to address your main question.  

---

## 1 answers

### Answer by username_0 on 2021-06-22. Score: 3 | Accepted answer

There were a few mistakes in the treatment of my spectra before fourier transform in the first place. So missing steps were:

1.) The spectra should be averaged to 0 by subtracting the median.

2.) You should tap the spectra at the edges with a window function (e.g. np.blackman())

3.) Cut off pixels at both ends of spectra to avoid discontinuties

Then you recover the correct input LOSVD, using the simple division deconvolution method in fourier space.

> **Comments:**
> **username_1**: Congratulations! It's always okay to answer your own question, and if say a week passes and no further answers show up (as is likely in this case) just go ahead and accept your own answer.  

---

