奥さーん、これがホシかったんだろー!!
ということでFFT実行サンプルプログラムを作ってみました。
えーあー、対応していない引数の回避とか組み込んでないですが、
その太平洋を彷彿させる大きな心でご容赦ください。
ファイルもアップロードしました。
分かりにくいですがー下の方にファイルへのリンクがありますので
使ってみればいいじゃない!
■go_fft実行コード
//-----------------------------------
// sample code to execute go_fft
// ver: 1.0
//-----------------------------------
//set lib path
//Please change the following path to fit your enviroment.
getf('C:\work\scilab\go_fft.sci');
//generate test wave
fs = 10000;
f_1 = 1250;
f_2 = 2500;
n = [1:1:8192];
sine_1 = 0.5 * sin(2*%pi*(f_1/fs)*n);
sine_2 = 0.25 * sin(2*%pi*(f_2/fs)*n);
input_wave = sine_1 + sine_2;
//go fft
[amp f] = go_fft(input_wave, fs, 're', 'lnr'); //plot in linear unit
//[amp f] = go_fft(input_wave, fs, 're', 'dB'); //plot in dB unit
//[amp f] = go_fft(input_wave, fs, 'hn', 'lnr'); //use hanning window
//[amp f] = go_fft(input_wave, fs, 'hm', 'lnr'); //use hamming window
//display fft result
plot(f, amp);
xgrid; //grid on
■go_fft本体
//---------------------------------------
// go_fft.sci
// calculate fft on scilab
// ver : 1.0
//---------------------------------------
function [amp, frequency]=go_fft(input_data, fs, win_sel, out_form)
printf("===== go_fft =====\n");
printf(" window = %s\n", win_sel);
printf(" out form = %s\n", out_form);
//get input length
input_length = length(input_data);
printf(" input_length = %d\n", input_length);
//output length
out_length = input_length/2;
//windowing
if win_sel == 'hn'
window_adjust_coef = 0.5;
elseif win_sel == 'hm'
window_adjust_coef = 0.54;
else
window_adjust_coef = 1;
end
win_l = window(win_sel, input_length);
printf(" window_adjust_coef = %f\n",window_adjust_coef);
if win_sel ~= 're'
input_windowing = input_data .* win_l;
else
input_windowing = input_data;
end
//fft process
res_cmp = fft(input_windowing);
//res_cmp = fft(input_data);
res_abs = abs(res_cmp)*(2/input_length);
res_lnr = res_abs/window_adjust_coef;
//convert dB unit
res_db = 20 * log10(res_lnr);
if out_form == 'dB'
result = res_db;
elseif out_form == 'lnr'
result = res_lnr;
elseif out_form == 'abs'
result = res_abs;
elseif out_form == 'cmp'
result = res_cmp;
else
result = res_db;
end
amp = result(1:out_length);
//generate frequency
freq_points = [0:1:out_length-1];
frequency = (fs/input_length) * freq_points;
printf("==================");
endfunction
最終更新:2009年08月01日 21:29