%% 学习目标:改变信号的采样率
%% 改变信号的采样率
clear all;
close all;
fs1=200; %采样频率为200HZ
t1=1/fs1:1/fs1:1; %采样频率为200HZ
x=sin(5*pi*t1); %正弦信号的波形
y=resample(x,2,5); %对信号X进行重新采样,变成原来的2/5
fs2=ceil(length(x)*2/5);
t2=1/fs2:1/fs2:1;
figure;
subplot(121);
stem(t1,x);
title('采样率为200Hz');
subplot(122);
stem(t2,y);
title('采样率为80Hz');
set(gcf,'position',[200,200,800,300]);
%%大仙QQ:1960009019
%%在线教育微信公众号:大仙一品堂
%%大鱼号:在线教育大仙一品堂
%%一点资讯号:大仙一品堂
%% 降低信号的采样率
clear all;
close all;
x1=1:30
y1=downsample(x1,4) %初始相位为0,降低为1/4的采样率
y2=downsample(x1,4,2) %初始相位为2
x2=[1:3;4:6;7:9] %矩阵的话是对每一列降低采样率
y3=downsample(x2,2)
%% 通过低通滤波来降低信号的采样率
clear all;
close all;
fs=1e4; % 原来的采样率为10KHZ
t=0:1/fs:1;
x=sin(2*pi*30*t)+sin(2*pi*60*t);
y=decimate(x,5); %将采样率降低5倍
figure;
subplot(121);
stem(x(1:200));
subplot(122);
stem(y(1:50));
set(gca,'xlim',[1,40]);
set(gcf,'position',[200,200,800,300]);
%% 提高信号的采样率
clear all;
close all;
x1=1:5
y1=upsample(x1,3) %3倍,插入0
y2=upsample(x1,3,2) %相位,两个0开始
%% 用过低通滤波器来提高信号的采样率
clear all;
close all;
fs=1e3; %1KHZ
t=0:1/fs:1;
x=sin(3*pi*50*t)+sin(6*pi*40*t); %正弦信号的叠加
y=interp(x,4); %提高4倍
figure;
subplot(121);
stem(x(1:50));
subplot(122);
stem(y(1:200));
set(gca,'xlim',[1,200]);
set(gcf,'position',[200,200,800,300]);