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



我目前正在学习计算机科学,我的实验项目有一个任务需要解决。我必须传输输入信号&系数从时域到频域,加在一起,再传回时域。我的结果必须匹配过滤函数输出。然而,我似乎找不到我在这里做错了什么。当我通过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)

最新更新