<!DOCTYPE html>
<html lang="id">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Filter Elektro - MALIK89</title>
<style>
*{margin:0;padding:0;box-sizing:border-box;font-family:Arial,sans-serif}
body{background:#0f172a;color:#fff;padding:14px}
header{text-align:center;margin-bottom:12px}
header b{font-size:24px} header b span{color:#FFC107}
header p{color:#94a3b8;font-size:13px;margin-top:4px}
.tabs{display:flex;gap:8px;justify-content:center;margin-bottom:14px}
.tab{flex:1;padding:12px;border-radius:12px;border:none;font-weight:bold;cursor:pointer;background:#1e293b;color:#fff}
.tab.active{background:#FFC107;color:#000}
.card{background:#1e293b;border-radius:16px;padding:16px;margin-bottom:14px}
.card h3{margin-bottom:8px}
.card p{font-size:13px;color:#cbd5e1;line-height:1.5}
.rangkaian{background:#fff;border-radius:12px;padding:10px;text-align:center;margin:10px 0;color:#000}
.rangkaian svg{width:100%;max-width:480px;height:auto}
label{font-size:13px;font-weight:bold;display:block;margin-top:12px}
input[type=range]{width:100%;accent-color:#FFC107}
.val{display:flex;justify-content:space-between;font-size:13px;margin-top:4px}
.hasil{background:#FFC107;color:#000;border-radius:12px;padding:14px;text-align:center;margin-top:14px}
.hasil b{font-size:28px}
canvas{background:#fff;border-radius:12px;width:100%;height:180px;margin-top:10px}
table{width:100%;border-collapse:collapse;margin-top:10px;font-size:13px}
td,th{border:1px solid #334155;padding:8px;text-align:left}
th{background:#0f172a}
.formula{background:#0f172a;padding:12px;border-radius:10px;font-size:13px;line-height:1.6;margin-top:10px}
.kaki{font-size:11px;text-align:center;color:#64748b;margin-top:10px}
button{width:100%;padding:12px;border:none;border-radius:12px;background:#25D366;color:#fff;font-weight:bold;margin-top:10px;cursor:pointer}
</style>
</head>
<body>
<header><b>MALIK<span>89</span> ELEKTRO</b><p>Simulator Low Pass - High Pass - Band Pass Filter (RC Pasif)</p></header>
<div class="tabs">
<button class="tab active" id="tabLPF" onclick="pilih('LPF')">🔻 LOW PASS</button>
<button class="tab" id="tabHPF" onclick="pilih('HPF')">🔺 HIGH PASS</button>
<button class="tab" id="tabBPF" onclick="pilih('BPF')">🔶 BAND PASS</button>
</div>
<div class="card">
<h3 id="judul">🔻 LOW PASS FILTER (LPF)</h3>
<p id="deskripsi">Meloloskan frekuensi RENDAH, menahan frekuensi TINGGI. Contoh: untuk speaker bass / subwoofer, menghilangkan noise tinggi.</p>
<div class="rangkaian" id="diagram"></div>
<div class="formula" id="rumus">
<b>Rumus:</b> fc = 1 / (2 × Ï€ × R × C)<br>
<b>Komponen:</b> R seri dengan input, C paralel ke output (ke ground).<br>
<b>Cara Kerja:</b> Frekuensi rendah → C seperti rangkaian terbuka → sinyal lolos. Frekuensi tinggi → C seperti short ke ground → sinyal dibuang.
</div>
<label>🔧 Resistor (R) : <span id="labelR">10 kΩ</span></label>
<input type="range" id="sliderR" min="100" max="100000" step="100" value="10000" oninput="hitung()">
<div class="val"><span>100 Ω</span><span>100 kΩ</span></div>
<label>🔋 Kapasitor (C) : <span id="labelC">100 nF</span></label>
<input type="range" id="sliderC" min="1" max="1000" step="1" value="100" oninput="hitung()">
<div class="val"><span>1 nF</span><span>1000 nF = 1 µF</span></div>
<div id="extraBPF" style="display:none">
<label>🔧 Resistor 2 (R2 untuk HPF) : <span id="labelR2">10 kΩ</span></label>
<input type="range" id="sliderR2" min="100" max="100000" step="100" value="10000" oninput="hitung()">
<label>🔋 Kapasitor 2 (C2 untuk HPF) : <span id="labelC2">10 nF</span></label>
<input type="range" id="sliderC2" min="1" max="1000" step="1" value="10" oninput="hitung()">
</div>
<div class="hasil">
<div id="labelHasil">FREKUENSI CUT-OFF (fc)</div>
<b id="hasilFc">159.15 Hz</b>
<div id="hasilDetail" style="font-size:13px;margin-top:4px">R = 10 kΩ | C = 100 nF</div>
</div>
<canvas id="grafik" width="600" height="200"></canvas>
<table>
<tr><th>Frekuensi Input</th><th>Output</th><th>Keterangan</th></tr>
<tbody id="tabel"></tbody>
</table>
<button onclick="alert('Rangkaian ini dibuat untuk belajar. R = Resistor, C = Kapasitor. Gunakan R & C sesuai hitungan fc di atas!')">📥 SIMPAN HASIL / CATAT RANGKAIAN</button>
</div>
<div class="card">
<h3>📚 Perbandingan Cepat</h3>
<table>
<tr><th>Filter</th><th>Diloloskan</th><th>Ditahan</th><th>Contoh Pakai</th></tr>
<tr><td><b>LPF</b></td><td>Rendah</td><td>Tinggi</td><td>Subwoofer, Anti-noise</td></tr>
<tr><td><b>HPF</b></td><td>Tinggi</td><td>Rendah</td><td>Twitter, Hilangkan dengung 50Hz</td></tr>
<tr><td><b>BPF</b></td><td>Tengah saja</td><td>Rendah & Tinggi</td><td>Radio, Equalizer, Sensor</td></tr>
</table>
</div>
<p class="kaki">MALIK89.COM - Teknik Elektro Dasar | Rumus fc = 1 / (2Ï€RC)</p>
<script>
let jenis='LPF';
function pilih(j){
jenis=j;
document.querySelectorAll('.tab').forEach(e=>e.classList.remove('active'));
document.getElementById('tab'+j).classList.add('active');
document.getElementById('extraBPF').style.display = (j==='BPF')?'block':'none';
if(j==='LPF'){document.getElementById('judul').textContent='🔻 LOW PASS FILTER (LPF)';document.getElementById('deskripsi').textContent='Meloloskan frekuensi RENDAH, menahan frekuensi TINGGI. Contoh: untuk speaker bass / subwoofer, menghilangkan noise tinggi.'}
if(j==='HPF'){document.getElementById('judul').textContent='🔺 HIGH PASS FILTER (HPF)';document.getElementById('deskripsi').textContent='Meloloskan frekuensi TINGGI, menahan frekuensi RENDAH. Contoh: untuk speaker tweeter, menghilangkan dengung / hum 50Hz.'}
if(j==='BPF'){document.getElementById('judul').textContent='🔶 BAND PASS FILTER (BPF)';document.getElementById('deskripsi').textContent='Meloloskan frekuensi TENGAH saja. Gabungan HPF + LPF. Contoh: untuk radio, equalizer, sensor suara.'}
hitung();
}
function formatR(v){ if(v>=1000) return (v/1000)+' kΩ'; return v+' Ω'; }
function formatC(v){ if(v>=1000) return '1 µF'; if(v>=100) return v+' nF'; return v+' nF'; }
function hitung(){
let R=parseFloat(document.getElementById('sliderR').value);
let CnF=parseFloat(document.getElementById('sliderC').value);
let C=CnF*1e-9;
let R2=parseFloat(document.getElementById('sliderR2').value);
let C2nF=parseFloat(document.getElementById('sliderC2').value);
let C2=C2nF*1e-9;
document.getElementById('labelR').textContent=formatR(R);
document.getElementById('labelC').textContent=formatC(CnF);
document.getElementById('labelR2').textContent=formatR(R2);
document.getElementById('labelC2').textContent=formatC(C2nF);
let fc=1/(2*Math.PI*R*C);
let fc1=1/(2*Math.PI*R2*C2); // untuk HPF di BPF
let fc2=fc; // untuk LPF di BPF
let html='';
if(jenis==='LPF'){
html=`<svg viewBox="0 0 480 160"><text x="10" y="20" font-size="13" font-weight="bold">Vin ~</text><line x1="40" y1="60" x2="120" y2="60" stroke="#000" stroke-width="2"/><rect x="120" y="45" width="90" height="30" fill="#fff" stroke="#000" stroke-width="2"/><text x="135" y="65" font-size="13">R = ${formatR(R)}</text><line x1="210" y1="60" x2="340" y2="60" stroke="#000" stroke-width="2"/><circle cx="340" cy="60" r="4" fill="#000"/><line x1="340" y1="60" x2="340" y2="110" stroke="#000" stroke-width="2"/><line x1="320" y1="110" x2="360" y2="110" stroke="#000" stroke-width="2"/><line x1="325" y1="118" x2="355" y2="118" stroke="#000" stroke-width="2"/><text x="310" y="140" font-size="12">C = ${formatC(CnF)}</text><line x1="340" y1="60" x2="430" y2="60" stroke="#000" stroke-width="2"/><text x="430" y="20" font-size="13" font-weight="bold">Vout</text><line x1="40" y1="130" x2="430" y2="130" stroke="#000" stroke-width="2"/><text x="200" y="150" font-size="11">GND ─────────────</text></svg><div style="font-size:12px">Vin → <b>R seri</b> → Vout | <b>C paralel</b> dari Vout ke GND</div>`;
document.getElementById('hasilFc').textContent=fc.toFixed(2)+' Hz';
document.getElementById('hasilDetail').textContent=`R = ${formatR(R)} | C = ${formatC(CnF)}`;
document.getElementById('rumus').innerHTML=`<b>Rumus:</b> fc = 1 / (2 × Ï€ × R × C) = 1 / (2 × 3.14 × ${formatR(R)} × ${formatC(CnF)}) = <b>${fc.toFixed(2)} Hz</b><br><b>Komponen:</b> R seri, C paralel ke ground.<br><b>Cara Kerja:</b> Frekuensi < fc → Lolos. Frekuensi > fc → Ditahan / dibuang ke ground.`;
}
if(jenis==='HPF'){
html=`<svg viewBox="0 0 480 160"><text x="10" y="20" font-size="13" font-weight="bold">Vin ~</text><line x1="40" y1="60" x2="100" y2="60" stroke="#000" stroke-width="2"/><line x1="100" y1="45" x2="100" y2="75" stroke="#000" stroke-width="2"/><line x1="130" y1="45" x2="130" y2="75" stroke="#000" stroke-width="2"/><line x1="100" y1="60" x2="130" y2="60" stroke="#000" stroke-width="0"/><text x="90" y="95" font-size="12">C = ${formatC(CnF)}</text><line x1="130" y1="60" x2="340" y2="60" stroke="#000" stroke-width="2"/><line x1="340" y1="60" x2="340" y2="110" stroke="#000" stroke-width="2"/><rect x="315" y="105" width="50" height="20" fill="#fff" stroke="#000"/><text x="320" y="119" font-size="11">R ${formatR(R)}</text><line x1="340" y1="60" x2="430" y2="60" stroke="#000" stroke-width="2"/><text x="430" y="20" font-size="13" font-weight="bold">Vout</text><line x1="40" y1="130" x2="430" y2="130" stroke="#000" stroke-width="2"/><text x="200" y="150" font-size="11">GND ─────────────</text></svg><div style="font-size:12px">Vin → <b>C seri</b> → Vout | <b>R paralel</b> dari Vout ke GND</div>`;
document.getElementById('hasilFc').textContent=fc.toFixed(2)+' Hz';
document.getElementById('hasilDetail').textContent=`C = ${formatC(CnF)} | R = ${formatR(R)}`;
document.getElementById('rumus').innerHTML=`<b>Rumus:</b> fc = 1 / (2 × Ï€ × R × C) = <b>${fc.toFixed(2)} Hz</b><br><b>Komponen:</b> C seri, R paralel ke ground (kebalikan LPF).<br><b>Cara Kerja:</b> Frekuensi > fc → Lolos. Frekuensi < fc → Ditahan. Kapasitor menahan DC & frekuensi rendah.`;
}
if(jenis==='BPF'){
// BPF = HPF (R2,C2) + LPF (R,C)
let fL=Math.min(fc1,fc2), fH=Math.max(fc1,fc2);
html=`<svg viewBox="0 0 480 170"><text x="5" y="20" font-size="12" font-weight="bold">Vin ~</text><line x1="35" y1="60" x2="75" y2="60" stroke="#000" stroke-width="2"/><line x1="75" y1="45" x2="75" y2="75" stroke="#000" stroke-width="2"/><line x1="95" y1="45" x2="95" y2="75" stroke="#000" stroke-width="2"/><text x="60" y="95" font-size="10">C2 ${formatC(C2nF)}</text><line x1="95" y1="60" x2="170" y2="60" stroke="#000" stroke-width="2"/><line x1="170" y1="60" x2="170" y2="110" stroke="#000" stroke-width="2"/><rect x="150" y="105" width="40" height="18" fill="#fff" stroke="#000"/><text x="152" y="117" font-size="9">R2</text><line x1="170" y1="60" x2="230" y2="60" stroke="#000" stroke-width="2"/><rect x="230" y="45" width="70" height="30" fill="#fff" stroke="#000" stroke-width="2"/><text x="235" y="65" font-size="10">R ${formatR(R)}</text><line x1="300" y1="60" x2="370" y2="60" stroke="#000" stroke-width="2"/><line x1="370" y1="60" x2="370" y2="110" stroke="#000" stroke-width="2"/><line x1="355" y1="110" x2="385" y2="110" stroke="#000" stroke-width="2"/><line x1="360" y1="118" x2="380" y2="118" stroke="#000" stroke-width="2"/><text x="350" y="140" font-size="10">C ${formatC(CnF)}</text><line x1="370" y1="60" x2="430" y2="60" stroke="#000" stroke-width="2"/><text x="430" y="20" font-size="12" font-weight="bold">Vout</text><line x1="35" y1="135" x2="430" y2="135" stroke="#000" stroke-width="2"/><text x="200" y="155" font-size="11">GND ─────────────</text></svg><div style="font-size:12px"><b>HPF dulu</b> (C2 seri + R2 ke GND) → <b>LPF</b> (R seri + C ke GND) = Band Pass</div>`;
document.getElementById('hasilFc').textContent=`${fL.toFixed(1)} Hz - ${fH.toFixed(1)} Hz`;
document.getElementById('hasilDetail').textContent=`f Low = ${fL.toFixed(1)} Hz | f High = ${fH.toFixed(1)} Hz | Bandwidth = ${(fH-fL).toFixed(1)} Hz`;
document.getElementById('rumus').innerHTML=`<b>Rumus BPF:</b> f<sub>L</sub> (HPF) = 1/(2Ï€×R2×C2) = <b>${fc1.toFixed(2)} Hz</b><br>f<sub>H</sub> (LPF) = 1/(2Ï€×R×C) = <b>${fc2.toFixed(2)} Hz</b><br><b>Syarat:</b> f<sub>L</sub> harus LEBIH KECIL dari f<sub>H</sub> agar ada pita yang lolos. Bandwidth = f<sub>H</sub> - f<sub>L</sub> = <b>${(fH-fL).toFixed(2)} Hz</b>`;
}
document.getElementById('diagram').innerHTML=html;
gambarGrafik(fc,fc1,fc2);
isiTabel(fc,fc1,fc2);
}
function gambarGrafik(fc,fc1,fc2){
let cv=document.getElementById('grafik'); let c=cv.getContext('2d');
c.clearRect(0,0,600,200);
c.strokeStyle='#cbd5e1'; c.strokeRect(40,10,540,150);
c.fillStyle='#000'; c.font='11px Arial'; c.fillText('Vout / Vin',5,20); c.fillText('1.0',5,25); c.fillText('0.707 (-3dB)',5,70); c.fillText('0',5,155);
c.fillText('10 Hz',40,175); c.fillText('100 Hz',150,175); c.fillText('1k Hz',280,175); c.fillText('10k Hz',410,175); c.fillText('100k Hz',520,175);
c.beginPath(); c.strokeStyle='#e94560'; c.lineWidth=2;
for(let x=0;x<=540;x++){
let logf=1+ (x/540)*5; // 10^1 s/d 10^6
let f=Math.pow(10,logf);
let gain=0;
if(jenis==='LPF') gain=1/Math.sqrt(1+Math.pow(f/fc,2));
if(jenis==='HPF') gain=1/Math.sqrt(1+Math.pow(fc/f,2));
if(jenis==='BPF'){ let fL=Math.min(fc1,fc2), fH=Math.max(fc1,fc2); let g1=1/Math.sqrt(1+Math.pow(fL/f,2)); let g2=1/Math.sqrt(1+Math.pow(f/fH,2)); gain=g1*g2; }
let y=160 - gain*140;
if(x===0) c.moveTo(40+x,y); else c.lineTo(40+x,y);
}
c.stroke();
// garis -3dB
c.setLineDash([5,5]); c.strokeStyle='#94a3b8'; c.beginPath(); c.moveTo(40,160-0.707*140); c.lineTo(580,160-0.707*140); c.stroke(); c.setLineDash([]);
c.fillStyle='#e94560'; c.fillText('-3dB = fc',430,60);
}
function isiTabel(fc,fc1,fc2){
let tb=document.getElementById('tabel');
let frek=[10,100,1000,10000,100000];
let rows='';
frek.forEach(f=>{
let gain, ket;
if(jenis==='LPF'){ gain=1/Math.sqrt(1+Math.pow(f/fc,2)); ket = f<fc?'✅ LOLOS (Rendah)':'❌ DITAHAN (Tinggi)'; }
if(jenis==='HPF'){ gain=1/Math.sqrt(1+Math.pow(fc/f,2)); ket = f>fc?'✅ LOLOS (Tinggi)':'❌ DITAHAN (Rendah)'; }
if(jenis==='BPF'){ let fL=Math.min(fc1,fc2), fH=Math.max(fc1,fc2); let g1=1/Math.sqrt(1+Math.pow(fL/f,2)); let g2=1/Math.sqrt(1+Math.pow(f/fH,2)); gain=g1*g2; ket = (f>fL && f<fH)?'✅ LOLOS (Tengah)':'❌ DITAHAN'; }
rows+=`<tr><td>${f} Hz</td><td>${(gain*100).toFixed(1)} %</td><td>${ket}</td></tr>`;
});
tb.innerHTML=rows;
}
hitung();
</script>
</body>
</html>
Tidak ada komentar:
Posting Komentar