viewof shaftSpeed = Inputs.range([10, 100], {
label: "Shaft Speed (Hz):",
step: 5,
value: 30
})
viewof defectType = Inputs.select(
["Imbalance", "Misalignment", "Bearing - BPFO", "Bearing - BPFI", "Looseness"],
{
label: "Defect Type:",
value: "Imbalance"
}
)
bearingParams = {
const ballDiameter = 0.5; // inches
const pitchDiameter = 3.0; // inches
const ballCount = 8;
const contactAngle = 0; // degrees
const beta = Math.cos(contactAngle * Math.PI / 180);
const BPFO = (ballCount / 2) * (1 - (ballDiameter / pitchDiameter) * beta);
const BPFI = (ballCount / 2) * (1 + (ballDiameter / pitchDiameter) * beta);
const BSF = (pitchDiameter / (2 * ballDiameter)) * (1 - Math.pow((ballDiameter / pitchDiameter) * beta, 2));
return { BPFO, BPFI, BSF };
}
vibrationSignal = {
const samples = 1000;
const samplingRate = shaftSpeed * 100;
const time = Array.from({length: samples}, (_, i) => i / samplingRate);
let frequency;
let amplitude = 1.0;
let harmonics = [];
switch(defectType) {
case "Imbalance":
frequency = shaftSpeed;
harmonics = [{freq: shaftSpeed, amp: 1.0}];
break;
case "Misalignment":
frequency = 2 * shaftSpeed;
harmonics = [
{freq: shaftSpeed, amp: 0.3},
{freq: 2 * shaftSpeed, amp: 1.0},
{freq: 3 * shaftSpeed, amp: 0.2}
];
break;
case "Bearing - BPFO":
frequency = shaftSpeed * bearingParams.BPFO;
harmonics = [
{freq: shaftSpeed * bearingParams.BPFO, amp: 1.0},
{freq: shaftSpeed * bearingParams.BPFO * 2, amp: 0.5},
{freq: shaftSpeed * bearingParams.BPFO * 3, amp: 0.3}
];
break;
case "Bearing - BPFI":
frequency = shaftSpeed * bearingParams.BPFI;
harmonics = [
{freq: shaftSpeed * bearingParams.BPFI, amp: 1.0},
{freq: shaftSpeed * bearingParams.BPFI * 2, amp: 0.6},
{freq: shaftSpeed * bearingParams.BPFI * 3, amp: 0.4}
];
break;
case "Looseness":
harmonics = [
{freq: shaftSpeed, amp: 0.8},
{freq: 2 * shaftSpeed, amp: 0.6},
{freq: 3 * shaftSpeed, amp: 0.4},
{freq: 5 * shaftSpeed, amp: 0.3},
{freq: 0.5 * shaftSpeed, amp: 0.5}
];
break;
}
const signal = time.map(t => {
let value = 0;
harmonics.forEach(h => {
value += h.amp * Math.sin(2 * Math.PI * h.freq * t);
});
// Add noise
value += (Math.random() - 0.5) * 0.1;
return value;
});
return time.map((t, i) => ({time: t, amplitude: signal[i]}));
}
fftData = {
const signal = vibrationSignal.map(d => d.amplitude);
const n = signal.length;
const frequencies = Array.from({length: Math.floor(n/2)}, (_, i) => i * (shaftSpeed * 100) / n);
// Simple magnitude calculation (approximation)
const magnitudes = frequencies.map((f, i) => {
let sum = 0;
for(let k = 0; k < n; k++) {
sum += signal[k] * Math.cos(2 * Math.PI * f * k / (shaftSpeed * 100));
}
return Math.abs(sum) / n;
});
return frequencies.map((f, i) => ({frequency: f, magnitude: magnitudes[i]}))
.filter(d => d.frequency <= shaftSpeed * 10); // Show up to 10x shaft speed
}
html`<div style="display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin: 20px 0;">
<div>
<h4 style="color: #2C3E50; margin-bottom: 10px;">Time Domain</h4>
${Plot.plot({
width: 400,
height: 250,
x: {label: "Time (seconds)", grid: true},
y: {label: "Amplitude", domain: [-2, 2]},
marks: [
Plot.line(vibrationSignal.slice(0, 200), {x: "time", y: "amplitude", stroke: "#16A085", strokeWidth: 1.5}),
Plot.ruleY([0])
]
})}
</div>
<div>
<h4 style="color: #2C3E50; margin-bottom: 10px;">Frequency Domain (FFT)</h4>
${Plot.plot({
width: 400,
height: 250,
x: {label: "Frequency (Hz)", grid: true},
y: {label: "Magnitude"},
marks: [
Plot.line(fftData, {x: "frequency", y: "magnitude", stroke: "#E67E22", strokeWidth: 1.5}),
Plot.ruleX([shaftSpeed], {stroke: "#2C3E50", strokeDasharray: "4 4"}),
Plot.text([{x: shaftSpeed, y: 0}], {
x: "x",
y: "y",
text: ["1x"],
dy: -10,
fill: "#2C3E50",
fontSize: 10
})
]
})}
</div>
</div>`