How to extract ENF from audio in matlab?

7 views (last 30 days)
振贤 倪
振贤 倪 on 23 Mar 2021
Answered: Suraj Kumar on 18 Mar 2025
I am working ENF (electric network frequency) of audio signal..
but I do not how to calculate ENF in matlab..
The process is in following paper (I'm Listening to your Location! Inferring User Location with Acoustic Side Channels, in section 2.2)
please help me...
Thanks a lot !!

Answers (1)

Suraj Kumar
Suraj Kumar on 18 Mar 2025
The ENF is typically embedded in audio files due to the electromagnetic interference from power lines.
Following are the steps which can help you to extract it from the audio files:
1. You can preprocess your audio signal to enhance the ENF component. This involves filtering the signal to focus on the expected ENF range .
2. Use STFT to transform your signal into the frequency domain over time. This will help you observe the frequency components of the signal.
3. Then identify the frequency component that corresponds to the ENF in each time frame.
You can refer to the following MATLAB script to get more insights:
[audio, fs] = audioread('your_audio_file.wav');
% Parameters
window_size = 4096;
overlap = window_size / 2;
nfft = 8192;
% Short-Time Fourier Transform (STFT)
[S, F, T] = stft(audio, fs, 'Window', hamming(window_size), 'OverlapLength', overlap, 'FFTLength', nfft);
enf_range = [45, 55];
freq_indices = find(F >= enf_range(1) & F <= enf_range(2));
% Extract the ENF component
enf_magnitude = abs(S(freq_indices, :));
[~, max_indices] = max(enf_magnitude, [], 1);
enf_frequencies = F(freq_indices(max_indices));
% Plot the estimated ENF over time
figure;
plot(T, enf_frequencies);
xlabel('Time (s)');
ylabel('Frequency (Hz)');
title('Estimated ENF Over Time');
grid on;
For more information on the "stft" function in MATLAB, you can refer to the following documentation:
Happy Coding!

Categories

Find more on Audio Processing Algorithm Design in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!