How to create Trignometric function lookup table

Hi
I need help to create a lookup table for twiddle factor generated by trignometric cosine and sine function ?
Thanks

12 Comments

Why?
t=linspace(0,2*pi,1000);
lookup=[t;cos(t)];
Thank you !
I was looking something like below code .
  • Can you pls add further to improve say 1/4 quater radian lookup table and calculate all angles / radians ?
  • What is best and efficient way for generating the lookup to get twiddle factor real and imaginary points ?
  • How fft and ifft calculation can be improved here in case I use cordic sine and cosine lookup table ?
  • cordiccosine and cordicsine Lookup table for N point FFT length ( say 1024,2048 upto 8192) ?
% Angle_rad = [-2*pi:1:2*pi];
close all;
clearvars;clc;
Angle_th = [0:1:360]; %
lookup_table = cos(Angle_th*2*pi/360); % replace cos with
% Replace current code here with pseudo
% What is the size of lookup table ? FFT length -1 , N = 1024, N*m-1 ( m
% =2,3,4 etc )
% cdcCosineTh = cordiccos(th_Rad_fix = [-2*pi :steps: 2*pi]);
% cdcsinTh = cordicsin(th_Rad_fix = [-2*pi :steps: 2*pi]);
% lookup_table[sizeof(FFT_Index)] = cordiccos(th_Rad_fix = [-2*pi :steps: 2*pi]) + -j*cordicsin(th_Rad_fix = [-2*pi :steps: 2*pi]);
% Which Radix 2/4/8/16/64/128/256 for odd and even is suggested and why ?
% How real and imaginary lookup table looks like
% Input real_lookup_cordiccos(angles[0:360])
% Input imag_lookup_cordicsin(angles[0:360])
% Accuracy ,performat and speed are determined by total harmonic
% distortion in -dBc i.e. SNR = rms( cordiccos & cordicsin -
% lookup_table_real & lookup_table_imag)
% It should work for iFFT and FFT implementation (reconstruct) without dC
% and capture fundamental and all harmonics for 2 octave onwards
% clf;
figure;
subplot(3,2,1);
plot(1:size(Angle_th,2),cos(Angle_th*2*pi/360),'g--','Linewidth', 1.5); hold on; grid on;
xlabel('\theta');
h1.XLim = [0, 2*pi];
h1.XTick =[0:22.5:360];
h1.XTickLabel = {'0', '45', '90','135' , '180' , '225' , '270' , '315' , '360'};
h1.YTick = -1:0.5:1;
h1.YTickLabel = {'-1.0','-0.5','0','0.5','1.0'};
title('Trignometric-Cosine-Lookup-table');
subplot(3,2,2);
plot(1:size(Angle_th,2),sin(Angle_th*2*pi/360),'r--','Linewidth', 1.5); hold on; grid on;
xlabel('\theta');
h1.XLim = [0, 2*pi];
h1.XTick =[0:22.5:360];
h1.XTickLabel = {'0', '45', '90','135' , '180' , '225' , '270' , '315' , '360'};
h1.YTick = -1:0.5:1;
h1.YTickLabel = {'-1.0','-0.5','0','0.5','1.0'};
title('Trignometric-sine-Lookup-table');
subplot(3,2,3);
radian = (pi/180)*Angle_th;
plot(Angle_th,radian,'r--'); hold on; grid on;
xlabel('\theta');ylabel('Radian');
subplot(3,2,4);
radian = (pi/180)*Angle_th;
plot(Angle_th,cos(radian),'r--'); hold on; grid on;
xlabel('\theta');ylabel('ARC');
subplot(3,2,5);
degree = (180/pi)*radian;
plot(radian,(degree),'b--'); hold on; grid on;
h1.YLim = [0, 360];
h1.YTick =[0:22.5:360];
h1.YTickLabel = {'0', '45', '90','135' , '180' , '225' , '270' , '315' , '360'};
ylabel('\theta');xlabel('Radian');
subplot(3,2,6);
degree = (180/pi)*radian;
plot(radian,cos(degree),'b--'); hold on; grid on;
ylabel('\theta');xlabel('Arc');
You do not seem to be using the Fixed Point Toolbox, but you seem to be wanting to implement fixed point operations ?
That's right Walter. Initial preparation is done for floating point and next level take it to DSP :-)
The reason is to know the total harmonic distortion across the fltpt and fixpt
Write it using the fixed point toolbox. One of the options for fixed point toolbox use is to override the fixed point definitions with double precision for testing purposes. And you can test in fixed point on the host CPU anyhow.
Thanks, I will do in double precision and take to it fixed point.
@Walter Roberson, can you please help me with some references for twiddle calculation using cordic cosine and cordic sine function?
I am assuming for calculation
twiddle(index) = cos(theta) + (1i*(sin(theta)));
Thank you!
I do not know about twiddle calculation for cordic, so I would have to research it.
Thank you very much@Walter Roberson.
It is not 100% clear How to go about implmentation from the link.
You asked for references about twiddle factor computation; I linked to a reference about twiddle factor computation.
If you had asked for a MATLAB implementation then I probably would not have posted any links. I do not have source code for that purpose, and I do not have time to research the topic and write the code.
No worries @Walter Roberson. Indeed it's super direction you have shared across. A big thank you .
I have some insight now . Folks have worked on this topic and there are advantage of using cordic algorithm for twiddle factor on DSP. May be MathWork documentation is poor and they should come up
With this I can write equation on a paper and start designing the code.

Sign in to comment.

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Asked:

on 15 Apr 2021

Edited:

on 20 Apr 2021

Community Treasure Hunt

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

Start Hunting!