频谱图 [英] Plotting of spectrum

查看:135
本文介绍了频谱图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将在TDM-DeMux项目中工作,在该项目中,我必须从生成的信号中绘制频谱.甚至在此之前,我还被要求先绘制正弦波和余弦波的频谱. Java中是否有任何库(或文章/教程)可以帮助我绘制频谱图.
当前,我正在使用最新版本的JDK和Eclipse.

提前谢谢!

(已更新)
无论如何,我决定首先自己创建一个图形.因此,我绘制了x& y轴,并根据算法(给了我)创建了一个比例尺.代码在这里:

I am going to work on a TDM-DeMux project, in which I have to plot spectrum from the generated signals. Even before that, I was asked to to plot spectrum for sine and cosine waves, first. Are there any libraries(or articles/tutorials) in Java that can help me in plotting spectrum.
Currently, I am working with the latest versions of JDK and Eclipse.

Thanks in advance!

(Updated)
Anyways, I have decided to create a graph first by myself. So I drew x&y axes, created a scale from an algorithm (given to me). The code is here:

public class Graph extends JPanel{
	int[] data = { 30, 60, 75, 90 };
	final int PAD = 200;
	
	protected void paintComponent(Graphics g) {
		
		super.paintComponent(g);
		Graphics2D g2 = (Graphics2D)g;
		g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
		int h = getHeight();
		int w = getWidth();
		System.out.println("h = " + h + "\tw = " + w);
		g2.setColor(Color.GREEN);
		g2.drawLine(300, 0, 300, h+300);
		g2.drawLine(0, 300, w+300, 300);
                //this is the algorithm given to me
		double xScale = (w-2*PAD)/(data.length+1);
		double maxValue = 100.0;
		double yScale = (h-2*PAD)/maxValue;
                //------------------------------------//
		System.out.println("xScale= " + xScale + "\tyScale = " + yScale);
		//The origin location
		int x0 = 300;
		int y0 = h-300;
		System.out.println("x0 = " + x0 + "\ty0 = " + y0);
		g2.setPaint(Color.red);
		int x = x0 + data[0];
		int y = y0 + data[1];
		System.out.println("x = " + x);
		System.out.println("y = " + y);
		g2.drawOval(x, y, 30, 30);
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				JFrame f = new JFrame("JGraph");
				f.setBackground(Color.BLACK);//background color is not changing
				f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
				f.getContentPane().add(new Graph());
				f.setSize(600, 600);
				f.setLocation(100, 100);
				f.setVisible(true);
			}
		});	
	}

}



问题是尽管x& y坐标相对于原点为正.我画的圆不是
在第一象限.为什么会这样呢?另外,我想将图形的背景颜色更改为黑色.
再次感谢!



The problem is although x & y co-ordinates are positive relative to the origin. The circle which I drew is not
in the first quadrant. Why is this happening? Also I want to change the background color of my graph into black.
Thanks once again!

推荐答案

您正在将JPanel放置在JFrame上-因此,JPanel位于JFrame的前面.因此,您需要更改JPanels颜色:

you are placing a JPanel on your JFrame - therefor the JPanel is in front of the JFrame. So you need to change the JPanels color:

// line 15ff
@Override
protected void paintComponent(Graphics g) {
    this.setBackground(Color.BLACK); //now black



相减的值(此处为400,您使用的是300)定义了圆的位置.您应该将其与PAD相关联,从短期看,它似乎是图中平方长度的定义:



the subtracted value (here 400, you used 300) is defining the position of the circle. You should relate it to PAD, which on a short look seems to be the definition of the square length in the diagram:

// line 33/34
int y0 = h-400;
System.out.println("x0 = " + x0 + "\ty0 = " + y0);


这篇关于频谱图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆