数字信号处理采样&内插

实验一、数字信号采样与重建

实验文档

1.信号降采样

decimate

decimate函数只能降低采样率,或者说只能实现信号的抽取。
比如:y = decimate(x,r)
x是样本信号,这里将输入信号x的采样率降低r倍,即在x的数据点中每r个点中,只保留一个点。

t = 0:.0003:1;  % Time vector

x = sin(2*pi*30*t) + sin(2*pi*60*t);

y = decimate(x,5)

subplot(1,2,1);

stem(x(1:120)), axis([0 120 -2 2])   % Original signal

title('Original Signal')

subplot(1,2,2);

stem(y(1:30))                    % Decimated signal

 title('Decimated Signal')

 

t=0:0.002:0.029;                      

x = sin(2*pi*30*t) + sin(2*pi*60*t);        

y = interp(x,10);                       

    subplot(211);

    stem(x);

    title('Original Signal');

    subplot(212);

    stem(y);

title('Interpolated Signal');

3.任意降采样

y=resample(x,p,q,n,beta)
x:待重采样信号;
p:目标采样率;
q:待重采样信号的采样率;
n:滤波器长度与n成正比,采用chebyshevIIR型低通滤波器的阶数,缺省值为10;
beta:设置低通滤波器使使用Kaiser窗的参数,缺省值为5;

Fs = 100;

    tx = linspace(0,1,21) + .015*rand(1,21);

    x = sin(2*pi*tx);

    [y, ty] = resample(x, tx, Fs);

    plot(tx,x,'--',ty,y,'o:')

    legend('original','resampled');

    xlabel('Time')

    axis tight

4 采样定理与频谱分析

Fs=10000;

tx = 0:0.0002:1;

a=50*sqrt(2)*pi;b=a;

x=exp(-a*tx).*sin(b*tx);

[y, ty] = resample(x, tx, Fs);

[h,w]=freqz(x);

[h1,w1]=freqz(y);

subplot(211);

plot(w(1:512),abs(h(1:512)));

subplot(212);

plot(w1(1:512),abs(h1(1:512)));

Fs=100;

tx = 0:0.0002:1;

a=50*sqrt(2)*pi;b=a;

x=exp(-a*tx).*sin(b*tx);

[y, ty] = resample(x, tx, Fs);

[h,w]=freqz(x);

[h1,w1]=freqz(y);

subplot(211);

plot(w(1:512),abs(h(1:512)));

subplot(212);

plot(w1(1:512),abs(h1(1:512)));

5 连续时间傅里叶变换与离散时间傅里叶变换

连续时间傅里叶变换

dt = 0.00005;                                                 

t = -0.005:dt:0.005;

A=100;a=50*sqrt(2)*pi;b=a;

     xa=exp(-a*t).*sin(b*t);                                      

%contunites_time fourier transform

Wmax = 2*pi* 2000;                                       

K = 500;                                                     

k = 0: 1: K;

W = k*Wmax/K;

Xa = xa * exp(-1i * t'*W)*dt;

Xa = real(Xa);

W = [-fliplr(W),W(2:501)];          

Xa = [fliplr(Xa),Xa(2:501)];          

subplot(2,1,1);

plot(t*10000,xa);grid

title('analog signal');

xlabel('t  (ms)');

ylabel('xa(t)');

subplot(2,1,2);

plot(W/(2*pi*1000),Xa*1000);grid

title('continues_time fourier transform');

xlabel('f   (Khz)');

ylabel('Xa(jw) * 1000');

离散时间傅里叶变换

dt = 0.00005;                            

t = -0.005:dt:0.005;  

A=100;a=50*sqrt(2)*pi;b=a;

xa=exp(-a*t).*sin(b*t);

ts = 0.0002;

n = -40:1:40;

x=exp(-a*n*ts).*sin(b*n*ts);

K = 500;

k = 0:1:K;

w = 2*pi*k/K;

X = x*exp(-1i *n'*w);

X= real(X);

w = [-fliplr(w),w(2:K+1)];

X = [fliplr(X),X(2:K+1)];                 

subplot(2,1,1);    

plot(t*1000,xa);

title('discrete signal');

xlabel('t in msec');

ylabel('x(n)');

hold on

stem(n*ts*1000,x);  

gtext('ts = 0.2msec'); hold off

subplot(2,1,2);

plot(w/pi, X);

title('discrete_time fourier transform');

xlabel('frequence in pi unit');

ylabel('X(w)');

6.信号采样与重构

 clear all;

wm=1;

wc=wm;

Ts=pi/wm;

ws=2*pi/Ts;

n=-100:100;

nTs=n*Ts;

f=sinc(nTs/pi);

t=-20:0.005:20;

fa=f*Ts*wc/pi*sinc((wc/pi)*(ones(length(nTs),1)*t-nTs'*ones(1,length(t))));

error=abs(fa-sinc(t/pi));

t1=-15:0.5:15;

f1=sinc(t1/pi);

subplot(3,1,1);

stem(t1,f1);

xlabel('kTs'); ylabel('f(kTs)');

title('sa(t)=sinc(t/pi)临界采样信号');

subplot(3,1,2);

plot(t,fa);

xlabel('t'); ylabel('fa(t)');

title('sa(t)=sinc(t/pi)的临界采样信号重构sa(t)');

grid on;

subplot(3,1,3);

plot(t,error);

xlabel('t'); ylabel('error(t)');

title('临界采样信号与原信号的误差error(t)');

 

clear all;

wm=1;

wc=wm;

Ts=pi/wm;

ws=4*2*pi/Ts;

n=-100:100;

nTs=n*Ts;

f=sinc(nTs/pi);

t=-20:0.005:20;

fa=f*Ts*wc/pi*sinc((wc/pi)*(ones(length(nTs),1)*t-nTs'*ones(1,length(t))));

error=abs(fa-sinc(t/pi));

t1=-15:0.5:15;

f1=sinc(t1/pi);

subplot(3,1,1);

stem(t1,f1);

xlabel('kTs'); ylabel('f(kTs)');

title('临界采样信号与原信号的误差error(t)');

subplot(3,1,2);

plot(t,fa);

xlabel('t'); ylabel('fa(t)');

title('sa(t)=sinc(t/pi)的过采样信号重构sa(t)');

grid on;

subplot(3,1,3);

plot(t,error);

xlabel('t'); ylabel('error(t)');

title('过采样信号与原信号的误差error(t)');

clear all;

wm=1;

wc=wm;

Ts=3*pi/wm;

ws=pi/Ts;

n=-100:100;

nTs=n*Ts;

f=sinc(nTs/pi);

t=-20:0.005:20;

fa=f*Ts*wc/pi*sinc((wc/pi)*(ones(length(nTs),1)*t-nTs'*ones(1,length(t))));

error=abs(fa-sinc(t/pi));

t1=-15:0.5:15;

f1=sinc(t1/pi);

subplot(3,1,1);

stem(t1,f1);

xlabel('kTs'); ylabel('f(kTs)');

title('sa(t)=sinc(t/pi)欠采样信号');

subplot(3,1,2);

plot(t,fa);

xlabel('t'); ylabel('fa(t)');

title('sa(t)=sinc(t/pi)的欠采样信号重构sa(t)');

grid on;

subplot(3,1,3);

plot(t,error);

xlabel('t'); ylabel('error(t)');

title('欠采样信号与原信号的误差error(t)');

 

 

 

 

 

 

 

 

 

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值