1 信号内插0
%
%
%
%
%% 结论:内插过滤波后,会使得信号的幅度降低。
% 如果内插的是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信号内插输入信号(零阶保持滤波)
%
%
%
%
%% 结论:内插过滤波后,会使得信号的幅度降低。
% 如果内插的是原来的输入信号,那么内插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('内插后的信号过低通滤波器');
|