private void write_square_wave_period( Channel channel, SquareWave square) { square.period = (uint)(((SOUND_MAX_FREQUENCY + 1) - channel.frequency) * 4); }
private void DrawSquareWave() { // Set the x axis range to be the period of the wave. m_GraphXAxisRange = double.Parse(textBox_Period.Text); // Get the amplitude of the wave from the user double amplitude = Convert.ToDouble(textBox_Amplitude.Text); // Get the phase of the wave from the user double phase = Convert.ToDouble(textBox_Phase.Text); // Create the square wave //m_SquareWave = new SquareWave(amplitude, // m_GraphXAxisRange, // phase, // m_SamplingPeriod); m_SquareWave = new SquareWave(amplitude, m_GraphXAxisRange, (int)phase, m_SamplingPeriod); // Set the graph y axis limits m_GraphAxisYMax = Math.Round(amplitude + (amplitude / 4), 2); m_GraphAxisYMin = -1 * m_GraphAxisYMax; // Set the current wave m_currentWave = m_SquareWave; }
public void HaveHeightAndWidth() { var squareWave = new SquareWave(10, 10, 10, 0); Assert.IsTrue(squareWave.Height > 0); Assert.IsTrue(squareWave.Width > 0); }
public void Constructor_ReturnsSquareWave() { double[] dutyCycles = { 0.0, 0.5, 1.0 }; foreach (var dutyCycle in dutyCycles) { SquareWave sw = new SquareWave(dutyCycle); Assert.IsInstanceOfType(sw, typeof(SquareWave)); } }
void Awake() { sawAudioWave = new SawWave(); squareAudioWave = new SquareWave(); sinusAudioWave = new SinusWave(); amplitudeModulationOscillator = new SinusWave(); frequencyModulationOscillator = new SinusWave(); sampleRate = AudioSettings.outputSampleRate; }
//Below runs the necessary scan on the APM public async Task <Method> RunScan() { List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync(); ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count); ScanParams instance = new ScanParams(); switch (_database.VoltamType) { case "Linear Voltammetry": LinearSweep linSweep = instance.LinSweep(_database); linSweep.Ranging.StartCurrentRange = new CurrentRange(5); linSweep.Ranging.MaximumCurrentRange = new CurrentRange(6); linSweep.Ranging.MaximumCurrentRange = new CurrentRange(3); return(linSweep); case "Cyclic Voltammetry": CyclicVoltammetry cVoltammetry = instance.CV(_database); cVoltammetry.Ranging.StartCurrentRange = new CurrentRange(5); cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(6); cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(3); return(cVoltammetry); case "Square Wave Voltammetry": SquareWave squareWave = instance.SWV(_database); squareWave.Ranging.StartCurrentRange = new CurrentRange(5); squareWave.Ranging.MaximumCurrentRange = new CurrentRange(6); squareWave.Ranging.MaximumCurrentRange = new CurrentRange(3); return(squareWave); case "Alternating Current Voltammetry": ACVoltammetry acVoltammetry = instance.ACV(_database); acVoltammetry.Ranging.StartCurrentRange = new CurrentRange(5); acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(6); acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(3); return(acVoltammetry); default: //Add code to notify user that something has gone wrong and needs to be fixed return(null); } }
public void Value_ReturnsDouble() { double[] dutyCycles = { 0.0, 0.5, 1.0 }; double[] phases = { 0.0, 0.25 * Math.PI, 0.5 * Math.PI, Constants._2PI }; foreach (double dutyCycle in dutyCycles) { SquareWave sw = new SquareWave(dutyCycle); foreach (double phase in phases) { Assert.IsInstanceOfType(sw.Value(phase), typeof(double)); } } }
public void Value_Returns1AlwaysForDutyCycleOf1() { double dutyCycle = 1.0; double[] phases = { 0.0, 0.25 * Math.PI, 0.5 * Math.PI, Constants._2PI }; double expected = 1.0; SquareWave sw = new SquareWave(dutyCycle); foreach (double phase in phases) { Assert.AreEqual(sw.Value(phase), expected); } }
public SquareWave SWV(ScanDatabase _database) //Set the parameters for a square wave scan { SquareWave squareWave = new SquareWave { BeginPotential = (float)_database.StartingPotential, EndPotential = (float)_database.EndingPotential, StepPotential = (float)_database.PotentialStep, PulseAmplitude = (float)_database.Amplitude, Frequency = (float)_database.Frequency }; return(squareWave); }
public void Constructor_ThrowsArgumentOutOfRangeException_ForDutyCycleGreatherThan1() { double dutyCycle = 1.000001; try { SquareWave sw = new SquareWave(dutyCycle); } catch (ArgumentOutOfRangeException e) { Assert.IsInstanceOfType(e, typeof(ArgumentOutOfRangeException)); StringAssert.Contains(e.Message, Constants.DutyCycleAbove1); return; } Assert.Fail(); }
public void TestSquareWave() { Calibration.Initialize(); IBGCStream stream = new SquareWave(1f, 400f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "squareWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); }
public void Constructor_ThrowsArgumentOutOfRangeException_ForNegativeDutyCycle() { double dutyCycle = -1.0; try { SquareWave sw = new SquareWave(dutyCycle); } catch (ArgumentOutOfRangeException e) { Assert.IsInstanceOfType(e, typeof(ArgumentOutOfRangeException)); StringAssert.Contains(e.Message, Constants.DutyCycleNegativeMessage); return; } Assert.Fail(); }
public void Value_ReturnsKnownResults_ForKnownPhases_BeforeAndAfterSetDutyCycle() { double initialDutyCycle = 0.25; double[] initialPhases = { 0.0, 0.2, initialDutyCycle *Constants._2PI, 3.0, Constants._2PI }; double[] initialexpectedValues = { 1.0, 1.0, 0.0, 0.0, 1.0 }; SquareWave sw = new SquareWave(initialDutyCycle); TestMethods.TestKnownInputsAgainstKnownResults(sw, initialPhases, initialexpectedValues); double finalDutyCycle = 0.6; double[] finalPhases = { 0.0, 0.2, initialDutyCycle *Constants._2PI, 3.0, 6.0, Constants._2PI }; double[] finalExpectedValues = { 1.0, 1.0, 1.0, 1.0, 0.0, 1.0 }; sw.DutyCycle = finalDutyCycle; TestMethods.TestKnownInputsAgainstKnownResults(sw, finalPhases, finalExpectedValues); }
void Awake() { sawAudioWave = new SawWave(); squareAudioWave = new SquareWave(); sinusAudioWave = new SinusWave(); amplitudeModulationOscillator = new SinusWave(); frequencyModulationOscillator = new SinusWave(); // Gets the Sample Rate of the audio system in Unity sampleRate = AudioSettings.outputSampleRate; //Debug.Log(sampleRate); // The value that is assigned to the variable volume, this is the actual volume of the synth volumeValue = 0.3f; // Change this value to make it louder volume = volumeValue; }
public void Value_ReturnsKnownValues_ForKnownPhases() { double dutyCycle = 0.25; double[] phases = { 0.0, 0.2, dutyCycle *Constants._2PI, 3.0, Constants._2PI }; double[] expectedValues = { 1.0, 1.0, 0.0, 0.0, 1.0 }; SquareWave sw = new SquareWave(dutyCycle); Assert.AreEqual(phases.Length, expectedValues.Length, "Known inputs and results test sets do not contain the same number of values."); for (int count = 0; count < phases.Length; count++) { double phase = phases[count]; double actual = sw.Value(phase); double expected = expectedValues[count]; string message = string.Format("Phase: {0}\nExpected: {1}\nActual:{2}", phase, expected, actual); Assert.AreEqual(actual, expected, message); } }
public void SetDutyCycle_ThrowsArgumentOutOfRangeException_ForNegativeDutyCycle() { double initialDutyCycle = 0.5; SquareWave sw = new SquareWave(initialDutyCycle); try { double negativeDutyCycle = -0.25; sw.DutyCycle = negativeDutyCycle; } catch (ArgumentOutOfRangeException e) { Assert.IsInstanceOfType(e, typeof(ArgumentOutOfRangeException)); StringAssert.Contains(e.Message, Constants.DutyCycleNegativeMessage); return; } Assert.Fail(); }
public void SquareWave_1000_samples_500000_iterations_4_channels() { var buffers = new[] { new float[1000], new float[1000], new float[1000], new float[1000] }; var target = new SquareWave(); target.Format = new WaveFormat(44100, 4); for (int i = 0; i < 500000; i++) { target.Process(buffers, 1000); } }
public void Set( string Trig, Signal Signal = null, VirtualPath VirtualPath = null, SquareWave SquareWave = null, SetVar SetVar = null, string PortOut = null, string Next = null ) { SetCommand cmd = new SetCommand( inSignal: Signal, inVirtualPath: VirtualPath, inSquareWave: SquareWave, inSetVar: SetVar, inPortOut: PortOut, inNext: Next ); PublicController.Instance.Register(Trig, cmd); }
//Sets the scan parameters public async Task <Method> RunScan() { //Grabs the most recent database to get the required parameters List <ScanDatabase> allDb = await App.Database.GetScanDatabasesAsync(); ScanDatabase _database = await App.Database.GetScanAsync(allDb.Count); //Gets an instance of ScanParams ScanParams instance = new ScanParams(); switch (_database.VoltamType) //Switch which invokes the correct type of scan { case "Alternating Current Voltammetry": //Sets an alternating current voltammetric scan using (ACVoltammetry acVoltammetry = instance.ACV(_database)) { acVoltammetry.SmoothLevel = 0; acVoltammetry.Ranging.StartCurrentRange = new CurrentRange(CurrentRanges.cr10uA); //Sets the range that the potentiostat will use to detect the current acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA); acVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA); return(acVoltammetry); } case "Cyclic Voltammetry": //Sets a cyclic voltammetric scan using (CyclicVoltammetry cVoltammetry = instance.CV(_database)) { cVoltammetry.SmoothLevel = 0; cVoltammetry.Ranging.StartCurrentRange = new CurrentRange(CurrentRanges.cr10uA); //Sets the range that the potentiostat will use to detect the current cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA); cVoltammetry.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA); return(cVoltammetry); } case "Differential Pulse Voltammetry": //Sets a differential pulse voltammetric scan using (DifferentialPulse differentialPulse = instance.DPV(_database)) { differentialPulse.SmoothLevel = 0; differentialPulse.Ranging.StartCurrentRange = new CurrentRange(CurrentRanges.cr1uA); //Sets the range that the potentiostat will use to detect the current differentialPulse.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr1uA); differentialPulse.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr10nA); return(differentialPulse); } case "Linear Voltammetry": //Sets a linear voltammetric scan using (LinearSweep linSweep = instance.LinSweep(_database)) { linSweep.SmoothLevel = 0; linSweep.Ranging.StartCurrentRange = new CurrentRange(CurrentRanges.cr10uA); //Sets the range that the potentiostat will use to detect the current linSweep.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA); linSweep.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA); return(linSweep); } case "Square Wave Voltammetry": //Sets a square wave voltammetric scan using (SquareWave squareWave = instance.SWV(_database)) { squareWave.SmoothLevel = 0; squareWave.Ranging.StartCurrentRange = new CurrentRange(CurrentRanges.cr10uA); //Sets the range that the potentiostat will use to detect the current squareWave.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100uA); squareWave.Ranging.MaximumCurrentRange = new CurrentRange(CurrentRanges.cr100nA); return(squareWave); } default: //Add code to notify user that something has gone wrong and needs to be fixed return(null); } }
public void BeAWave() { var squareWave = new SquareWave(10, 10, 10, 0); Assert.IsInstanceOf <Wave>(squareWave); }
public void TestInitialise() { target = new SquareWave(); target.Format = new WaveFormat(44100, 2); }
public void TestBiQuadFilters() { Calibration.Initialize(); { //Bandpass Filtered Sine Wave, Matched Frequency IBGCStream stream = new SquareWave(1f, 400f) .BiQuadBandpassFilter(400f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "BiQuadMostThroughBandWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); } { //Bandpass Filtered Sine Wave, 2x Frequency IBGCStream stream = new SquareWave(1f, 400f) .BiQuadBandpassFilter(800f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "BiQuadTooHighBandWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); } { //Bandpass Filtered Sine Wave, Half Frequency IBGCStream stream = new SquareWave(1f, 400f) .BiQuadBandpassFilter(200f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "BiQuadTooLowBandWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); } { //Notch Filtered Square Wave, Matched Frequency IBGCStream stream = new SquareWave(1f, 400f) .BiQuadNotchFilter(400f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "BiQuadNotchFilteredSquareWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); } { //Notch Filtered Sine Wave, Matched Frequency IBGCStream stream = new SineWave(1f, 400f) .BiQuadNotchFilter(400f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "BiQuadNotchFilteredSineWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); } { //Notch Filtered Sine Wave, +10 Hz Mismatch IBGCStream stream = new SineWave(1f, 400f) .BiQuadNotchFilter(410f) .Window(DURATION) .Normalize(LEVEL); bool success = WaveEncoding.SaveStream( filepath: DataManagement.PathForDataFile("Test", "BiQuadNotchFiltered410SineWave.wav"), stream: stream, overwrite: true); Assert.IsTrue(success); } }
public Harmonic(CustomSoundProvider provider) { Sine = new SineWave(provider); Square = new SquareWave(provider); Triangle = new TriangleWave(provider); Sawtooth = new SawtoothWave(provider); Amplitude = 0.25f; }