加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

离散系统的matlab实现

(2012-10-04 12:25:23)
标签:

离散

matlab

信号

filter

freqz

分类: 信号处理

1.时域表示

离散系统模型时域表示的Matlab实现函数有filter函数和impz函数两种,其中impz函数用于实现离散系统的单位冲击响应,具体情况如下所述。

(1)filter函数

filter函数其实就是对数据进行滤波。因为一个离散系统可以看作是一个滤波器,系统的输出就是输入经过滤波器滤波的结果。下面的说明很详细,简单的说就是b是传递函数的分子,a是分母,X为输入,zi为输入信号的初始状态。其他见说明。

filter

1-D digital filter
Syntax

y = filter(b,a,X)
[y,zf] = filter(b,a,X)
[y,zf] = filter(b,a,X,zi)
y = filter(b,a,X,zi,dim)
[...] = filter(b,a,X,[],dim)

Description

The filter function filters a data sequence using a digital filter which works for both real and complex inputs. The filter is a direct form II transposed implementation of the standard difference equation (see "Algorithm").

y = filter(b,a,X) filters the data in vector X with the filter described by numerator coefficient vector b and denominator coefficient vector a. If a(1) is not equal to 1, filter normalizes the filter coefficients by a(1). If a(1) equals 0, filter returns an error.

If X is a matrix, filter operates on the columns of X. If X is a multidimensional array, filter operates on the first nonsingleton dimension.

[y,zf] = filter(b,a,X) returns the final conditions, zf, of the filter delays. If X is a row or column vector, output zf is a column vector of max(length(a),length(b))-1. If X is a matrix, zf is an array of such vectors, one for each column of X, and similarly for multidimensional arrays.

[y,zf] = filter(b,a,X,zi) accepts initial conditions, zi, and returns the final conditions, zf, of the filter delays. Input zi is a vector of length max(length(a),length(b))-1, or an array with the leading dimension of size max(length(a),length(b))-1 and with remaining dimensions matching those of X.

y = filter(b,a,X,zi,dim) and [...] = filter(b,a,X,[],dim) operate across the dimension dim.

 

(2)impz函数

impz(b,a)

impz函数直接给出系统的单位冲击响应。同样的,b为分子,a为分母。

在matlab中,有很多方法可以产生单位冲激信号,但是最直接的方法就是利用matlab的zeros函数。如产生一个64点的单位冲激信号,可以用这样的语句:

pulse = [1 zeros(1,63)];

impz

Filter impulse response
Syntax

[h,t] = impz(hfilt)
[h,t] = impz(hfilt,n)
[h,t] = impz(hfilt,n,fs)
[h,t] = impz(hfilt,[],fs)
impz(hfilt)
[h,t] = impz(hs)
[h,t] = impz(hs,Name,Value)
impz(hs)

Description

impz returns the impulse response based on the current filter coefficients. This section describes common impz operation with adaptive filters, discrete-time filters, multirate filters, and filter System objects. For more input options, refer to impz in Signal Processing Toolbox documentation.

[h,t] = impz(hfilt) returns the impulse response h and the corresponding time points w at which the impulse response of hfilt is computed. The impulse response is evaluated at 10 1-second intervals—(0:9)'.

[h,t] = impz(hfilt,n) returns the impulse response evaluated at floor(n) 1-second intervals—(0:floor(n)-1)'.

[h,t] = impz(hfilt,n,fs) returns the impulse response evaluated at floor(n) 1/fs-second intervals—(0:floor(n)-1)'/fs.

[h,t] = impz(hfilt,[],fs) returns the impulse response evaluated at 10 1/fs-second intervals—(0:9)'/fs.

impz(hfilt) uses FVTool to plot the impulse response of the filter. You can also provide the optional input arguments n and fs with this syntax.

[h,t] = impz(hs) returns the impulse response for the filter System object hs. The impulse response is evaluated at 10 1-second intervals—(0:9)'. You can also provide the optional input arguments n and fs with this syntax.

[h,t] = impz(hs,Name,Value) returns an impulse response with additional options specified by one or more Name,Value pair arguments.

impz(hs) uses FVTool to plot the impulse response of the filter System object hs.

Note   You can use impz for both real and complex filters. When you omit the output arguments, impz plots only the real part of the impulse response.

 

 

例1:当系统的输入输出差分方程为:

y(n) – 0.8 * y(n-1) – 0.5y(n-2) = 0.7x(n) + 0.3x(n-1)

并且系统的输入为单位冲激响应函数时,分别利用filter函数和impz函数得到系统的响应曲线

程序如下:

clear all;
pulse = [1,zeros(1,63)];
b = [0.7 0.3];
a = [1,-0.8,-0.5];
h1 = filter(b,a,pulse);
h2 = impz(b,a,64);
subplot(211);
stem(h1);
title('filter function');
subplot(212);
stem(h2);
title('impz function');

运行结果:

http://s11/middle/84024a4a4cb3424b06d5a&690

2.传递函数响应

Matlab中实现传递函数响应的函数为freqz函数。

常用格式为:

[h,f] = freqz(b,a,n,fs)

其中,向量b和a为离散系统的参数,fs为采样频率,n为区间[0 fs/2]频率范围内选取的频率点数,f为记录频率点数。由于freqz函数式采用基2的FFT算法,n常取2的幂次方,以便提高计算速度。

例2:系统的输入输出传递函数为

http://s14/middle/84024a4a4cb3424b1e12d&690

其Matlab程序如下:

clear all
close all;

fs = 1000;
b = [0.3 0.2];
a = [1 -0.4 -0.7];
[h,f] = freqz(b,a,256,fs);
mag = abs(h);
ph = angle(h);
ph = ph*180/pi;
subplot(211);
plot(f,mag);
grid on;
xlabel('freqency(Hz)');
ylabel('magnitude');
subplot(212);
plot(f,ph);
grid on;
xlabel('freqency(Hz)');
ylabel('phase')

运行结果:

http://s11/middle/84024a4a4cb3424c040ca&690

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有