DSP

数字信号的产生和基本运算

2019-07-13 19:07发布

常用数字信号序列的产生

单位冲激序列δ(n)

function [ x,n ] = impseq( n0,n1,n2 ) if ((n0n2) || (n1>n2)) error('Arguments must satisfy n1 <= n0 <= n2') end n = [n1:n2]; x = [(n-n0) == 0]; >> n=[-10:10]; >> y=impseq(0,-10,10); >> stem(n,y)

1

单位阶跃序列2u(n5)

function [ x,n ] = stepseq( n0,n1,n2 ) if ((non2) || (n1>n2)) error('Arguments must satisfy n1 <= n0 <= n2') end n = [n1:n2]; x = [(n-n0) >= 0]; >>n=[-10:10]; >>y=2*stepseq(5,-10,10); >>stem(n,y)

2

矩形序列 R5(n)

>> n=[-10:10]; >> y=stepseq(0,-10,10)-stepseq(5,-10,10); >> stem(n,y)

3

y(n)2sin(0.3πn)+0.5cos2(0.6πn)

>> n=[-10:10]; >> y=2*sin(0.3*pi*n)+0.5*(cos(0.6*pi*n)).^2; >> stem(n,y)

4

数字信号的基本运算

%录制并保存人声x(n) >> R=audiorecorder(44100,16,1); >> recordblocking(R,45); >> play(R); >> x = getaudiodata(R); >> audiowrite('myNews.wav',x,44100); %读入并处理背景音乐y(n),原音频长度非45s,且是双声道,须处理 >> [y,Fs]=audioread('bgm.mp3'); >> y1=y(1:1984500,1); %混音并保存 >> z=0.7*x+0.3*y1; >> audiowrite('MySpeech.wav',z,44100); %绘图 >> t=[1:1984500]; >> figure >> plot(t,x,t,y1,t,z); >> title('z(n)=0.3*x(n)+0.7*y(n)'); %分别绘制图像 >> subplot(3,1,1),plot(x),title('MyNews'); >> subplot(3,1,2),plot(y1),title('bgm'); >> subplot(3,1,3),plot(z),title('MySpeech');

5

注:蓝 {MOD}为x(n),绿 {MOD}为y(n),红 {MOD}为z(n)

6

数字信号处理
Matlab实验一