信号的抽取与插值MATLAB(含代码)

1.例题

 2.代码

clear
f1= 12; % fs/f的值
n=-f1:0.3:f1;
x=cos(2*pi*(1/f1)*n);  %x(n)

%作L=2倍的插值
L=2;
[y1,hn]=interp(x,L,4,0.25);%实现信号的插值
H=fft(hn); %求用于插值的低通滤波器的幅频特性
H=fftshift(H);%将零频分量移动到数组中心
length=length(H);
H=H(length/2:length);
N=ceil(length/2);
a=linspace(0,0.5,N);%频谱横轴
 
%求用于抽取和抽样率转化的低通滤波器的幅频特性
f=[0 0.6 0.7 1];
A=[1 1  0 0];
weigh=[1 10];   
b=remez(32,f,A,weigh);%设计切比雪夫最佳一致逼近FIR滤波器
[h,w]=freqz(b,1,256,1);%求频率响应
h1=abs(h);h1=20*log10(h1);

M=3;
y2=decimate(x,M,31,'FIR');%作M=3倍的抽取
y3=resample(x,L,M);%作L/M=2/3倍的抽样率转换

%绘出相关波形
figure(1)
subplot(221);stem(x,'.');
title('原始信号x(n)');grid on;
subplot(222);stem(hn,'.');
title('用于插值的低通滤波器的单位抽样响应');grid on; 
subplot(223);stem(y1,'.');
title('作L=2倍的插值后的信号');grid on;
subplot(224);plot(a,abs(H));
title('用于插值的低通滤波器的幅频特性');grid on;
figure(2)
subplot(221);stem(y2,'.');
title('作M=3倍的抽取后的信号');grid on;
subplot(222);stem(b,'.');
title('用于抽取和抽样率转化的低通滤波器的单位抽样响应');grid on;
subplot(223);stem(y3,'.');
title('作L/M=2/3倍的抽样率转换后的信号');grid on;
subplot(224);plot(w,h1);
title('用于抽取和抽样率转化的低通滤波器的幅频特性');grid on;

3.运行结果

猜你喜欢

转载自blog.csdn.net/qq_46035929/article/details/130681955