function diff_err_energy = difff(data0, data1, Title0, Title1, option)
% Plots two complex functions, their difference and ratio; plus a few
% other stats like max min of the difference and ratio, and SNR.
%
% difff(datain, dataout);
% difff(datain, dataout, Title0, Title1);
% difff(datain, dataout, Title0, Title1, 1); % real data only
% DiffErrEnergy = difff(data0, data1, Title0, Title1)
% data0, data1 Complex data vectors
% Title0, Title1 Character string names used in graph titles for
% the two data vectors.
% option 1 Compare only *real* portions of input data
% Engineer: Amey Kulkarni
% Module Name: difff
% Project Name: Fast Fourier Transform (16-point)
% 06/03/11 Inverted dB calculation ratio so output is positive (SNR)
% 01/06/20 Added optional diff_err_energy output
% 01/04/11 Added option=1 for real-only input data
% 01/01/02 Fixed separated mean part so it doesn't give 'Rank deficient' error
% 00/06/07 Added Title0 and Title1 arguments.
% 00/05/23 Added check for log(0)
% Sped up calculation of Energy (oops, should've done it before)
% Sped up plotting of ratio (oops, should've done it before)
% 00/05/19 Added mean of ratio; needs work for when data1 == 0
% 00/04/06 Added energy, SNR
% 00/01/28 Added plot of data0-data1
% I can't get rid of that crazy "Warning:...axis limit..." message
% that shows up sometimes! axis([...]) arguments are fine! Grr.
% 99/12/17 Cleaned up ratio stuff when undefined
% 99/12/10 Written
%--- Check inputs
if (length(data0) ~= length(data1))
fprintf('Warning: difff(): data0 and data1 are different lengths\n');
end
% Set default titles if needed
if (nargin == 2)
Title0 = 'data 0';
Title1 = 'data 1';
end
if (nargin == 3)
Title1 = 'data 1';
end
if (nargin == 5)
if (option ~= 1)
fprintf('Error: difff(): Illegal option value\n');
return;
end
else
option = 0;
end
%--- Init
% Resize inputs if they're of different lengths
len0 = length(data0);
len1 = length(data1);
if len0 == len1
len = len0;
else
len = min(length(data0), length(data1));
temp = data0; clear data0; data0 = temp(1:len);
temp = data1; clear data1; data1 = temp(1:len);
clear temp;
end
min_r = +inf;
min_i = +inf;
max_r = -inf;
max_i = -inf;
clf;
%--- Calculate stuff
errR = real(data0)-real(data1);
errI = imag(data0)-imag(data1);
err = data0-data1;
if (option ~= 1) % complex data
Energy_data0 = sum(abs(data0.^2));
Energy_diff = sum(abs(err.^2));
else % real-only data
Energy_data0 = sum(abs(real(data0).^2));
Energy_diff = sum(abs(real(err).^2));
end
%--- plot data0
subplot(4,1,1);
plot(0:len-1, real(data0), 'r'); hold on;
if (option ~= 1)
plot(0:len-1, imag(data0), 'b'); end
axis tight; grid on; title(Title0);
%--- plot data1
subplot(4,1,2);
plot(0:len-1, real(data1), 'r'); hold on;
if (option ~= 1)
plot(0:len-1, imag(data1), 'b'); end
axis tight; grid on; title(Title1);
%--- plot difference
subplot(4,1,3);
plot(0:len-1, errR, 'rx'); hold on;
if (option ~= 1)
plot(0:len-1, errI, 'bo'); end
axis tight; grid on; title(strcat('(', Title0, ') - (', Title1, ')'));
%--- plot ratio
subplot(4,1,4);
%for j=1:len,
% if real(data1(j)) ~= 0 % Real part
% ratio = real(data0(j))/real(data1(j));
% plot(j-1, ratio, 'rx');
% if ratio < min_r min_r = ratio; end
% if ratio > max_r max_r = ratio; end
% if j == 1 hold on; end
% end
% if imag(data1(j)) ~= 0 % Imag part
% ratio = imag(data0(j))/imag(data1(j));
% plot(j-1, ratio, 'bo');
% if ratio < min_i min_i = ratio; end
% if ratio > max_i max_i = ratio; end
% if j == 1 hold on; end
% end
%end
% Improved vectorized method
denom = real(data1);
temp = find(denom == 0);
denom(temp) = 1; % temporary to do division
ratio = real(data0)./denom;
ratio(temp) = Inf; % Inf when ratio==infinity
plot(0:len-1, ratio, 'rx');
hold on;
if (option ~= 1)
denom = imag(data1);
temp = find(denom == 0);
denom(temp) = 1; % temporary to do division
ratio = imag(data0)./denom;
ratio(temp) = Inf; % Inf when ratio==infinity
plot(0:len-1, ratio, 'bo');
end
%axis([0 len-1 min(min_r, min_i)/1.05 max(max_r, max_i)*1.05]);
axis tight;
grid on;
title(strcat('(', Title0, ') \div (', Title1, ...
'); Points not plotted if ratio is \infty'));
%----- Print some stats
fprintf('max(data0-data1) = ');
fprintf(' %+f', max(real(data0)-real(data1)));
fprintf(' %+fi = ', max(imag(data0)-imag(data1)));
fprintf(' %+g', max(real(data0)-real(data1)));
fprintf(' %+gi\n', max(imag(data0)-imag(data1)));
fprintf('min(data0-data1) = ');
fprintf(' %+f', min(real(data0)-real(data1)));
fprintf(' %+fi = ', min(imag(data0)-imag(data1)));
fprintf(' %+g', min(real(data0)-real(data1)));
fprintf(' %+gi\n', min(imag(data0)-imag(data1)));
fprintf('max(data0/data1) = %+f', max_r);
fprintf(' %+fi\n', max_i);
fprintf('min(data0/data1) = %+f', min_r);
fprintf(' %+fi\n', min_i);
numer = real(data0);
denom = real(data1);
temp = find(denom == 0);
denom(temp) = 1; % temporary to do division
ratio = numer ./ denom;
ratio(temp) = 0; % introduces error, should remove sample
fprintf('approx separated mean(data0/data1) = %+f', mean(ratio));
numer = imag(data0);
denom = imag(data1);
temp = find(denom == 0);
denom(temp) = 1; % temporary to do division
ratio = numer ./ denom;
ratio(temp) = 0; % introduces error, should remove sample
fprintf('+ %+fi\n', mean(ratio));
%----- Print more stats: energy, SNR
fprintf('Energy_data0 = %f\n', Energy_data0);
fprintf('Energy_diff = %f\n', Energy_diff);
if Energy_diff ~= 0
fprintf('Energy_data0/Energy_diff = %f', Energy_data0/Energy_diff);
fprintf(' = %fdB', 10*log10(Energy_data0/Energy_diff));
fprintf('\n');
end
%----- Return
if (nargout == 1)
diff_err_energy = Energy_diff;
end
没有合适的资源?快使用搜索试试~ 我知道了~
毕业设计&课设-开发了16点FFT,以便对MATLAB函数的FFT进行精确建模。该模块使用verilog testbe.zip
共30个文件
m:16个
v:8个
png:4个
需积分: 0 0 下载量 196 浏览量
2024-01-08
23:06:05
上传
评论
收藏 45KB ZIP 举报
温馨提示
matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随时与博主沟通,第一时间进行解答! matlab算法,工具源码,适合毕业设计、课程设计作业,所有源码均经过严格测试,可以直接运行,可以放心下载使用。有任何使用问题欢迎随
资源推荐
资源详情
资源评论
收起资源包目录
毕业设计&课设-开发了16点FFT,以便对MATLAB函数的FFT进行精确建模。该模块使用verilog testbe.zip (30个子文件)
matlab_code
matlab
result_iii.png 6KB
fft.m 2KB
check_result_ii.m 963B
data_out.m 445B
UART.m 2KB
calculate_w.m 615B
difff.m 6KB
result_iv.png 9KB
check_result_iii.m 969B
check_result_i.m 919B
result_i.png 5KB
test_hw.m 1KB
check_results.m 814B
data_in.m 406B
check_result_iv.m 1KB
send_samples.m 1KB
saturate.m 512B
result_ii.png 8KB
test_uart.m 388B
ffthw.m 2KB
sim
butterfly_tb.v 3KB
.fft_top_tb.v.un~ 681B
fft_top_tb.v 4KB
fft_top_tb.v~ 4KB
rtl
read_addr_lut.v 5KB
mem_32x16.v 2KB
fft_ctrl_sm.v 9KB
fft_top.v 3KB
butterfly.v 5KB
w_lut.v 777B
共 30 条
- 1
资源评论
白话机器学习
- 粉丝: 1w+
- 资源: 7671
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- C#ASP.NET学生成绩管理系统源码 学生信息管理系统源码数据库 SQL2008源码类型 WebForm
- 时间序列-白银-30分钟数据
- 基于HTML5+CSS3+JavaScript 实现的移动Web商城前端UI源码课程源码
- 时间序列-白银-5分钟数据
- CAD/CASS缝隙自动修复插件(仅含安装包,需另行激活)
- 基于python + Mask R-CNN的交通标志识别课程设计
- iTunes9.2.1.dmg
- C#通用固定资产管理系统源码带二维码数据库 SQL2008源码类型 WebForm
- Matlab 建立了并具有数字调压功能的空间矢量脉宽调制SVPWM逆变器仿真
- 毕业设计-毕业设计&课设-推荐系统项目:含协同过滤、矩阵分解等算法及相关代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功