OpenCores
URL https://opencores.org/ocsvn/versatile_fft/versatile_fft/trunk

Subversion Repositories versatile_fft

[/] [versatile_fft/] [trunk/] [multiple_units/] [test_fft.m] - Blame information for rev 3

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 wzab
% Modify the length of the FFT in the line below
2
log2fftlen = 4;
3
% If you modify the number of bits used to represent
4
% real and imaginary part of the complex number,
5
% you should also modify the ICPX_WIDTH constant
6
% in the icpx_pkg.vhd file
7
icpx_width = 16;
8
% Do not modify below
9
% Write the package defining length of the FFT
10
fo=fopen("src/fft_len.vhd","w");
11
fprintf(fo,"package fft_len is\n");
12
fprintf(fo,"constant LOG2_FFT_LEN : integer := %d;\n",log2fftlen);
13
fprintf(fo,"constant FFT_LEN      : integer := 2 ** LOG2_FFT_LEN;\n");
14
fprintf(fo,"constant ICPX_WIDTH : integer := %d;\n",icpx_width);
15
fprintf(fo,"end fft_len;\n");
16
fclose(fo)
17
fftlen=2 ** log2fftlen;
18
%Generate the data. Now it is only a noise, but you
19
%can generate something with periodic components
20
%It is important, that values fit in range of representation
21
%(-2,2) for standard implementation.
22
%May be changed if you redefine our icpx_number format
23
%To check that calculation of spectrum for overlapping windows
24
%works correctly, we generate a longer data stream...
25
len_of_data=fftlen*5
26
re=3*rand(1,len_of_data)-1.5;
27
im=3*rand(1,len_of_data)-1.5;
28
fo=fopen("data_in.txt","w");
29
for i=1:len_of_data
30
   fprintf(fo,"%g %g\n",re(i),im(i));
31
end
32
fclose(fo)
33
%Create the Hann window.
34
%Remember, that you must use the same window function
35
%in your VHDL code!
36
x=0:(fftlen-1);
37
hann=0.5*(1-cos(2*pi*x/(fftlen-1)));
38
%Now we calculate the FFT in octave
39
scale = 2 ** (icpx_width-2);
40
fo=fopen("data_oct.txt","w");
41
for i=1:(fftlen/2):(len_of_data-fftlen)
42
   x=i:(i+fftlen-1);
43
   di = (re(x)+j*im(x))*scale/fftlen;
44
   fr = fft(di.*hann);
45
%   fr = fft(di);
46
   fprintf(fo,"FFT RESULT BEGIN\n")
47
   for k=1:fftlen
48
     fprintf(fo,"%d %d\n",floor(real(fr(k))),floor(imag(fr(k))));
49
   end
50
   fprintf(fo,"FFT RESULT END\n")
51
end
52
fclose(fo)
53
%Run the simulation
54
system("make clean; make")
55
%Compare results calculated in octave and in our IP core
56
system("vim -d data_oct.txt data_out.txt")
57
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.