信号内插(零阶保持滤波器+插零)

1 信号内插0

% // 程序功能说明:
% // 1、用100M的系统钟产生10M的点频信号RtI(一个周期采10个点)
% // 2、对RtI进行2倍内插,一个点插1个0
% // 3、低通滤波器滤波,保留10M的信号

%% 结论:内插过滤波后,会使得信号的幅度降低。
%        如果内插的是0,那么内插2倍信号幅度变为原来的1/2%        理由:从能量守恒定理考虑

close all;
clear all;
clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%           参数定义
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Quantify_bit=16;   % 希尔伯特滤波器量化位数 16位
fs=100e6;          % 采样频率  以内插后的信号频率为准
COUNT=1000;
t=0:1/fs:(COUNT-1)/fs;
fc=10e6;
st=cos(2*pi*fc*t);  % 原始信号
fs_200M=2*fs;       % 三倍内插

figure(1)
subplot(211);plot(st);
title('原始信号');
subplot(212);
f=(0:COUNT-1)*fs/COUNT-fs/2;
plot(f/1e6,abs(fftshift(fft(st)))/length(st));
xlabel('频率/MHz');ylabel('幅度')
title('信号频谱');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               2倍 内插
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for p=1:2*COUNT
    if(mod(p,2)==1)
        st_inter(p)=st((p+1)/2);
    else
        st_inter(p)=0;
    end
end

figure(2)
subplot(211);
plot(st_inter);

L_inter=length(st_inter);
f=(0:L_inter-1)*fs_200M/L_inter-fs_200M/2;
subplot(212);
plot(f/1e6,abs(fftshift(fft(st_inter)))/L_inter);
xlabel('频率/MHz');ylabel('幅度')
title('内插后的信号');



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            低通滤波器
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%LOW_PASS Returns a discrete-time filter object.

% MATLAB Code
% Generated by MATLAB(R) 9.5 and Signal Processing Toolbox 8.1.
% Generated on: 26-Mar-2022 21:53:46

% FIR Window Lowpass filter designed using the FIR1 function.

% All frequency values are in MHz.
Fs = 200;  % Sampling Frequency

Fpass = 11;              % Passband Frequency
Fstop = 20;              % Stopband Frequency
Dpass = 0.057501127785;  % Passband Ripple
Dstop = 0.001;           % Stopband Attenuation
flag  = 'scale';         % Sampling Flag

% Calculate the order from the parameters using KAISERORD.
[N,Wn,BETA,TYPE] = kaiserord([Fpass Fstop]/(Fs/2), [1 0], [Dstop Dpass]);

% Calculate the coefficients using the FIR1 function.
b  = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag);

figure(3)
f=(0:length(b)-1)*Fs/(length(b))-Fs/2;
plot(f,abs(fftshift(fft(b))));
xlabel('频率/MHz');ylabel('幅度')
title('低通滤波器');

L=length(b);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%      导出滤波器的数据
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fid=fopen('low_pass.coe','w');  % 实部
[h_data]= coe_generate(fid,Quantify_bit,L,b);



y2=conv(b,st_inter);
y2_end=y2(round(L/2):1:end-round(L/2));
figure(4);
subplot(211);plot(y2_end);

L_y2_end=length(y2_end);
f=(0:L_y2_end-1)*fs_200M/L_y2_end-fs_200M/2;
subplot(212);
plot(f/1e6,abs(fftshift(fft(y2_end)))/L_y2_end);
xlabel('频率/MHz');ylabel('幅度')
title('内插后的信号过低通滤波器');

在这里插入图片描述

2信号内插输入信号(零阶保持滤波)

% // 程序功能说明:
% // 1、用100M的系统钟产生10M的点频信号RtI(一个周期采10个点)
% // 2、对RtI进行2倍内插,一个点插1个上一时刻的原来的输入信号
% // 3、低通滤波器滤波,保留10M的信号

%% 结论:内插过滤波后,会使得信号的幅度降低。
%        如果内插的是原来的输入信号,那么内插2倍,信号幅度不变。
%        理由:从能量守恒定理考虑

close all;
clear all;
clc;

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%           参数定义
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Quantify_bit=16;   % 希尔伯特滤波器量化位数 16位
fs=100e6;          % 采样频率  以内插后的信号频率为准
COUNT=1000;
t=0:1/fs:(COUNT-1)/fs;
fc=10e6;
st=cos(2*pi*fc*t);  % 原始信号
fs_200M=2*fs;       % 三倍内插

figure(1)
subplot(211);plot(st);
title('原始信号');
subplot(212);
f=(0:COUNT-1)*fs/COUNT-fs/2;
plot(f/1e6,abs(fftshift(fft(st)))/length(st));
xlabel('频率/MHz');ylabel('幅度')
title('信号频谱');

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%               2倍 内插
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
st1=[st;st];
st_inter=reshape(st1,[1 COUNT*2]);% 相当于零阶保持滤波器

figure(2)
subplot(211);
plot(st_inter);

L_inter=length(st_inter);
f=(0:L_inter-1)*fs_200M/L_inter-fs_200M/2;
subplot(212);
plot(f/1e6,abs(fftshift(fft(st_inter)))/L_inter);
xlabel('频率/MHz');ylabel('幅度')
title('内插后的信号');



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%            低通滤波器
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%LOW_PASS Returns a discrete-time filter object.

% MATLAB Code
% Generated by MATLAB(R) 9.5 and Signal Processing Toolbox 8.1.
% Generated on: 26-Mar-2022 21:53:46

% FIR Window Lowpass filter designed using the FIR1 function.

% All frequency values are in MHz.
Fs = 200;  % Sampling Frequency

Fpass = 11;              % Passband Frequency
Fstop = 20;              % Stopband Frequency
Dpass = 0.057501127785;  % Passband Ripple
Dstop = 0.001;           % Stopband Attenuation
flag  = 'scale';         % Sampling Flag

% Calculate the order from the parameters using KAISERORD.
[N,Wn,BETA,TYPE] = kaiserord([Fpass Fstop]/(Fs/2), [1 0], [Dstop Dpass]);

% Calculate the coefficients using the FIR1 function.
b  = fir1(N, Wn, TYPE, kaiser(N+1, BETA), flag);

figure(3)
f=(0:length(b)-1)*Fs/(length(b))-Fs/2;
plot(f,abs(fftshift(fft(b))));
xlabel('频率/MHz');ylabel('幅度')
title('低通滤波器');

L=length(b);


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%      导出滤波器的数据
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
fid=fopen('low_pass.coe','w');  % 实部
[h_data]= coe_generate(fid,Quantify_bit,L,b);



y2=conv(b,st_inter);
y2_end=y2(round(L/2):1:end-round(L/2));
figure(4);
subplot(211);plot(y2_end);

L_y2_end=length(y2_end);
f=(0:L_y2_end-1)*fs_200M/L_y2_end-fs_200M/2;
subplot(212);
plot(f/1e6,abs(fftshift(fft(y2_end)))/L_y2_end);
xlabel('频率/MHz');ylabel('幅度')
title('内插后的信号过低通滤波器');

在这里插入图片描述

  • 1
    点赞
  • 14
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值