📄 fft_real.m
字号:
%_______________________________________________________________________
% FFT_REAL.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
N='1024';
input_file=['inputs/input',N,'.dat'];
output_file=['outputs/output_real_',N,'.dat'];
output_matlab_file=['outputs/output_real_',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 wrtten after each input number
for i=1:size(a)/2
input(i,1)=a(2*i-1);
end;
%//input is NOT complex, so the points of FFT must be halved.
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/2
fprintf(fin, '%g\n%g\n', 2*real(infft(i,1)), 2*imag(infft(i,1)));
end;
fclose(fin);
inrealfft_in=infft(1:N1/2); %need only half points because of TS input.
for i=1:N1/2
inrealfft(1,i)=inrealfft_in(i,1); %//change the matrix format.
end
s=load (output_file); %//load file output of optimized FFT for TigerSHARC TS-101.
output=s/2; %//output of optimized FFT for TigerSHARC TS-101.
for k=1:N1/2
outreal(k)=output(2*k-1);
outimag(k)=output(2*k);
end
realoutput=complex(outreal, outimag);
x=0:1/N1:1-1/N1;
y=0:1/(N1/2):1-1/(N1/2);
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,input) %//plot input data.
grid
title([N,' Real Input data'])
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
title('Error in Magnitude')
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 + -