The goal of this lab is to investigate two important properties of FIR filters w
ID: 1834529 • Letter: T
Question
The goal of this lab is to investigate two important properties of FIR filters which are represented by the linear constant coefficient difference equations. To implement the difference equation, you will need the delay function from lab 8. The input output relationship of the FIR filter is represented by the following difference equation: y[n] = bkx[n-k] In your report include all the M-files and plots. Function M-files are required to have a detailed help section and the codes should be well commented. Create a function called FIR_Filter Inputs: X (row vector), bk (row vector of real coefficients) Output: Y Generate an error message if any of the inputs does not meet the condition. Evaluate the response of FIR filter to X as an input using the difference equation (and the delay function). Store the output values in Y. Linear systems have the property that if x1[n] rightarrow y1 [n] and x2|n| rightarrow y2[n] then x[n] = alpha x1[n] + beta x2[n]x[n] rightarrow y[n] = alpha y1[n] + beta y2[n] Create a function called Linearity_Test Inputs: alpha, beta (any constant number-no condition), X1, X2 (row vectors), bk (row vector of real coefficients) No output Generate an error message if any of the inputs X1, X2 or bk do not meet the condition. Call the function FIR_Filter for (X1, bk) and (X2, bk) and store the results in Y1 and Y2 respectively. Evaluate the expression alpha*X1 + beta*X2 and store the result in X. Call the function FIR_filter for (X, bk) and store the output in Y. Store the absolute value of the difference of Y and the expression alpha*Y1 + beta*Y2 in a variable called ERR Plot Y, alpha*Y1 + beta*Y2 and ERR, against their element numbers, using stem function, in the same figure window (three subplots in a column). Label the axes and title the subplots. Compare Y to the result of the expression alpha*Y1 + beta * Y2. Create a message to display the result of linearity test in the command window (It is recommended to define a limit on ERR values and to consider the system to be linear if the error values are negligible). A discrete-time system is said to be time-invariant if, when an input is delayed by n0, the output is delayed by the same amount. We can express this condition as x[n - n0] rightarrow y(n - n0) Where x[n] rightarrow y[n] Create a function called TI_Test Inputs: X (row vector), bk (row vector of real coefficients). n0 (integer, greater than I) No output Call the FIR_filter function for (X, bk) and store the result in Y. Use the delay function to delay X by n0 and store the delayed sequence in Xd. Call the FIR_filter function for (Xd, bk) and store the result in Yd. Plot Yd and the delayed version of Y by n0 (created by using the delay function), against their element numbers using stem function, in the same figure window (two subplots in a column). Label the axes and title the subplots. Compare Yd to the delayed version of Y. Generate a message to display the result of time-invariance test in the command window. Suppose that the FIR filter is represented by: y[n] = 2 x[n] + 2x[n - 1] Is it high-pass or low-pass? Test the filter for lineanty and time invariance using the following inputs: x1[n] = 5 cos (pi/2 n) x2[n] =3/2cos(pi/4 n)Explanation / Answer
function Y = FIR_filter(x,bk)
N= 1024; % no. of input samples
M = 2; % order of filter
for i = M+1:1:N
p = 0;
for j = 1:1:M
temp = bk(1,j)*x(1,i-j);
p = p + temp;
end
Y(1,i-M) = p;
end
in this FIR_Filter function im considering input to be of 1024 length.
% Linearity_Test(alpha,beta,x1,x2,bk)
clc;
clear all;
close all;
x1(1,:) = ones(1,1024);
x2 = ones(1,1024);
bk = ones(1,2);
alpha = 2;
beta = 3;
y1=FIR_filter(x1,bk);
y2=FIR_filter(x2,bk);
x = alpha*x1 + beta*x2;
y = FIR_filter(x,bk);
Err = y - alpha*y1 - beta*y2;
Err = abs(Err);
figure;
stem(y);
figure;
stem(alpha*y1+beta*y2);
figure;
stem(Err);
% TI_Test(x,bk,n0);
x=ones(1,1024);
bk = ones(1,2);
n0 = 5;
y=FIR_filter(x,bk);
xd = zeros(1,1024);
for i=1:1024-n0 % delay function
xd(1,i)=x(1,i+n0);
end
yd=FIR_filter(xd,bk);
figure;
subplot(2,1,1);
stem(y);
title('y');
subplot(2,1,2);
stem(yd);
the above both functions are designed for general case.
% Linearity_Test(alpha,beta,x1,x2,bk)
% this function is for x1[n] = 5cos(pi/4n) & x2[n] = 3/2cos(pi/4n)
clc;
clear all;
close all;
for i=1:1024
x1(1,i) = 5*cos(pi/2 * i);
end
for i=1:1024
x2(1,i) = 3/2*cos(pi/4 * i);
end
bk = [2 2];
alpha = 2;
beta = 3;
y1=FIR_filter(x1,bk);
y2=FIR_filter(x2,bk);
x = alpha*x1 + beta*x2;
y = FIR_filter(x,bk);
Err = y - alpha*y1 - beta*y2;
Err = abs(Err);
stem(y);
figure;
stem(alpha*y1+beta*y2);
figure;
stem(Err);
% TI_Test(x,bk,n0);
%for testing x1[n]=5cos(pi/4n)
for i=1:1024
x1(1,i) = 5*cos(pi/2 * i);
end
bk = [2 2];
n0 = 5;
y=FIR_filter(x,bk);
xd = zeros(1,1024);
for i=1:1024-n0 % delay function
xd(1,i)=x(1,i+n0);
end
yd=FIR_filter(xd,bk);
figure;
subplot(2,1,1);
stem(y);
title('y');
subplot(2,1,2);
stem(yd);
title('yd');
% TI_Test(x,bk,n0);
%for testing x2[n]= 3/2cos(pi/4n)
for i=1:1024
x2(1,i) = 3/2*cos(pi/4 * i);
end
bk = [2 2];
n0 = 5;
y=FIR_filter(x,bk);
xd = zeros(1,1024);
for i=1:1024-n0 % delay function
xd(1,i)=x(1,i+n0);
end
yd=FIR_filter(xd,bk);
figure;
subplot(2,1,1);
stem(y);
title('y');
subplot(2,1,2);
stem(yd);
title('yd');
just copy the codes to matlab & run u will get the plots & if u need the plots & m files also then contact me....
i think i deserve more points for this...
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.