我试图用MATLAB中的sinc函数在采样频率800e6处重建信号cos(2*pi*300 e6)。当我输入下面的代码时,我会得到一些非常嘈杂的东西--而不是我想要的东西。我做错了什么?提前谢谢你!
代码:
F1 = 300e6;
Fs = 800e6;
tmin = 0;
tmax = 10/F1;
t = tmin:1e-12:tmax;
x1 = cos(2*pi*F1*t);
Ts = 1/Fs;
ts = tmin:Ts:tmax;
x1resampled = cos(2*pi*F1*ts);
x1reconstructed = zeros(1,length(t)); %preallocating for speed
samples = length(ts);
for i = 1:1:length(t)
for n = 1:1:samples
x1reconstructed(i) = sum(x1resampled(n)*sinc(pi*(t(i)-n*Ts)/Ts));
end
end
figure(1)
subplot(2,1,1)
plot(t,x1)
hold on
stem(ts,x1resampled)
subplot(2,1,2)
plot(t,x1reconstructed)发布于 2018-01-28 05:45:06
代码有两个问题:
sinc在MATLAB中使用归一化的正弦函数。这意味着您不必将参数乘以pi。还记得重建公式需要归一化的sinc函数,因此在函数的参数中不存在pi的乘法。因此,您只需更改for循环中的代码:
F1 = 300e6;
Fs = 800e6;
tmin = 0;
tmax = 10/F1;
t = tmin:1e-12:tmax;
x1 = cos(2*pi*F1*t);
Ts = 1/Fs;
ts = tmin:Ts:tmax;
x1resampled = cos(2*pi*F1*ts);
x1reconstructed = zeros(1,length(t)); %preallocating for speed
samples = length(ts);
for i = 1:1:length(t)
for n = 1:1:samples
x1reconstructed(i) = x1reconstructed(i) + x1resampled(n)*sinc((t(i)-n*Ts)/Ts); %%% CHANGE
end
end
figure(1)
subplot(2,1,1)
plot(t,x1)
hold on
stem(ts,x1resampled)
subplot(2,1,2)
plot(t,x1reconstructed)我现在得到了这个情节:

为了提高效率,一定要使用sum函数,但要对所有示例都这样做。因此,您的for循环现在应该是:
for i = 1:1:length(t)
x1reconstructed(i) = sum(x1resampled .* sinc((t(i) - (1:samples)*Ts) ./ Ts));
end发布于 2018-01-28 07:12:17
您可以使用离散傅里叶变换(DFT)完成同样的事情,但效率更高:
F1 = 300e6;
Fs = 800e6;
tmin = 0;
tmax = 10/F1;
t = tmin:1e-12:tmax;
x1 = cos(2*pi*F1*t);
Ts = 1/Fs;
ts = tmin:Ts:tmax;
x1resampled = cos(2*pi*F1*ts);
x1resampledDFT = fftshift(fft(x1resampled));
n = (length(x1)-length(x1resampledDFT))/2;
x1reconstructedDFT = [zeros(1,ceil(n)),x1resampledDFT,zeros(1,floor(n))];
x1reconstructed = ifft(ifftshift(x1reconstructedDFT));
x1reconstructed = x1reconstructed / length(x1resampled) * length(x1reconstructed);
figure(1)
subplot(2,1,1)
plot(t,x1)
hold on
stem(ts,x1resampled)
subplot(2,1,2)
plot(t,x1reconstructed)

这里发生的事情是,我将DFT (使用fft有效地计算)填充到所需大小的零。然后,逆变换产生使用sinc插值器进行插值的信号。为了保持信号强度,需要一定的归一化。你看到雷林回答的任何不同,都是因为DFT的周期性:基本上,sinc函数在离开右边的信号域时,会从左边返回;右边的数据会影响到图的左边的结果,反之亦然。
要了解有关使用傅里叶变换进行插值的更多信息,请参见这篇博客文章。
https://stackoverflow.com/questions/48482987
复制相似问题