?? fft_complex.m
字號:
%_______________________________________________________________________
% FFT_COMPLEX.M Matlab script to plot ADSP-TS201 FFT results
%
%_______________________________________________________________________
clear all;
close all;
%please introduce here the number X from the assembly program.
%Nothing else is to be done. X=2*number of complex points
N='1024';
Number_points=num2str(str2num(N)*2);
input_file=['inputs/input',Number_points,'.dat'];
output_file=['outputs/output_cplx_',N,'.dat'];
output_matlab_file=['outputs/output_cplx_',N,'_matlab.dat'];
%//load input file from generated random value.
fid = fopen(input_file, 'r');
[a, count] = fscanf (fid, '%f%c');
fclose(fid);
%I have to eliminate the comma that is written after each input number
for i=1:size(a)/2
input(i,1)=a(2*i-1);
end;
%//input is NOT complex, so the point of FFT must be halved.
N1=length(input)/2; %//get the length of input file and point for FFT.
FFT_point=N1
j=sqrt(-1);
for i=1:N1
inreal(i)=input(2*i-1);
inimag(i)=input(2*i);
end
incomplex=inreal+(inimag*j);
incplx=fft(incomplex,N1); %//FFT of input.
fin = fopen(output_matlab_file, 'wt');
for i=1:N1
fprintf(fin, '%g\n%g\n', real(incplx(1,i)), imag(incplx(1,i)));
end;
fclose(fin);
output=load (output_file); %//load file output of optimized FFT for TigerSHARC TS-101.
%//output of optimized FFT for TigerSHARC TS-101.
for k=1:N1
outreal(k)=output(2*k-1);
outimag(k)=output(2*k);
end
outcplx=outreal+(outimag*j);
y=0:1/N1:1-1/N1;
mlb=20*log10(abs(incplx));
%chip=20*log10(sqrt((outreal.*outreal)+(outimag.*outimag)));
chip=20*log10(abs(outcplx));
figure
subplot(2,2,1);
plot(y,abs(incomplex)) %//plot input data.
grid
title([num2str(FFT_point),' Complex Input data'])
%subplot(2,2,2);
%plot(y,outcplx,'r',y,incplx,'g') %//plot comparison of FFT TigerSHARC vs MATLAB.
%grid
%title(['Output of ',num2str(FFT_point),' point FFT, TS in green')
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(incplx),'r',y,abs(outcplx),'g') %//plot Magnitude comparison TigerSHARC vs MATLAB.
grid
title('Magnitude Comparison, TS in green')
subplot(2,2,4);
plot(y,abs(incplx)-(abs(outcplx))) %//plot Error Magnitude TigerSHARC vs MATLAB.
grid
title('Error in Magnitude')
figure
subplot(2,2,1);
plot(y,real(incplx),'r',y,outreal,'g')
grid
title('Real Part Comparison, TS in green')
subplot(2,2,2);
plot(y,real(incplx)-outreal)
grid
title('Error in Real')
subplot(2,2,3);
plot(y,imag(incplx),'r',y,outimag,'g')
grid
title('Imaginary Part Comparison, TS in green')
subplot(2,2,4);
plot(y,imag(incplx)-outimag)
grid
title('Error in Imaginary')
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -