How to extract ENF (Electrical Network Frequency) form audio signal. I want extracted ENF pattern from the audio signal using MATLAB code

10 views (last 30 days)
% STFT anaysis of 50 Hz siganl present in audio signal
clc, clear all, close all;
[x, fs] = audioread('Record_Trans.wav'); % get the samples of the .wav file
x = x(:, 1); % get the first channel
xmax = max(abs(x)); % find the maximum abs value
x = x/xmax; % scalling the signal
% define analysis parameters
wlen = 8192;
n = round(log2(wlen));
nfft = 2^n;
% define filter parameters
fn = fs/2;
fc = 50;
Fc=fc/fn;
[c,d]=butter(3,Fc);
z = filter(c,d,x);
N = 3;
w1 = 49/fn;
w2 = 51/fn;
Wp = [w1 w2];
[b,a] = butter(N,Wp); %butterworth bandpass filter of bw = 2 Hz
y = filter(b,a,x);
spectrogram(y,wlen,4096,nfft,fs,'yaxis');
axis([0.1 90 .1 100]); axis xy; colormap(jet); view(0,90);
This code will plot the spectrogram of the filtered audio sgnal containing electrical network frequency (ENF) 50 Hz. But I want the frequency vs time plot not spectrogram. Can anyone knows how to extract ENF from audio signal.

Answers (1)

Wayne King
Wayne King on 20 Jul 2014
Edited: Wayne King on 20 Jul 2014
Do you just want to plot frequency vs. time for a single frequency component, for example 50 Hz?
In that case, you can simply extract the row in the short-time Fourier transform matrix and plot that row against time.
For example, I'll create a signal sampled at 1000 Hz with a 200-Hz component that occurs between 1 and 3 seconds:
Fs = 1000;
t = 0:1/Fs:5-1/Fs;
x = cos(2*pi*200*t).*(t>1 & t<3)+randn(size(t));
[STFT,F,T,P] = spectrogram(x,250,200,250,Fs);
The frequency spacing above is 4 Hz (Fs/250) so we know that 200 Hz will be located in bin 51 (the first bin is for zero frequency).
plot(T,10*log10(P(51,:)))
You see that the short-time periodogram has captured that the 200-Hz component is "on" for 1 < t <3
  2 Comments
Hemant Nagvanshi
Hemant Nagvanshi on 20 Jul 2014
Edited: Walter Roberson on 29 Sep 2015
[STFT,F,T,P] = spectrogram(x,250,200,250,Fs);
x - signal
what about
250
200
250
what are they
Is
250 - window length
200 - noverlap
250 - ???
Wayne King
Wayne King on 20 Jul 2014
This is documented in the spectrogram help, 250 is the NFFT, I kept it at 250 because that makes my frequency of interest (200 Hz) in this example fall directly on a DFT bin.

Sign in to comment.

Categories

Find more on Time-Frequency Analysis in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!