从时域到频率的输入和系数,将它们加在一起并返回到时域

Input & Coefficients from time domain to frequency, add them together and back to time domain

我目前正在学习计算机科学,我有一个任务要解决我的实验室项目。我必须将输入的信号和系数从时域传输到频域,将它们加在一起并传输回时域。我的结果必须与过滤函数输出相匹配。但是我似乎找不到这里做错了什么。当我通过 conj 函数添加两个频率时,我认为它有问题。不幸的是,我的老师和我的实验室主管都没有兴趣实际教授任何东西,所以我必须自己寻找答案。希望大家帮帮忙。

clc
clear
B = [0.2];
A = [1,-0.5];
xt = ones(1,20);
xt = padarray(xt,[0,100])
A1 = 1;
A2 = 1;
f1 = 1;
f2 = 25;
fs = 1000;

xd = fft(xt);
wd = freqz(B,A,length(xt));
y = filter(B,A,xt);
yd = conj((wd)').*xd;

yt = real(ifft(yd));

subplot(4,2,1);
plot(xt)
title('Input signal')

subplot(4,2,2);
plot(abs(xd))
title('Input in frequency domain')

subplot(4,2,4);
plot(abs(wd))
title('Coefficients in frequency domain')

subplot(4,2,7);
plot(y)
title('Output using FILTER function')

subplot(4,2,6);
plot(yd)
title('Adding input with coefficients in frequency domain')

subplot(4,2,8);
plot(yt)
title('Back to time domain using IFFT')

matlab 函数 freqz() 可能有点误导。系数的 "FFT" 域需要以不同方式生成。用以下代码替换你的东西,它应该给你你想要的东西:

xt = xt.';
xd = fft(xt);
wd = freqz(B,A,length(xt),'whole');
y = filter(B,A,xt);
yd = wd.*xd;
yt = ifft(yd);

figure
plot(abs(xd))
hold on
plot(abs(wd))

figure
plot(y,'.k','markersize',20)
hold on
plot(yt,'k')
hold off

此外,关于具有复数向量的 ' 运算符的注释:除非您使用 .' 运算符(例如,x = x.'),否则它会在取复数时转置向量共轭,即 (1+1i).' = (1+1i)(1+1i)' = (1-1i)