Perform Expand Operation in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:59:35

3K+ Views

Tensor.expand() attribute is used to perform expand operation. It expands the Tensor to new dimensions along the singleton dimension.Expanding a tensor only creates a new view of the original tensor; it doesn't make a copy of the original tensor.If you set a particular dimension as -1, the tensor will not be expanded along this dimension.For example, if we have a tensor of size (3, 1), we can expand this tensor along the dimension of size 1.StepsTo expand a tensor, one could follow the steps given below −Import the torch library. Make sure you have already installed it.import torchDefine a tensor ... Read More

Create Tensors with Gradients in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:54:45

5K+ Views

To create a tensor with gradients, we use an extra parameter "requires_grad = True" while creating a tensor.requires_grad is a flag that controls whether a tensor requires a gradient or not.Only floating point and complex dtype tensors can require gradients.If requires_grad is false, then the tensor is same as the tensor without the requires_grad parameter.Syntaxtorch.tensor(value, requires_grad = True)Parametersvalue – tensor data, user-defined or randomly generated.requires_grad – a flag, if True, the tensor is included in the gradient computation.OutputIt returns a tensor with requires_grad as True.StepsImport the required library. The required library is torch.Define a tensor with requires_grad = TrueDisplay the ... Read More

Find Element-wise Remainder in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:49:37

312 Views

Element-wise remainder when a tensor is divided by other tensor is computed using the torch.remainder() method. We can also apply torch.fmod() to find the remainder.The difference between these two methods is that in torch.remainder(), when the sign of result is different than the sign of divisor, then the divisor is added to the result; whereas in torch.fmod(), it is not added.Syntaxtorch.remainder(input, other) torch.fmod(input, other)ParametersInput – It is a PyTorch tensor or scalar, the dividend.Other – It is also a PyTorch tensor or scalar, the divisor.OutputIt returns a tensor of element-wise remainder values.StepsImport the torch library.Define tensors, the dividend and the ... Read More

Compute Singular Value Decomposition (SVD) of a Matrix in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:43:33

989 Views

torch.linalg.svd() computes the singular value decomposition (SVD) of a matrix or a batch of matrices. Singular value decomposition is represented as a named tuple (U, S, Vh).U and Vh are orthogonal for real matrix and unitary for input complex matrix.Vh is transpose of V when V is a real value and conjugate transpose when V is complex.S is always real valued even when the input is complex.SyntaxU, S, Vh = torch.linalg.svd(A, full_matrices=True)ParametersA – PyTorch tensor (matrix or batch of matrices).full_matrices – If True, the output is a full SVD, else a reduced SVD. Default is True.OutputIt returns a named tuple ... Read More

Perform In-Place Operations in PyTorch

Shahid Akhtar Khan
Updated on 06-Dec-2021 10:31:27

2K+ Views

In-place operations directly change the content of a tensor without making a copy of it. Since it does not create a copy of the input, it reduces the memory usage when dealing with high-dimensional data. An in-place operation helps to utilize less GPU memory.In PyTorch, in-place operations are always post-fixed with a "_", like add_(), mul_(), etc.StepsTo perform an in-place operation, one could follow the steps given below −Import the required library. The required library is torch.Define/create tensors on which in-place operation is to be performed.Perform both normal and in-place operations to see the clear difference between them.Display the tensors ... Read More

What is Even Symmetry in Signals and Systems

Manish Kumar Saini
Updated on 06-Dec-2021 05:34:30

3K+ Views

Importance of Wave SymmetryIf a periodic signal 𝑥(𝑡) has some type of symmetry, then some of the trigonometric Fourier series coefficients may become zero and hence the calculation of the coefficients becomes simple.Even or Mirror SymmetryWhen a periodic function is symmetrical about the vertical axis, it is said to have even symmetry or mirror symmetry. The even symmetry is also called the reflection symmetry. Mathematically, a periodic function x(t) is said to have even symmetry, if$$\mathrm{𝑥(𝑡) = 𝑥(−𝑡)\:\:\:\:\:\: ...(1)}$$Some examples of functions having even symmetry are shown in the figure. The even functions are always symmetrical about the vertical axis.ExplanationAs ... Read More

Complex Exponential Fourier Series in Signals and Systems

Manish Kumar Saini
Updated on 06-Dec-2021 04:46:38

6K+ Views

Exponential Fourier SeriesPeriodic signals are represented over a certain interval of time in terms of the linear combination of orthogonal functions. If these orthogonal functions are the exponential functions, then the Fourier series representation of the function is called the exponential Fourier series.The exponential Fourier series is the most widely used form of the Fourier series. In this representation, the periodic function x(t) is expressed as a weighted sum of the complex exponential functions. The complex exponential Fourier series is the convenient and compact form of the Fourier series, hence, its findsextensive application in communication theory.ExplanationLet a set of complex ... Read More

Conjugation and Autocorrelation Property of Fourier Transform

Manish Kumar Saini
Updated on 03-Dec-2021 13:34:42

8K+ Views

Fourier TransformFor a continuous-time function x(t), the Fourier transform of x(t) can be defined as, $$\mathrm{X(\omega)=\int_{-\infty}^{\infty}x(t)e^{-j\omega t}dt}$$Conjugation Property of Fourier TransformStatement − The conjugation property of Fourier transform states that the conjugate of function x(t) in time domain results in conjugation of its Fourier transform in the frequency domain and ω is replaced by (−ω), i.e., if$$\mathrm{x(t)\overset{FT}{\leftrightarrow}X(\omega)}$$Then, according to conjugation property of Fourier transform, $$\mathrm{x^*(t)\overset{FT}{\leftrightarrow}X^*(-\omega)}$$ProofFrom the definition of Fourier transform, we have$$\mathrm{X(\omega)=\int_{-\infty}^{\infty}x(t)e^{-j\omega t}dt}$$Taking conjugate on both sides, we get$$\mathrm{X^*(\omega)=[\int_{-\infty}^{\infty}x(t)e^{-j\omega t}dt]^*}$$$$\mathrm{\Rightarrow X^*(\omega)=\int_{-\infty}^{\infty}x^*(t)e^{j\omega t}dt}$$Now, by replacing (ω) by (−ω), we obtain, $$\mathrm{X^*(-\omega)=\int_{-\infty}^{\infty}x^*(t)e^{-j\omega t}dt=F[x^*(t)]}$$$$\mathrm{\therefore F[x^*(t)]=X^*(-\omega)}$$Or, it can also be represented as, $$\mathrm{x^*(t)\overset{FT}{\leftrightarrow}X^*(-\omega)}$$Autocorrelation Property ... Read More

Average Power Calculations of Periodic Functions using Fourier Series

Manish Kumar Saini
Updated on 03-Dec-2021 13:22:43

1K+ Views

When a voltage of V volts is applied across a resistance of R Ω, then a current I flows through it. The power dissipated in the resistance is given by, $$\mathrm{P=I^2R=\frac{V^2}{R}\:\:\:\:\:\:....(1)}$$But when the voltage and current signals are not constant, then the power varies at every instant, and the equation for the instantaneous power is given by, $$\mathrm{P=i^2(t)R=\frac{V^2(t)}{R}\:\:\:\:\:\:....(2)}$$Where, 𝑖(𝑡) and 𝑣(𝑡) are the corresponding instantaneous values of current and voltage respectivelyNow, if the value of the resistance (R) is 1 Ω, then the instantaneous power can be represented as, $$\mathrm{p=i^2(t)=v^2(t)\:\:\:\:\:\:....(3)}$$Therefore, the instantaneous power of a signal x(t) can be given ... Read More

Duality Property of Fourier Transform in Signals and Systems

Manish Kumar Saini
Updated on 03-Dec-2021 13:11:55

24K+ Views

Fourier TransformFor a continuous-time function x(t), the Fourier transform of x(t) can be defined as$$\mathrm{X(\omega)= \int_{-\infty}^{\infty}x(t)e^{-j\omega t}dt}$$Duality Property of Continuous-Time Fourier TransformStatement – If a function x(t) has a Fourier transform X(ω) and we form a new function in time domain with the functional form of the Fourier transform as X(t), then it will have a Fourier transform X(ω) with the functional form of the original time function, but it is a function of frequency.Mathematically, the duality property of CTFT states that, if$$\mathrm{x(t)\overset{FT}{\leftrightarrow}X(\omega)}$$Then, according to duality property, $$\mathrm{X(t)\overset{FT}{\leftrightarrow}2\pi x(-\omega)}$$ProofFrom the definition of inverse Fourier transform, we have$$\mathrm{x(t)=\frac{1}{2\pi}\int_{-\infty}^{\infty}X(\omega)e^{j\omega t}d\omega }$$$$\mathrm{\Rightarrow 2\pi.x(t)=\int_{-\infty}^{\infty}X(\omega)e^{j\omega ... Read More

Advertisements