[Matlab-4]信号的采样与恢复(采样定理)

采样定理(Nyquist Sampling Theorem)

虽然对陶哲轩的压缩感知也非常感兴趣,但是,我们先来提一嘴采样定理。
在这里插入图片描述
在这里插入图片描述
从这个图很容易看到,如果ws不是wb的至少两倍大,那么就会造成信号损失
在这里插入图片描述

移动平均滤波器(Moving-average filter)

在这里插入图片描述
这里给一个 windowSize=5的例子

% signal with noise
clf;clear;
ds = 0.1;
Fs = 1/ds;
t = -pi:ds:pi;
x = sin(t)+0.25*randn(size(t));
N = length(x);
% set the filter
windowSize = 5;
b = (1/windowSize)*ones(1,windowSize);
a = 1;
% show the result in time domain
y = filter(b,a,x);
subplot(2,2,[1 3]);
plot(t,x); hold on;
plot(t,y); legend('Input Data','Filtered Data');
xlabel('t(s)');ylabel("x(t)");title('Time Domain')
% show the result in frequency domain
f = (-floor(N/2):floor(N/2))*Fs/N;
X = fftshift(fft(x))/N;
subplot(2,2,2); plot(f,abs(X)); axis([-4 4 0 0.6])
xlabel('f(Hz)');ylabel('Amplitude');title('Input signal');
Y = fftshift(fft(y))/N;
subplot(2,2,4); plot(f,abs(Y));axis([-4 4 0 0.6])
xlabel('f(Hz)');ylabel('Amplitude');title('Filted signal');

输出如下
在这里插入图片描述

巴特沃斯滤波器(Butterworth filter)

在这里插入图片描述

% signal with noisy
% signal with noisy
clf; clear;
ds = 0.1;
fs = 1/ds;
t = -pi:ds:pi-ds;
x = sin(t)+0.25*randn(size(t));
fc = 0.5; % cutoff frequency
% set the filter
[b,a] = butter(4,fc/(fs/2));
[H w] = freqz(b,a);
plot(w/pi*fs/2,abs(H)); % the unit of the horizontal axis is *pi
rad/sample
xlim([0 1]);grid minor;title('Amplitude Response');
xlabel('Frequency (Hz)'); ylabel('Amplitude');
% show the result in time domain
y = filter(b,a,x);
subplot
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值