联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-23:00
  • 微信:codinghelp

您当前位置:首页 >> Matlab编程Matlab编程

日期:2024-03-21 08:02

Matlab Laboratory (ELEC 224)

Session II: Convolution

1. Overview

The objective of this assignment is to gain some experience in writing Matlab code by

creating a Matlab function that performs a convolution in discrete-time known as a

convolution sum. Given discrete-time input signals x[n] and h[n], the general expression for

the convolution sum, y[n], is given by the equation,

=?∞

= ? k

y[n] x[k]h[n k] (1)

or equivalently ∑

=?∞

= ? k

y[n] h[k]x[n k]. That is, the sum is the same if the inputs are

interchanged. While the above applies to signals that are infinite in length, we are concerned

with input signals that are nonzero over a finite interval. Suppose that x[n] has M samples

x[1], x[2],…,x[M] and h[n] has N samples h[1], h[2],…, h[N]. Then output y[n] will have at

most M +N ?1 nonzero samples. Here we use time sample 1 as the starting sample rather

than time sample zero to conform with Matlab’s vector indexing. Then Eq. (1) would look

like

∑=

= ? +

N

k

y n h k x n k

1

[ ] [ ] [ 1]. (2)

That is, the outputs are:

y[1] = h[1] x[1] + h[2] x[0] + …+ h[N?1] x[3? N ]+ h[N] x[2 ? N]

= h[1] x[1]

y[2] = h[1] x[2] + h[2] x[1] + …+ h[N?1] x[4? N ]+ h[N] x[3 ? N]

= h[1] x[2] + h[2] x[1]

y[n] = h[1] x[n] + h[2] x[n ? 1] + …+ h[N?1] x[n +2? N ] + h[N] x[n +1? N ]

y[M+N?2] = h[1] x[M+N?2] + h[2] x[M+N?3] + …+ h[N?1] x[M]+ h[N] x[M?1]

= h[N?1] x[M] + h[N] x[M?1]

y[M+N?1] = h[1] x[M+N?1] + h[2] x[M+N?2] + …+ h[N?1] x[M+1]+ h[N] x[M]

= h[N] x[M]

2

Although much of your future use of Matlab would mainly require you to run existing

programs and perhaps write scripts to automate this process, it is still important to gain a

more thorough understanding of Matlab from a programming perspective. Another way to

view this is by the old adage,

...give someone a fish and they will be self-sufficient for a day. Teach someone to fish, and

they will be self-sufficient for life...

2. The Task

You are to design, write, debug and test a Matlab function named “convolver” that meets

the following specifications:

? The function is of the form y = convolver(h, x). For general information on how to run a

function, consult Matlab help. In other words, the only inputs are x and h. The sizes of

the input signals, x and h, represented either by row or column vectors, must be

determined by your function. If the input signals are not row or column vectors, the

function must exit with an explanatory error message.

? The user input ”help convolver” will output a one-line help message and then exit.

? It is assumed that the input vectors are indexed from time sample 1, to match Matlab’s

indexing convention. That is, the first nonzero element of vector x is denoted by x(1).

This matches the equations presented in the previous section. It is also assumed that the

first output sample begins at time sample 1.

? In addition to producing the correct output vector, the function should display all three

signals in stem-style subplots in a single figure window. Appropriate axis scaling should

be used to enhance visibility and ease interpretation of the effect of the convolution.

? No Matlab toolbox functions should be used in your code. Only commands from the

basic Matlab language are allowed.

? Your solution should try to conform to Matlab’s array computation language. In other

words, as many computations as possible should be ”vectorized”. That is, matrix/vector

operations should be used wherever possible and the use of loops, although necessary,

should be minimized.

3

? In your solution to be handed in, a complete listing of your function should be provided.

Also, the function should be tested with output provided on the following three sample

sets of inputs:

c = convolver (a,b) where:

a=[1 2 3 4] b = [1.5 0.5]

a = [1.5; 0.5] b = [1 2 3 4]

a = [1; 2; 3; 4] b = [1; 1; 1; 1]

This assignment should be completed and the report should be submitted within one week

after completion of the lab. Each team submits one report.


相关文章

版权所有:留学生编程辅导网 2020 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp