Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

### Test Program for F0 Estimation

The following test program generates a harmonic signal and uses f0est to determine the fundamental frequency, first with all harmonics present, and second with the fundamental suppressed by a notch filter.

```% Tested using Octave 3.0.0, Aug 2008

clear all;

f0 = 440;    % true fundamental frequency
n = 1:200;   % time in samples
fs = 10000;  % sampling rate

N = length(n);
fund = sin(2*pi*f0*n/fs); % sine at fundamental frequency
npartials = 7;
sig = zeros(1,N);
for k=1:npartials
ampk = 1 / k^2; % give a natural roll-off
sig = sig + ampk * sin(2*pi*k*f0*n/fs);
end
%rmsnoise = 0.01;
rmsnoise = 0.0;
sig = sig + rmsnoise * randn(1,N); % add some noise for realism

framesize = N;
minlevel = -60; % Lowest relative partial amplitude to accept
% (-40 good with Hamming window family)
% (-60 good with Blackman window family)
debug = 0;
f0 = f0est(sig,fs,framesize,npartials,minlevel,debug)
% Trick to leave all internal f0est variables defined
% (comment-out first line of f0est.m declaring the function):
% nargin = 6; f0est;

% Notch out fundamental and repeat:
b1 = -2*cos(2*pi*f0/fs);
sig = filter([1 b1 1],1,sig);
f0 = f0est(sig,fs,framesize,npartials,minlevel,debug)

% Example output:
% f0 =  439.99
% f0 =  437.50
```

Next  |  Prev  |  Up  |  Top  |  Index  |  JOS Index  |  JOS Pubs  |  JOS Home  |  Search

[How to cite this work]  [Order a printed hardcopy]  [Comment on this page via email]
{"ft_lang_label":"__label__en","ft_lang_prob":0.58621174,"math_prob":0.98731846,"size":1209,"snap":"2021-04-2021-17","text_gpt3_token_len":369,"char_repetition_ratio":0.11452282,"word_repetition_ratio":0.0,"special_character_ratio":0.34077752,"punctuation_ratio":0.19607843,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.97026724,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-27T20:20:44Z\",\"WARC-Record-ID\":\"<urn:uuid:5f957c8d-24b2-4236-867c-24ea1f5e0538>\",\"Content-Length\":\"11021\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:06b3c72e-34ef-4f10-a306-38648ed14639>\",\"WARC-Concurrent-To\":\"<urn:uuid:9d578c1c-b520-46d1-b9de-d11c59e87cc7>\",\"WARC-IP-Address\":\"171.64.197.141\",\"WARC-Target-URI\":\"https://ccrma.stanford.edu/~jos/sasp/Test_Program_F0_Estimation.html\",\"WARC-Payload-Digest\":\"sha1:URMUKO4O6UFJVCTCEV2W7DIIJ5AGSYKO\",\"WARC-Block-Digest\":\"sha1:OIA7LJTXWWEEPO2TEDJZCKLRYOQ4GPPU\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610704832583.88_warc_CC-MAIN-20210127183317-20210127213317-00342.warc.gz\"}"}