feat: 支持修改单位
This commit is contained in:
@@ -1,26 +1,42 @@
|
||||
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 };
|
||||
type WaveformDataType = {
|
||||
x: number[];
|
||||
y: number[][];
|
||||
xUnit: "s" | "ms" | "us";
|
||||
yUnit: "V" | "mV" | "uV";
|
||||
};
|
||||
|
||||
export { WaveformDisplay, generateTestData };
|
||||
// Test data generator
|
||||
function generateTestData(): WaveformDataType {
|
||||
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, xUnit: "ms", yUnit: "V" };
|
||||
}
|
||||
|
||||
export { WaveformDisplay, generateTestData , type WaveformDataType };
|
||||
|
||||
Reference in New Issue
Block a user