Posts

Showing posts with the label MathLib

Using MathLib in Artificial Intelligence systems - computing sqrt in Matlab vs. SystemVerilog

Image
Consider an AI (Artificial Intelligence) engine trying to decipher key information from a series of images in real-time. Fourier transform is a powerful tool used to analyze and manipulate images in the frequency domain. The Fourier transform of an image result in a complex-valued representation, consisting of real and imaginary components. To visualize the frequency content of the image or perform further analysis, it is common to calculate the magnitude of this complex representation. This is done by computing the square-root ( sqrt ) of the sum of the squares of its real and imaginary components. By applying the sqrt function to the complex image representation, we can obtain the magnitude image. At system level, Matlab is commonly used to model such algorithms. Matlab's sqrt  works with both positive and negative numbers, which is different from a typical IEEE 754 standard. While SystemVerilog has a built-in system function $sqrt()  - it works only with scalars and does no...

MathLib - computing modulo on real numbers in SystemVerilog

  Think of noise filtering algorithms, floating point computations etc. - a handy operator in such circumstances is   modulo  - loosely defined as a function that returns remainder after division (however, there is a close cousin   rem  - for later discussion).  System designers often use   mod  function to perform certain periodic functions, DSP algorithms etc. When such systems are implemented in hardware, designers often use Verilog to capture the same intent. Verilog (or SystemVerilog) has   %  operator in-built to provide basic support for modulo computation - it works just fine for unsigned integers. However, in behavioral models, testbenches and AMS models, often real numbers get involved and suddenly you get an error from your favorite HDL simulator as below (Verilator as example): %Error: t.sv:7:32: Expected integral (non-real) input to MODDIV : ... In instance m 7 | $display ("3.2 MOD 1: %f", 3.2%1...