Finding the Square root of a signal using matlab and C language with out using sqrt function
    7 visualizaciones (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
I am using Sqare Law  demodualtor For AM Demodulation.
i am getting two terms 1)m^2(t)/2
                                     2)cos(4*pi*Fc*T)                                                                            
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...
                 F_Sample=48000  
         F_Carrier=12500 
input signal is an audio signal....                                                                                                                                
0 comentarios
Respuestas (1)
  Corentin OGER
      
 el 3 de Dic. de 2019
        
      Editada: Corentin OGER
      
 el 3 de Dic. de 2019
  
      Hello,
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
end
>> DirtySqrt(-9)
ans =
    2.9686
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 comentarios
Ver también
Categorías
				Más información sobre Startup and Shutdown en Help Center y File Exchange.
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

