/* * nm6.java - revised 19 Apr 05 - width 385, height 261 * @author jack@ord.ca * FFSS coefficients for Pulse A and Pulse B * on an n-segment string clamped at both ends */ import java.applet.Applet; import java.awt.*; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; public class nm6 extends Applet implements ActionListener { int kk=0; // Declarations String b1s="Pulse A"; Button b1=new Button(b1s); String b2s="Pulse B"; Button b2=new Button(b2s); Choice ch=new Choice(); public void init() { setBackground(new Color(211, 211, 211)); ch.setBackground(getBackground()); ch.addItem("n=48"); ch.addItem("n=96"); ch.addItem("n=192"); ch.addItem("n=384"); add(b1); add(b2); add(ch); b1.addActionListener(this); b2.addActionListener(this); } public void paint(Graphics g) { int n, nm, k, x1, y1, x2, y2; // Declarations n=48*(int)(Math.pow(2, ch.getSelectedIndex())); if (n==48) { nm=n; } else { nm=64; } int [] yy=new int[nm+1]; double [] y=new double[n+1]; double [] v=new double[n+1]; double [] b=new double[nm+1]; double [] d=new double[nm+1]; double [] w=new double[nm+1]; double pi, s, z; k=0; s=0; z=0; pi=Math.PI; g.setColor(Color.black); g.drawRect(0, 0, 384, 260); if (kk>0) { for (int i=3*n/8; i<=5*n/8; i=i+1) { // Init Pulse A z=(i-3*n/8)*pi/(n/8); y[i]=40*(1-Math.cos(z)); v[i]=-40*pi/(n/8)*Math.sin(z); if (kk==2) { // Init Pulse B v[i]=v[i]*Math.cos(4*z)+y[i]*4*pi/(n/8)*Math.sin(4*z); y[i]=y[i]*Math.cos(4*z); } } for (int i=1; i<=nm; i=i+1) { // FFSS w[i]=2*Math.sin(pi*i/2/n); for (int j=1; j<=n-1; j=j+1) { b[i]=b[i]+y[j]*2/n*Math.sin(pi*i*j/n); d[i]=d[i]+v[j]/w[i]*2/n*Math.sin(pi*i*j/n); } s=s+b[i]*b[i]+d[i]*d[i]; } g.setColor(Color.red); for (int i=1; i<=nm; i=i+1) { // Show FFSS coeffts yy[i]=260-(int)(1200*(b[i]*b[i]+d[i]*d[i])/s+.5); if (yy[i]<1) { yy[i]=1; } g.fillRect(6*i-2, yy[i], 5, 260-yy[i]); } z=0; do { k=k+1; z=z+b[k]*b[k]+d[k]*d[k]; } while ((z/s)<.9999); g.setColor(Color.black); g.drawString("For Nmax = "+k, 100, 45); g.drawString("Percent = "+(int)(100000*z/s)/1000., 200, 45); kk=0; g.setColor(Color.blue); x1=0; y1=260; // Plot dispersion reln if (n==48) { nm=288; } else { nm=384; } for (int i=n/48; i<=nm; i=i+n/48) { x2=i; y2=260-(int)(2.4*n*Math.sin(i*pi/12/n)+.5); g.drawLine(x1, y1, x2, y2); x1=x2; y1=y2; } } } public void actionPerformed(ActionEvent e) { // Buttons String tst; tst=e.getActionCommand(); if (b1s.equals(tst)) { kk=1; } // Pluck A if (b2s.equals(tst)) { kk=2; } // Pulse B repaint(); } }