function updateCalcLabel() {
var unit = document.getElementById('inputUnit').value;
var btn = document.querySelector('.btn-calc');
if (['Hz', 'kHz', 'MHz', 'GHz'].indexOf(unit) > -1) {
btn.innerHTML = "Calculate Period (Time)";
} else {
btn.innerHTML = "Calculate Frequency (Hz)";
}
}
function calculatePhysics() {
var valInput = document.getElementById('inputValue');
var unitSelect = document.getElementById('inputUnit');
var resultContainer = document.getElementById('resultContainer');
var mainResult = document.getElementById('mainResult');
var subResult = document.getElementById('subResult');
var resultLabel = document.getElementById('resultLabel');
var val = parseFloat(valInput.value);
var unit = unitSelect.value;
if (isNaN(val) || val === 0) {
resultContainer.style.display = 'block';
mainResult.innerHTML = "Invalid Input";
subResult.innerHTML = "Please enter a valid non-zero number.";
mainResult.style.color = "#dc3545";
return;
}
mainResult.style.color = "#28a745";
var baseValue = 0;
var resultValue = 0;
var mode = ""; // 'toPeriod' or 'toFreq'
// Determine mode based on unit
if (['Hz', 'kHz', 'MHz', 'GHz'].indexOf(unit) > -1) {
mode = 'toPeriod';
resultLabel.innerHTML = "Resulting Period (Time)";
// Convert everything to Hertz first
if (unit === 'Hz') baseValue = val;
if (unit === 'kHz') baseValue = val * 1000;
if (unit === 'MHz') baseValue = val * 1000000;
if (unit === 'GHz') baseValue = val * 1000000000;
// Calculate Period in Seconds (T = 1/f)
var periodSeconds = 1 / baseValue;
// Auto-format the result unit
var displayVal = 0;
var displayUnit = "";
if (periodSeconds >= 1) {
displayVal = periodSeconds;
displayUnit = "s";
} else if (periodSeconds >= 0.001) {
displayVal = periodSeconds * 1000;
displayUnit = "ms";
} else if (periodSeconds >= 0.000001) {
displayVal = periodSeconds * 1000000;
displayUnit = "μs";
} else {
displayVal = periodSeconds * 1000000000;
displayUnit = "ns";
}
mainResult.innerHTML = displayVal.toPrecision(6) * 1 + " " + displayUnit; // *1 removes trailing zeroes
subResult.innerHTML = "Base: " + periodSeconds.toExponential(4) + " seconds";
} else {
mode = 'toFreq';
resultLabel.innerHTML = "Resulting Frequency";
// Convert everything to Seconds first
if (unit === 's') baseValue = val;
if (unit === 'ms') baseValue = val / 1000;
if (unit === 'us') baseValue = val / 1000000;
if (unit === 'ns') baseValue = val / 1000000000;
// Calculate Frequency in Hz (f = 1/T)
var freqHz = 1 / baseValue;
// Auto-format the result unit
var displayVal = 0;
var displayUnit = "";
if (freqHz >= 1000000000) {
displayVal = freqHz / 1000000000;
displayUnit = "GHz";
} else if (freqHz >= 1000000) {
displayVal = freqHz / 1000000;
displayUnit = "MHz";
} else if (freqHz >= 1000) {
displayVal = freqHz / 1000;
displayUnit = "kHz";
} else {
displayVal = freqHz;
displayUnit = "Hz";
}
mainResult.innerHTML = displayVal.toPrecision(6) * 1 + " " + displayUnit;
subResult.innerHTML = "Base: " + freqHz.toExponential(4) + " Hz";
}
resultContainer.style.display = 'block';
}
Understanding Frequency and Period Conversions
In physics, electronics, and signal processing, the relationship between frequency and period is fundamental. These two concepts are inversely related: as one increases, the other decreases. This Frequency to Period Calculator allows you to instantly toggle between these two metrics, making it an essential tool for engineers, students, and hobbyists working with waveforms.
The Formula
The mathematical relationship between frequency ($f$) and period ($T$) is defined by the following inverse equations:
T = 1 / f
f = 1 / T
Where:
T (Period) is the time it takes for one complete cycle of a repeating event, measured in seconds (s).
f (Frequency) is the number of cycles that occur per unit of time, measured in Hertz (Hz).
How to Calculate Period from Frequency
To find the period of a wave when you know the frequency, you divide 1 by the frequency in Hertz. It is important to ensure your units are consistent.
Example 1: A standard AC power line operates at 60 Hz. The period is $1 / 60 = 0.0166$ seconds, or 16.6 milliseconds (ms).
Example 2: A processor clock runs at 1 GHz ($1,000,000,000$ Hz). The period is $1 / 1,000,000,000 = 1$ nanosecond (ns).
How to Calculate Frequency from Period
Conversely, if you know the time duration of one cycle (period), you can determine the frequency by dividing 1 by the period in seconds.
Example: If a pendulum swings back and forth once every 2 seconds, its frequency is $1 / 2 = 0.5$ Hz.
Example: If an audio wave has a cycle length of 1 millisecond ($0.001$s), its frequency is $1 / 0.001 = 1000$ Hz (1 kHz).
Common Unit Conversions
When working with high-speed electronics or slow mechanical waves, you will often encounter prefixes. Here is a quick reference guide:
1 kHz (Kilohertz) = 1,000 Hz
1 MHz (Megahertz) = 1,000,000 Hz
1 GHz (Gigahertz) = 1,000,000,000 Hz
1 ms (Millisecond) = 0.001 seconds
1 μs (Microsecond) = 0.000001 seconds
1 ns (Nanosecond) = 0.000000001 seconds
Applications
This calculator is widely used in:
Electronics: Calculating clock cycles for microcontrollers and CPUs.
Audio Engineering: determining the pitch of sound waves based on their wavelength duration.
Radio Frequency (RF): Tuning circuits and antenna design where frequency determines the wavelength.
Medical Physics: Analyzing biological rhythms, such as heart rates (beats per minute converted to Hz).