image thumbnail

Trigonometric Function FPGA Implementation using CORDIC Algorithm

by

 

Trigonometric function using CORDIC algorithm is implemented to FPGA.

calc_dev.m
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% CORDIC Culculator
% by Atsushi Matsumoto,  Cybernet Systems, Co., Ltd. All rights reserved.
% 05/01/26
% The CORDIC structure is simulated using Simulink (cordic_culc.mdl).
% Post-processing of the results is done with Matlab.
% 1. Calculates Deviation of CORDIC and MATLAB sin function
% 2. Plots Deviation changing Iterative count.
% CORDIC JԂ񐔂ωƂ̕΍̐ڂvbg
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear all
close all
clc

Fsig=100;					%Sin Wave Frequency
Tsig=1/Fsig;				%Sin wave 1cycle
SgStep=100;					%signal generator step per half cycle

Ts=0.0001;					%sampling time dummy preload		
m=1;						%iteration time dummy preload

%%%%%%%  Set Iteration  %%%%%%%
IterationStart=2;
IterationStop=20;

disp('********  CORDIC Culculation Start  ********')
disp(sprintf('Iteration from %4.0f  to  %4.0f ',(IterationStart),(IterationStop)))
disp('********************************************')

%%%%%%%  Angle Table  %%%%%%%
n=IterationStop+1;					% CORDIC Table size
for ii=1:n							% CORDIC Table
	Angles(ii)=atan(2^(-ii+1));		%*180/pi
end

%vZ郂fJ
%open_system('cordic_calc');

%%%%%%%  CORDIC Calculate  %%%%%%%
for i=1:IterationStop-IterationStart+1
	m=i+IterationStart-1;
	mp(i)=m;
	SgDelay=m;
	disp('********************************************')
	disp(sprintf('Iteration %d  Calculating ...',m))
	Ts=Tsig/SgStep/m;
	sim('cordic_calc',(Ts*SgDelay*(SgStep+0.5)*2));	% Starts Simulink simulation and stop at 1cycle
	WaveData=Wave.signals.values(2:length(Wave.signals.values),:);

	Deviation=WaveData(:,1)-WaveData(:,2);			% ΍vZ
	MaxDeviation(i)=max(abs(Deviation(:,1)));
	Error(i)=sqrt(sum(abs(Deviation(:,1)).^2))/length(Deviation);
end

%%%%%%%  Deviation Display  %%%%%%%
%disp('********************************************')
disp(sprintf('********************************************\nEnd'))
disp(sprintf('\nMax Deviation  %d - %d ',IterationStart,IterationStop))
disp(sprintf('%f\t',MaxDeviation))
disp(sprintf('\nStandard Deviation  %d - %d ',IterationStart,IterationStop))
disp(sprintf('%f\t',Error))

%%%%%%%  Deviation Plot (Linear)  %%%%%%%
figure(1)
plot(mp,MaxDeviation,'o-')
title('CORDIC Algorithm Max Deviation plot (Linear)')
xlabel('Iteration'),grid on
ylabel('Deviation')
set(gcf,'Position',[41    41   672   504])

%%%%%%%  Deviation Plot (Logarithmic)  %%%%%%%
figure(2)
semilogy(mp,MaxDeviation,'ro-')
title('CORDIC Algorithm Max Deviation plot (Logarithmic)')
xlabel('Iteration'),grid on
ylabel('Deviation')
set(gcf,'Position',[721    42   672   504])

Contact us