java实现FIR线性缓冲区

本文介绍了一个使用Java绘制线性缓冲区图表的例子,通过具体的代码展示了如何利用JFreeChart库创建带有自定义样式的图表,并实现了数据集的动态更新。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

         作者: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");
		}
	}
}







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值