Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

How to use ROM in Matlab

Status
Not open for further replies.

syedshan

Advanced Member level 1
Joined
Feb 27, 2012
Messages
463
Helped
27
Reputation
54
Reaction score
26
Trophy points
1,308
Location
Jeonju, South Korea
Activity points
5,134
Dear all,

I have to implement a ROM table for sine function in Matlab, and I do not find any way in Matlab functions.
One Idea that is in my mind is the use of Array and it might behave as ROM. Any idea about that.

If so, how can I compute the angle, e.g. in ROM there are discrete samples only. But if I give for example 32.34 degrees angles,
How can I get to know from which place to fetch data from. Is there any function in Matlab ( as I cannot find it) or should I make my own function.

Please share your experiences about this.

Bests,
Shan
 

ROM is always an array.
You store the values for one period of sine only. And different sine wave frequencies are achieved by reading values from table at different rates.

To take the sine value for your exact angle you may just choose nearest or interpolate between two nearest table values.
 
Thank you very much

For interpolation I did the following. Please comment if it is right method.


The approach I applied is this. Please comment if it is right or if there is some better way.

Angle range is from 0 -> 2 x PI ... so since I take 12 bits as the angle theta hence the ROM size is 12 bits. ( I know that it will take much space but I did it intentionally). so I have 4096 locations in ROM.

Next I divide range by 4096 to get the minimum d/f between two theta values... and then store sine and cosine accordingly....

Now the Interpolation. See the variable 'num'. which you can say is the address of the angle in ROM.
Although it yields competent result, but is there better way to get more accurate result.

Code in Matlab
Code:
%4096 samples of theta
theta_range=pi/4;
dtheta = transpose(theta_range / (4095));
theta = transpose(0:dtheta:theta_range);

%ROM table
wave_sine = sin(theta);
wave_cosine = cos(theta);

%Collecting Data
Xo = input('What is the value of Xo : ');
Yo = input('What is the value of Yo : ');
Val = input('What is the angle value (Degrees) : ');
rad =  Val*(pi/180); %to convert to radian

%sort of interpolation
num = int16(rad/dtheta) + 1;

X= Xo * cosine_wave(num) - Yo*sine_wave(num);


Bests,
Shan
 

1. 4096 samples - is not very long table, that's a widespread value in dsp applications.
2. You took only pi/4 values but not less than pi/2 may be enough.
3. You made no interpolation, only next closer value from table.
To interpolate you should take values
num1 = int16(rad/dtheta)
num2 = num1 + 1;
Interpolated_cos_value = (cosine_wave(num2) - cosine_wave(num1))*rem(rad,dtheta)/dtheta;
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top