MATLAB Answers

Finding the Square root of a signal using matlab and C language with out using sqrt function

조회 수: 16(최근 30일)
Hari Ijjada
Hari Ijjada 3 Dec 2019
편집: Corentin OGER 3 Dec 2019
I am using Sqare Law demodualtor For AM Demodulation.
i am getting two terms 1)m^2(t)/2
first applyig LPF so that High Frequencies will eliminate,what should i need to get exact m(t) from the m^2(t)...becuase i have to transform the Matlab code to C code also and i should get the same m(t) after executing the program in C Code also...
input signal is an audio signal....

  댓글 수: 0

댓글을 달려면 로그인하십시오.


Corentin OGER
Corentin OGER 3 Dec 2019
편집: Corentin OGER 3 Dec 2019
I'm not sure why you can't use a square root in C, do you not have a C library like "math.h" that includes square root? (I never code in C)
Sometimes, when I need to "emulate" a ressource-heavy function (to run on a real-time machine with limited ressources), I simply use a look-up table with linear interpolation (you can even make your own interpolation function).
Something like this very crude version (for input between 0 and 100):
function [ Out ] = DirtySqrt( In )
TableX = [0 0.2 0.4 1 2 4 10 20 40 100]; %Very Coarse values 0=>100
TableY = [0 0.4472 0.6325 1 1.4142 2 3.1623 4.4721 6.3246 10]; %Pre-caluclated
%they could be globals initialized at Startup, or passed to the function as arguments
In = abs(In); %absolute value
Out = interp1(TableX, TableY, In); %You can make your own interp function
>> DirtySqrt(-9)
ans =
For example, if it's just to evaluate the RMS power of a wave, you don't necessarily need great accuracy.
A larger look-up table (thousands of values) could also be stored in a file and loaded at startup.

  댓글 수: 0

댓글을 달려면 로그인하십시오.


Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by