Write a MATLAB function called convtd() to convolve a signal with a kernel in the time domain. It should have two input arguments: an input signal (a vector) and a kernel (also a vector).  It will return the vector that results from the convolution, which should be the same length as the input signal.

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a MATLAB function called convtd() to convolve a signal with a kernel in the time domain. It should have two input arguments: an input signal (a vector) and a kernel (also a vector).  It will return the vector that results from the convolution, which should be the same length as the input signal. 

The function will use a sliding window approach very similar to the bxcar() example from class. 

The first thing you should do is validate your inputs. Make sure both are vectors (use the isvector() function for this). Also, make sure the kernel has an odd number of elements. To do this, use the rem() function to make sure that there is a nonzero remainder when the length of the kernel is divided by 2. If either of these checks fails, use the matlab error() function to print an error message and immediately exit the function.

Next, figure out the half-width of the kernel (the w variable in bxcar()).

You are now ready to write the loop in which you "slide" the moving window across the signal. As in bxcar(), leave the first and last w elements in the output set to 0. One way to compute the output signal sample for a particular position of the sliding window is to flip the order of the kernel coefficients (you can use the flip() function for this), multiply elements of the flipped kernel with the corresponding chunk of the input signal that is in the window, and then sum these products.

Write a script called testConvtd to test your function.  This script should:

(1)  Generate a kernel to implement a moving average filter 21 elements long--each element should be 1/21. 

(2) Call your convtd() to filter a signal with this kernel. Download signal.dat from canvas to use as a test signal. This signal is sampled at 1 ms intervals (i.e., 1000 samples/sec).

(3) Plot the original signal and the filtered signal on the same axes in different colors. 

(4) On another set of axes, plot the spectra of the original and filtered signals in different colors. You can use the periodogram() function for this as I've done in class. You can use the figure() command to open a new figure window.

(4) On a third set of axes, plot the frequency response of the kernel. Make sure the x-axis is in Hz

To turn in the assignment, upload convtd(), testConvtd, and your 3 plots. Save your plots as graphics files (e.g., jpeg). To get full credit, you must turn in all files and your code must be appropriately commented and indented. 

Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Knowledge Booster
Representation of Polynomial
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education