feat: 实现简易示波器功能
This commit is contained in:
26
src/components/Oscilloscope/index.ts
Normal file
26
src/components/Oscilloscope/index.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import WaveformDisplay from "./WaveformDisplay.vue";
|
||||
|
||||
// Test data generator
|
||||
const generateTestData = () => {
|
||||
const sampleRate = 1000; // 1kHz
|
||||
const duration = 0.1; // 10ms
|
||||
const points = Math.floor(sampleRate * duration);
|
||||
|
||||
const x = Array.from({ length: points }, (_, i) => i / sampleRate * 1000); // time in ms
|
||||
|
||||
// Generate multiple channels with different waveforms
|
||||
const y = [
|
||||
// Channel 1: Sine wave 50Hz
|
||||
Array.from({ length: points }, (_, i) => Math.sin(2 * Math.PI * 50 * i / sampleRate) * 3.3),
|
||||
// Channel 2: Square wave 25Hz
|
||||
Array.from({ length: points }, (_, i) => Math.sign(Math.sin(2 * Math.PI * 25 * i / sampleRate)) * 5),
|
||||
// Channel 3: Sawtooth wave 33Hz
|
||||
Array.from({ length: points }, (_, i) => (2 * ((33 * i / sampleRate) % 1) - 1) * 2.5),
|
||||
// Channel 4: Noise + DC offset
|
||||
Array.from({ length: points }, () => Math.random() * 0.5 + 1.5)
|
||||
];
|
||||
|
||||
return { x, y };
|
||||
};
|
||||
|
||||
export { WaveformDisplay, generateTestData };
|
||||
Reference in New Issue
Block a user