1 |
2 |
vladimirar |
% //////////////////////////////////////////////////////////////////////
|
2 |
|
|
% //// ////
|
3 |
|
|
% //// Low Pass Filter FIR IP Core ////
|
4 |
|
|
% //// ////
|
5 |
|
|
% //// This file is part of the LPFFIR project ////
|
6 |
|
|
% //// https://opencores.org/projects/lpffir ////
|
7 |
|
|
% //// ////
|
8 |
|
|
% //// Description ////
|
9 |
|
|
% //// Implementation of LPFFIR IP core according to ////
|
10 |
|
|
% //// LPFFIR IP core specification document. ////
|
11 |
|
|
% //// ////
|
12 |
|
|
% //// To Do: ////
|
13 |
|
|
% //// - ////
|
14 |
|
|
% //// ////
|
15 |
|
|
% //// Author: ////
|
16 |
|
|
% //// - Vladimir Armstrong, vladimirarmstrong@opencores.org ////
|
17 |
|
|
% //// ////
|
18 |
|
|
% //////////////////////////////////////////////////////////////////////
|
19 |
|
|
% //// ////
|
20 |
|
|
% //// Copyright (C) 2019 Authors and OPENCORES.ORG ////
|
21 |
|
|
% //// ////
|
22 |
|
|
% //// This source file may be used and distributed without ////
|
23 |
|
|
% //// restriction provided that this copyright statement is not ////
|
24 |
|
|
% //// removed from the file and that any derivative work contains ////
|
25 |
|
|
% //// the original copyright notice and the associated disclaimer. ////
|
26 |
|
|
% //// ////
|
27 |
|
|
% //// This source file is free software; you can redistribute it ////
|
28 |
|
|
% //// and/or modify it under the terms of the GNU Lesser General ////
|
29 |
|
|
% //// Public License as published by the Free Software Foundation; ////
|
30 |
|
|
% //// either version 2.1 of the License, or (at your option) any ////
|
31 |
|
|
% //// later version. ////
|
32 |
|
|
% //// ////
|
33 |
|
|
% //// This source is distributed in the hope that it will be ////
|
34 |
|
|
% //// useful, but WITHOUT ANY WARRANTY; without even the implied ////
|
35 |
|
|
% //// warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR ////
|
36 |
|
|
% //// PURPOSE. See the GNU Lesser General Public License for more ////
|
37 |
|
|
% //// details. ////
|
38 |
|
|
% //// ////
|
39 |
|
|
% //// You should have received a copy of the GNU Lesser General ////
|
40 |
|
|
% //// Public License along with this source; if not, download it ////
|
41 |
|
|
% //// from http://www.opencores.org/lgpl.shtml ////
|
42 |
|
|
% //// ////
|
43 |
|
|
% //////////////////////////////////////////////////////////////////////
|
44 |
|
|
|
45 |
|
|
% Cleanup
|
46 |
|
|
clear;clc;close all;
|
47 |
|
|
|
48 |
|
|
% Difference equation of low-pass filter
|
49 |
|
|
b = [1, 1, 1, 1, 1, 1]; a = [1];
|
50 |
|
|
|
51 |
|
|
% Response
|
52 |
|
|
n = [0:7];
|
53 |
|
|
h = impz(b,a,8);
|
54 |
|
|
[H,w] = freqz(b,a,100);
|
55 |
|
|
magH = abs(H); phaH = angle(H);
|
56 |
|
|
|
57 |
|
|
% Plot
|
58 |
|
|
subplot(4,1,1); stem(n,h);
|
59 |
|
|
title('Impulse Response'); xlabel('n'); ylabel('h(n)')
|
60 |
|
|
subplot(4,1,2);zplane(b,a);grid
|
61 |
|
|
title('Pole-Zero Plot')
|
62 |
|
|
subplot(4,1,3);plot(w/pi,magH);grid
|
63 |
|
|
xlabel('Frequency in \pi units'); ylabel('Magnitude');
|
64 |
|
|
title('Magnitude Response')
|
65 |
|
|
subplot(4,1,4);plot(w/pi,phaH/pi);grid
|
66 |
|
|
xlabel('Frequency in \pi units'); ylabel('Phase in \pi units');
|
67 |
|
|
title('Phase Response')
|
68 |
|
|
|
69 |
|
|
% Write Tabular Impulse Response Data to Text File
|
70 |
|
|
fileID = fopen('matlab_impulseResponse.txt','w');
|
71 |
|
|
fprintf(fileID,'%1.1d\n',h);
|
72 |
|
|
fclose(fileID);
|