MCPcopy Create free account
hub / github.com/Meshcapade/difflocks / strands_from_signal_torch1

Function strands_from_signal_torch1

utils/general_util.py:331–367  ·  view source on GitHub ↗
(signal,input_type,decode_type,norm='ortho')

Source from the content-addressed store, hash-verified

329
330
331def strands_from_signal_torch1(signal,input_type,decode_type,norm='ortho'):
332
333 if input_type=='fft':
334 N = signal.shape[1]//2
335 F_cos = signal[:,: N]
336 F_sin = signal[:,N:2 * N]
337
338 # phase = F_cos * F_A + 1j*F_sin * F_A
339 phase = F_cos + 1j * F_sin
340 F_A = torch.abs(phase)
341
342 phase = torch.angle(phase)
343 reconstructed_fft_result = F_A * torch.exp(1j * phase)
344 reconstructed_fft_result = torch.fft.irfft(reconstructed_fft_result,dim=-2,norm=norm)
345 elif input_type=='chunked_fft':
346
347 N = signal.shape[1]//3
348 reconstructed_fft_result =[]
349 for i in range(3):
350 sub_signal = signal[:,N*i:(i+1)*N]
351
352 F_cos = sub_signal[:, : N//2]
353 F_sin = sub_signal[:, N//2: N]
354
355 phase = F_cos + 1j * F_sin
356 F_A = torch.abs(phase)
357 phase = torch.angle(phase)
358 reconstructed_fft= F_A * torch.exp(1j * phase)
359 reconstructed_fft = torch.fft.irfft(reconstructed_fft, dim=-2, norm=norm) #B,nr_points//3,3
360 reconstructed_fft_result.append(reconstructed_fft)
361 reconstructed_fft_result = torch.cat(reconstructed_fft_result,1)
362
363 if decode_type=='dir':
364 reconstructed_fft_result = torch.cumsum(reconstructed_fft_result,dim=1)
365
366
367 return reconstructed_fft_result
368
369def strands_from_signal_torch2(signal,norm='ortho'):
370 N = signal.shape[1]//2

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected