clear all; close all; N=256; 进行256点FFT t = 0:0.001:0.6; 采样频率1Khz x = sin(2*pi*50*t)+sin(2*pi*120*t); 原始信号包含50hz和120hz两种信号 x=x/2; 进行归一化处理 subplot(3,1,1); plot(1000*t,x); title('原始数据') 0 v, t* w$ t# d* z; F3 ^8 G
y= (x + 2 * rand(size(t)) -1)/2; 增加噪声信号,幅值正负1,并归一化处理 subplot(3,1,2); plot(1000*t,y); title('增加噪声后的数据') " B8 _/ {. {( p6 J; o
y2=round(y*2^15); 对数据取整,并进行16bit量化 fid=fopen('Data_input.txt','w+'); 把原始数据存入文件Data_input.txt fprintf(fid,'%g\r\n',y2); fclose(fid); * y, ~) u( R+ S& O
[Y, exp_out]= fft256_model(y2(1:256),N,0); 调用fft256_model
2 F: h+ g% i1 E+ u2 Q把转换后的数据分别存入fft_real_output.txt和fft_imag_output.txt fid=fopen('fft_real_output.txt','w+'); fprintf(fid,'%g\r\n',real(Y)); fclose(fid);
- _' g! Z" N1 U9 pfid=fopen('fft_imag_output.txt','w+'); fprintf(fid,'%g\r\n',imag(Y)); fclose(fid); ; l# @9 b9 d! l# J5 c
Pyy = Y.* conj(Y) ; f = 1000*(0:128)/256; subplot(3,1,3); plot(f,Pyy(1:129)) title('Quantus中IPcore函数转换的结果') |