compute squarepulse using pytorch equivalent to numpy implementation from https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.square.html
(sig, duty: float = 0.5)
| 2227 | |
| 2228 | |
| 2229 | def squarepulse(sig, duty: float = 0.5): |
| 2230 | """ |
| 2231 | compute squarepulse using pytorch |
| 2232 | equivalent to numpy implementation from |
| 2233 | https://docs.scipy.org/doc/scipy/reference/generated/scipy.signal.square.html |
| 2234 | """ |
| 2235 | t, w = convert_to_tensor(sig), convert_to_tensor(duty) |
| 2236 | w = convert_to_tensor(w) |
| 2237 | t = convert_to_tensor(t) |
| 2238 | |
| 2239 | y = torch.zeros(t.shape) |
| 2240 | |
| 2241 | mask1 = (w > 1) | (w < 0) |
| 2242 | |
| 2243 | tmod = torch.remainder(t, 2 * torch.pi) |
| 2244 | mask2 = (~mask1) & (tmod < w * 2 * torch.pi) |
| 2245 | y[mask2] = 1 |
| 2246 | mask3 = (~mask1) & (~mask2) |
| 2247 | y[mask3] = -1 |
| 2248 | return y |
| 2249 | |
| 2250 | |
| 2251 | def _to_numpy_resample_interp_mode(interp_mode): |
no test coverage detected
searching dependent graphs…