Asked by Jared Martin
on 21 Apr 2015

Filtering a set of recorded data is a constant occurrence in just about any engineering discipline. For problem 2, the students will read data from a given file, filter the data with Equation 3 and then store the filtered data results along with the original data into an output file. For reference, the filter found in Equation 3 is known as a moving average filter and fall into the more general class of Finite Impulse Response (FIR) Filters.

Y[n]= (1/N) summation from k=0 to N-1 for X[n-k]

where:

X[n] = Is the input data from the file Y[n] = Is the filtered output data N=50,000

This Program should perform at least the following functions: 1. The program should display a title banner which has the title of FIR Filter Problem and some brief text that explains the functionality of the program. 2. Read in data from the given data file and store into an array. 3. Filter the data with Equation 3 and generate output values Y [n] For N = 100. 4. Open a file for output, and write the original data with the filtered data in columns. (a) Remember that writing two data values on a line can be done with, save myDataFileName.txt myVar -ASCII; 5. Open the file that your program created in Matlab and plot the original data with the filtered data on the same plot versus the sample number n. (a) The plot should be properly labeled with a title and x,y axis labels. The x axis label should be Samples, and the y axis label should be Recorded Data.

Answer by Youssef Khmou
on 21 Apr 2015

The important part of the problem is the implementation of MA filter, here is an example of 6 points window,

fs=80;

t=0:1/fs:2-1/fs;

f=5;

x=1.5*sin(2*pi*f*t).*cos(-1.1*t);

y=x+0.6*randn(size(t));

N=6;

K=length(y);

for n=N+1:K

s=0;

for p=n:-1:n-N

s=s+y(p);

end

z(n)=s/N;

end

there is a specific built-in function that performs the above code, try to find how to design the coefficient vectors.

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 1 Comment

## Guillaume (view profile)

## Direct link to this comment

https://it.mathworks.com/matlabcentral/answers/212725-filtering-a-set-of-recorded-data#comment_280066

Sign in to comment.