⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fft_fxp16.m

📁 TigerSharc TS201 32-bit floating point FFT routine
💻 M
字号:
%this program verifies the results obtained in the fft assembly project


clear all;
close all;

%please introduce here the number N from the assembly program.
%Nothing else is to be done
N='32768';


input_file=['inputs/input',N,'.dat'];
output_file=['outputs/outdata_',N,'.dat'];
output_matlab_file=['outputs/outdata_',N,'_matlab.dat'];

%//load input file from generated random value.
        fid = fopen(input_file, 'r');
            [a, count] = fscanf (fid, '0x%04x%04x,\n');
        fclose(fid);

        for i=1:size(a)/2
            im=cvt2real(a(2*i-1));
            re=cvt2real(a(2*i));

            input(i,1)=complex(re, im);
        end;

N1=length(input);  %//get the length of input file and points for FFT.

infft=fft(input,N1);    %//FFT of input.

    fin = fopen(output_matlab_file, 'wt');
        for i=1:N1
          re=cvt2hex(real(infft(i)));
          im=cvt2hex(imag(infft(i)));

          fprintf(fin, '%04x\n%04x\n', re, im);
        end;
    fclose(fin);

inrealfft_in=infft(1:N1);  %need only half points because of TS input.

for i=1:N1
    inrealfft(1,i)=inrealfft_in(i,1); %//change the matrix format.
end


%load the outputs of the assembly program
        fid = fopen(output_file, 'r');
            [output, count] = fscanf (fid, '%04x\n');
        fclose(fid);


for k=1:N1
    outreal(k)=cvt2real(output(2*k-1));
    outimag(k)=cvt2real(output(2*k));
end

realoutput=complex(outreal, outimag);

x=0:1/N1:1-1/N1;
y=0:1/N1:1-1/N1;
mlb=20*log10(abs(inrealfft));
%chip=20*log10(sqrt((outreal.*outreal)+(outimag.*outimag)));
chip=20*log10(abs(realoutput));

figure
subplot(2,2,1);
plot(x,abs(input))      %//plot input data.
grid
title([N,' Input data points'])

subplot(2,2,2);
plot(y,mlb,'r',y,chip,'g')      %//plot Log Magnitude comparison TigerSHARC vs MATLAB.
grid
title('Log Magnitude Comparison, TS in green')

subplot(2,2,3);
plot(y,abs(inrealfft),'r',y,abs(realoutput),'g')  %//plot Magnitude comparison TigerSHARC vs MATLAB.
grid
title('Magnitude Comparison, TS in green')

subplot(2,2,4);
plot(y,abs(inrealfft)-abs(realoutput))    %//plot Error Magnitude TigerSHARC vs MATLAB.
grid
max_error=log2(max(abs(inrealfft)-abs(realoutput))*2^15);
title('Error in Magnitude')
xlabel(['Max magnitude error:',num2str(max_error),' bits']);


figure
subplot(2,2,1);
plot(y,real(inrealfft),'r',y,outreal,'g')
grid
title('Real Part Comparison, TS in green')
subplot(2,2,2);
plot(y,real(inrealfft)-outreal)
grid
title('Error in Real')
subplot(2,2,3);
plot(y,imag(inrealfft),'r',y,outimag,'g')
grid
title('Imaginary Part Comparison, TS in green')
subplot(2,2,4);
plot(y,imag(inrealfft)-outimag)
grid
title('Error in Imaginary')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -