用matlab实现一个100hz正弦波被400hz采样,再用一倍0内插进行滤波,看前后频谱变化?怎
%100hz正弦波被400hz采样,再用一倍0内插进行滤波,看前后频谱变化
f0 = 100;
fs = 400;
N = 1024; %采样点数
%画出信号本身(只画2个周期)
T2 = 2/f0;
t=0:0.0001:T2-0.0001; %精细画图,取步进0.001,即1Khz采样
x = sin(2*pi*f0.*t);
figure(1);set(gcf,'Color','w');
subplot(211);
plot(t,x); hold on;
%采样
t1 = (0:N-1)/fs;
x1 = sin(2*pi*f0.*t1);
%画出采样信号(只画两个周期)
L = floor(2/f0*fs);
stem(t1(1:L),x1(1:L),'r','MarkerFaceColor','r');
title('采样信号');
%1倍零插值
x2 = zeros(1,2*N);
for i=0:N-1
x2(2*i+1)=x1(i+1); %
end
subplot(212);
plot(t,x);hold on;
t2 = (0:2*N-2)/(2*fs); %因为插值,采样率增加一倍
%画出采样信号(只画两个周期)
L = L*2; %因为插值了,样本增加一倍
stem(t2(1:L),x2(1:L),'r','MarkerFaceColor','r');
title('插值信号');
%计算频谱并对比
figure(2);set(gcf,'Color','w');
%采样信号频谱
fx1 = fft(x1,N);
px1 = abs(fx1);
subplot(211);
f = fs/2*linspace(0,1,N/2+1);
plot(f,px1(1:N/2+1));
%插值信号频谱
fx2 = fft(x2,N*2);
px2 = abs(fx2);
f = fs*linspace(0,1,N+2);
subplot(212);
plot(f,px2(1:N+2));
都很好,不过还有滤波没有做吧,我就是滤波那里搞得很不好。。。先谢谢啦!!
滤波很简单啊(所以才没写)
直接用理想低通滤波器,把200Hz以上全部等于0即可.