Noise simulation using java: Please help, as I\'m beginner here. I\'m trying to
ID: 3736435 • Letter: N
Question
Noise simulation using java:
Please help, as I'm beginner here. I'm trying to create an simulation of an square wave signal using Java. Then I want the program to prompt the user to enter the noise percentage (-10% to +10%) and then it adds the noise to the signal. Next the program should filter out the noise from the signal and output the output the clean data, noisy data, and the filtered data into a text file in form of 3 columns for a given noise percentage. graphs of clean and noisy data in one chart and the graph of filtered
data in a seperate chart.
Explanation / Answer
using System; using System.Drawing; using System.Drawing.Imaging; using System.Threading; using System.Windows; using System.Windows.Forms; namespace WaveSimulator { public class WaveEngine { Bitmap bmp; // This will be our canvas. BitmapData bd; // This will be used to modify the RGB pixel array of the "bmp". // "vd" means "vertex data" float[] vd; // Height map float[] vdv; // Velocity map float[] vda; // Acceleration map float[] vds; // Sustainability map. Sustainability can be thought as anti-damping. bool[] vd_static; // Static particle map. Particles which will act like a obstacle or wall. float mass = 0.1f; // Mass of each particle. It is the same for all particles. float limit = 500f; // Maximum absolute height a particle can reach. float action_resolution = 20f; // Resolution of movement of particles. float sustain = 1000f; // Anti-damping. Propagation range increases by increasing this variable. Minimum is 1f. int delay = 1; // Time-out in milliseconds for force calculations. float phase1 = 0f; // Current phase value of oscillator1. float phase2 = 0f; // Current phase value of oscillator2. float freq1 = 0.2f; // Phase changing rate of oscillator1 per calculation. Frequency increases by increasing this variable. float freq2 = 0.2f; // Phase changing rate of oscillator2 per calculation. Frequency increases by increasing this variable. float power = 1.0f; // Power of the output force exerted on each particle. Natural value is 1.0f BufferedGraphics bufgraph; // Double-buffered graphics for rendering. It minimizes flickering. BufferedGraphicsContext bufgcont; // Will be used to initialize bufgraph. Thread ForceCalcT; // Worker thread that will do force calculations. Mutex mutex; // This will limit the access to variables. bool work_now = false; // True = Thread must make calculations now, False = Thread must sleep now. bool highcont = false; // High contrast drawing. bool disposing = false; // It will be true once the termination starts. bool osc1active = false; // Is oscillator1 is turned on? bool osc2active = false; // Is oscillator2 is turned on? int osc1point = 0; // Location of the oscillator1 in the wave pool. It is an index value. int osc2point = 0; // Location of the oscillator2 in the wave pool. It is an index value. int size = 200; // Size of the wave pool. It indicates both the width and height since the pool will always be a square. Color color1 = Color.Black; // Color of the crest or trough. Color color2 = Color.Cyan; // Color of the crest or trough. Color colorstatic = Color.Yellow; // Color of the static particles. // These variables are used for edge absorbtion. It is used for eliminating reflection from window boundaries. int absorb_offset = 10; // Offset from each window boundary where the sustainability starts to decrease. float min_sustain = 2f; // The lowest sustainability value. They are located at the boundaries. bool edge_absorbtion = true; // If true, the particles near the boundaries will have low sustainability. Control control; // This will be the control where the engine runs and renders on. public enum ParticleAttribute { Height = 1, Velocity = 2, Acceleration = 4, Sustainability = 8, Fixity = 16, All = 32, } public float Mass { get { return mass; } set { if (value > 0f) { mutex.WaitOne(); mass = value; mutex.ReleaseMutex(); } } } public float Limit { get { return limit; } set { if (value > 0f) { mutex.WaitOne(); limit = value; mutex.ReleaseMutex(); } } } public float ActionResolution { get { return action_resolution; } set { if (value >= 1f) { mutex.WaitOne(); action_resolution = value; mutex.ReleaseMutex(); } } } public float Sustainability { get { return sustain; } set { if (value >= 1f) { mutex.WaitOne(); sustain = value; setSustain(); mutex.ReleaseMutex(); } } } public int Delay { get { return delay; } set { if (value >= 0) { mutex.WaitOne(); delay = value; mutex.ReleaseMutex(); } } } public float PhaseRate1 { get { return freq1; } set { if (value > 0f && value 0f && value 0f) { mutex.WaitOne(); power = value; mutex.ReleaseMutex(); } } } public int Size { get { return size; } set { if (size >= 1f) { mutex.WaitOne(); size = value; setPool(); mutex.ReleaseMutex(); } } } public float EdgeSustainability { get { return min_sustain; } set { if (value >= 1f) { mutex.WaitOne(); min_sustain = value; setSustain(); mutex.ReleaseMutex(); } } } public int AbsorbtionOffset { get { return absorb_offset; } set { if (value > 0 && value size) rect.Height -= (rect.Y + rect.Height) - size; bool xh = false, xv = false, xa = false, xs = false, xf = false; if ((ParticleAttribute.All & partatt) == ParticleAttribute.All) { xh = true; xv = true; xa = true; xs = true; xf = true; } else { if ((ParticleAttribute.Height & partatt) == ParticleAttribute.Height) xh = true; if ((ParticleAttribute.Velocity & partatt) == ParticleAttribute.Velocity) xv = true; if ((ParticleAttribute.Acceleration & partatt) == ParticleAttribute.Acceleration) xa = true; if ((ParticleAttribute.Sustainability & partatt) == ParticleAttribute.Sustainability) xs = true; if ((ParticleAttribute.Fixity & partatt) == ParticleAttribute.Fixity) xf = true; } for (int y = rect.Y * size; y size) rect.Height -= (rect.Y + rect.Height) - size; result = new float[rect.Width * rect.Height]; if (partatt == ParticleAttribute.Height) xh = true; if (partatt == ParticleAttribute.Velocity) xv = true; if (partatt == ParticleAttribute.Acceleration) xa = true; if (partatt == ParticleAttribute.Sustainability) xs = true; if (partatt == ParticleAttribute.Fixity) xf = true; int r = 0; for (int y = rect.Y * size; yRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.