作者:sundroid
个人站点:sundroid.cn 邮箱: hfutsnjc@163.com 微博:http://weibo.com/Sundroid
package com.fir;
import java.awt.Color;
import java.awt.Font;
import java.util.Random;
import javax.swing.JPanel;
import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.ChartUtilities;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.StandardChartTheme;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYSplineRenderer;
import org.jfree.data.xy.XYDataset;
import org.jfree.data.xy.XYSeries;
import org.jfree.data.xy.XYSeriesCollection;
import org.jfree.ui.ApplicationFrame;
import org.jfree.ui.RectangleInsets;
import org.jfree.ui.RefineryUtilities;
public class FIR extends ApplicationFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
static double y[] = new double[40];
private XYDataset data1;
public FIR(String title) {
super(title);
JPanel jpanel = createChartPanel1();
add(jpanel);
}
private XYDataset createSampleData() {
XYSeries xyseries = new XYSeries("");
for (int i = 0; i < y.length; i++) {
xyseries.add(i, y[i]);
}
XYSeriesCollection xyseriescollection = new XYSeriesCollection(xyseries);
return xyseriescollection;
}
private ChartPanel createChartPanel1() {
StandardChartTheme standardChartTheme = new StandardChartTheme("CN"); // 创建主题样式
standardChartTheme.setExtraLargeFont(new Font("微软雅黑", Font.BOLD, 20)); // 设置标题字体
standardChartTheme.setRegularFont(new Font("宋体", Font.PLAIN, 16)); // 设置图例的字体
standardChartTheme.setLargeFont(new Font("宋体", Font.PLAIN, 16)); // 设置轴向的字体
ChartFactory.setChartTheme(standardChartTheme); // 应用主题样式
data1 = createSampleData();
NumberAxis numberaxis = new NumberAxis("Y");
numberaxis.setAutoRangeIncludesZero(false);
NumberAxis numberaxis1 = new NumberAxis("X");
numberaxis1.setAutoRangeIncludesZero(false);
XYSplineRenderer xysplinerenderer = new XYSplineRenderer();
XYPlot xyplot = new XYPlot(data1, numberaxis, numberaxis1,
xysplinerenderer);
xyplot.setBackgroundPaint(Color.lightGray);
xyplot.setDomainGridlinePaint(Color.white);
xyplot.setRangeGridlinePaint(Color.white);
xyplot.setAxisOffset(new RectangleInsets(4D, 4D, 4D, 4D));
JFreeChart jfreechart = new JFreeChart("线性缓冲区 ",
JFreeChart.DEFAULT_TITLE_FONT, xyplot, true);
ChartUtilities.applyCurrentTheme(jfreechart);
ChartPanel chartpanel = new ChartPanel(jfreechart);
return chartpanel;
}
public static void main(String[] agrs) {
Random random = new Random();
double x[] = new double[40];
// int[] array = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
//
// moveNum(array);
// for (int i = 0; i < array.length; i++) {
//
// System.out.println("array" + array[i]);
// }
double c[] = { -7.0 / 10000, 3.0 / 10000, 14.0 / 10000, 10.0 / 10000,
-16.0 / 10000, -38.0 / 10000, -8.0 / 10000, 64.0 / 10000,
81.0 / 10000, -30.0 / 10000, -169.0 / 10000, -118.0 / 10000,
162.0 / 10000, 353.0 / 10000, 83.0 / 10000, -515.0 / 10000,
-689.0 / 10000, 247.0 / 10000, 2051.0 / 10000, 3523.0 / 10000,
3523.0 / 10000, 2051.0 / 10000, 247.0 / 10000, -689.0 / 10000,
-515.0 / 10000, 83.0 / 10000, 353.0 / 10000, 162.0 / 10000,
-118.0 / 10000, -169.0 / 10000, -30.0 / 10000, 81.0 / 10000,
64.0 / 10000, -8.0 / 10000, -38.0 / 10000, -16.0 / 10000,
10.0 / 10000, 14.0 / 10000, 3.0 / 10000, -7.0 / 10000 };
// for (int i = 0; i < c.length; i++) {
// System.out.print("\n" + "C" + i + "--->" + c[i]);
// }
for (int i = 0; i < x.length; i++) {
x[0]=1;
x[i]=0;
}
for (int i = 0; i < x.length; i++) {
System.out.print("\n" + "X" + i + "--->" + x[i]);
}
for (int i = 0; i < c.length; i++) {
// 执行一次后再开始执行数组移位
if (i >= 1) {
moveNum(x);
System.out.println("\n数组第" + i + "次移位");
outNum(x);
}
// 直接开始用移位后的数组执行下面的算法
// moveNum(x);
// System.out.println("数组第" + i + "次移位");
// outNum(x);
for (int b = 0; b < c.length; b++) {
y[i] += x[b] * c[40 - b - 1];
}
// System.out.println("\nRESULT[" + i + "]=" + y[i]);
}
FIR show = new FIR("线性缓冲区");
show.pack();
RefineryUtilities.centerFrameOnScreen(show);
show.setVisible(true);
// System.out.println("-----------" + y.length);
}
private static void moveNum(double[] n) {// 数组元素右移位
double temp = n[n.length - 1];
for (int i = n.length - 1; i > 0; i--) {
n[i] = n[i - 1];
}
n[0] = temp;
}
private static void outNum(double[] n) {// 输出数组
for (int i = 0; i < n.length; i++) {
System.out.print("X" + i + "-----" + n[i]+"\n");
}
}
}