当前位置:
文档之家› 基于matlab的信号处理实例
基于matlab的信号处理实例
2
X1=1/2.*[x1,x];%求 x 的偶部 Y1=1/2.*[y1,y];%求 y 的偶部 Z1=1/2.*[z1,z];%求 z 的偶部 figure(2) subplot(3,1,1); plot(t,X1,'r');xlabel('t'),ylabel('Evex[n]'); title('3D 信号的偶信号'); subplot(3,1,2); plot(t,Y1,'g');xlabel('t'),ylabel('Evey[n]'); subplot(3,1,3); plot(t,Z1,'b');xlabel('t'),ylabel('Evez[n]'); X2=1/2.*[-x1,x];%求 x 的奇部 Y2=1/2.*[-y1,y];%求 y 的奇部 Z2=1/2.*[-z1,z];%求 z 的奇部 figure(3) subplot(3,1,1); plot(t,X2,'r');xlabel('t'),ylabel('Oddx[n]'); title('3D 信号的奇信号'); subplot(3,1,2) plot(t,Y2,'g');xlabel('t'),ylabel('Oddy[n]'); subplot(3,1,3); plot(t,Z2,'b');xlabel('t'),ylabel('Oddz[n]'); a1=X1+X2;%x 的奇部与偶部之和 a2=Y1+Y2;%y 的奇部与偶部之和 a3=Z1+Z2;%z 的奇部与偶部之和 figure(4) subplot(3,1,1); plot(t,a1,'r');xlabel('t'),ylabel('sumx[n]'); title('奇信号与偶信号的和信号'); subplot(3,1,2) plot(t,a2,'g');xlabel('t'),ylabel('sumy[n]'); subplot(3,1,3); plot(t,a3,'b');xlabel('t'),ylabel('sumz[n]'); s1=X1-X2;%x 的奇部与偶部之差 s2=Y1-Y2;%y 的奇部与偶部之差 s3=Z1-Z2;%z 的奇部与偶部之差 figure(5) subplot(3,1,1); plot(t,s1,'r');xlabel('t'),ylabel('decx[n]'); title('奇信号与偶信号的差信号'); subplot(3,1,2) plot(t,s2,'g');xlabel('t'),ylabel('decy[n]'); subplot(3,1,3); plot(t,s3,'b');xlabel('t'),ylabel('decz[n]');
y[n]
1
M 1
x[n k ]
M k 0
6
实验代码 3:the_filter.m
function [h]=the_filter(m)%画出 M 点滑动平均滤波器的波形
a=(1/m).*ones(1,m);%x 的系数
b=[1,0,0];
%y 的系数
h=impz(a,b,20); %求系统的单位冲激响应
函数调用 2:oddandeven('C:\Users\admin\Desktop\基于 matlab 的信号处理实例
\run 100m_TROUSERS POCKET_1_陈佳_1.txt')
实验结果 2:
3D信 号 的 偶 信 号 100
Evex[n]
50
0
-4000 -3000 -2000 -1000
500
1000
1500
2000
2500
3000
3500
n
500
1000
1500
2000
2500
3000
3500
n
500
1000
1500
2000
2500
3000
3500
n
z
2. 将读出的 3D 加速度信号分解为偶序列及奇序列,分别绘出波形;
绘出偶序列及奇序列的和信号、差信号及积信号的波形。
实验代码 2:oddandeven.m
x(i)=a(k); %将 a 中的第一列数据赋给 x y(i)=a(k+1); %将 a 中的第二列数据赋给 y z(i)=a(k+2); %将 a 中的第三列数据赋给 z k=k+3; end figure(1) subplot(3,1,1); plot(x,'r'),xlabel('n'),ylabel('x'); title('读取给定的 3D 加速度信号文件并绘出信号波形'); subplot(3,1,2); plot(y,'g'),xlabel('n'),ylabel('y'); subplot(3,1,3); plot(z,'b'),xlabel('n'),ylabel('z');
Oddz[n]
3D信 号 的 奇 信 号 100
0
-100
-4000 -3000 -2000 -1000
0
1000 2000 3000 4000
t
200
0
-200
-4000 -3000 -2000 -1000
0
1000 2000 3000
-4000 -3000 -2000 -1000
0
1000 2000 3000 4000
t
200
Evey[n]
100
0
-4000 -3000 -2000 -1000
0
1000 2000 3000 4000
t
200
Evez[n]
100
0
-4000 -3000 -2000 -1000
0
1000 2000 3000 4000
t
4
Oddx[n]
Oddy[n]
x(i)=a(k); %将 a 中的第一列数据赋给 x y(i)=a(k+1); %将 a 中的第二列数据赋给 y z(i)=a(k+2); %将 a 中的第三列数据赋给 z k=k+3; end x1=fliplr(x);%将 x 进行反转 y1=fliplr(y);%将 y 进行反转 z1=fliplr(z);%将 z 进行反转 t=[-len:-1 1:len];%给出横坐标的范围,使之匹配
figure(7)
stem(h,'y','filled');
%将单位冲激响应画出
xlabel('n'),ylabel('h[n]');
title('M 点的滑动平均滤波器的单位冲激响应图');
函数调用 3.1:the_filter(4)
实验结果 3.1:
M点 的 滑 动 平 均 滤 波 器 的 单 位 冲 激 响 应 图 0.25
3
m1=X1.*X2;%x 的奇部与偶部之积 m2=Y1.*Y2;%y 的奇部与偶部之积 m3=Z1.*Z2;%z 的奇部与偶部之积 figure(5) subplot(3,1,1); plot(t,m1,'r');xlabel('t'),ylabel('mulx[n]'); title('奇信号与偶信号的积信号'); subplot(3,1,2) plot(t,m2,'g');xlabel('t'),ylabel('muly[n]'); subplot(3,1,3); plot(t,m3,'b');xlabel('t'),ylabel('mulz[n]');
0
-2
-4000 -3000 -2000 -1000
0
1000 2000
t
x 104 2
0
-2
-4000 -3000 -2000 -1000
0
1000 2000
t
3000 3000 3000
4000 4000 4000
mulz[n]
3.画出 M 点滑动平均滤波器的波形(M 分别取 4 和 10)。
注:M 点滑动平均滤波器:
0
1000 2000 3000 4000
t
400
200
0
-4000 -3000 -2000 -1000
0
1000 2000 3000 4000
t
decz[n]
mulx[n]
muly[n]
x 104 1
奇信号与偶信号的积信号
0
-1
-4000 -3000 -2000 -1000
0
1000 2000
t
x 104 2
0.2
0.15
h[n]
0.1
0.05
0
0
2
4
6
8 10 12 14 16 18 20