Skip to content

Commit

Permalink
issue 321 fd_to_td() bug (#329)
Browse files Browse the repository at this point in the history
* bug bix : DC and Nyquist frequency should not be devided by two before ifft


* Changed td_to_fd to scale single sided frequency components rather than TD signal

* minor bug fix from issue332 #332
  • Loading branch information
dtgaebe committed Apr 3, 2024
1 parent 2abb4fb commit 6fdd660
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions wecopttool/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -705,7 +705,7 @@ def solve(self,
results = []

# x_wec scaling vector
if scale_x_wec == None:
if scale_x_wec is None:
scale_x_wec = [1.0] * self.ndof
elif isinstance(scale_x_wec, float) or isinstance(scale_x_wec, int):
scale_x_wec = [scale_x_wec] * self.ndof
Expand Down Expand Up @@ -1752,7 +1752,8 @@ def fd_to_td(
td = tmat @ complex_to_real(fd, zero_freq)
elif (f1 is None) and (nfreq is None):
n = 2*(fd.shape[0]-1)
td = np.fft.irfft(fd/2, n=n, axis=0, norm='forward')
fd = np.concatenate((fd[:1, :], fd[1:-1, :]/2, fd[-1:, :]))
td = np.fft.irfft(fd, n=n, axis=0, norm='forward')
else:
raise ValueError(
"Provide either both 'f1' and 'nfreq' or neither.")
Expand Down Expand Up @@ -1788,10 +1789,10 @@ def td_to_fd(
td= atleast_2d(td)
n = td.shape[0]
if fft:
fd = np.fft.rfft(td*2, n=n, axis=0, norm='forward')
fd = np.fft.rfft(td, n=n, axis=0, norm='forward')
else:
fd = np.dot(dft(n, 'n')[:n//2+1, :], td*2)
fd = np.concatenate((fd[:1, :]/2, fd[1:-1, :], fd[-1:, :]/2))
fd = np.dot(dft(n, 'n')[:n//2+1, :], td)
fd = np.concatenate((fd[:1, :], fd[1:-1, :]*2, fd[-1:, :]))
if not zero_freq:
fd = fd[1:, :]
return fd
Expand Down

0 comments on commit 6fdd660

Please sign in to comment.