Simulink: Microphone input find frequency / FFT
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi, i am totally new to matlab / simulink and i need help. I want to create a guitar tuner, but i am struggling with analyzing the input signal correctly.
i have got some code to find the frequency of a generated signal:
Fs = 96000;
t = linspace(0,1,Fs);
x = cos(2*pi*4999*t)+randn(size(t));
xdft = fft(x);
fftabs = abs(xdft(1:length(x)/2+1));
freq = 0:Fs/length(x):(Fs/2);
[~,maxindex] = max(fftabs);
mx = freq(maxindex);
fprintf('The maximum occurs at %2.1f Hz\n',mx );
this works perfectly fine, but when i replace the generated signal with the real microphone input i got some strange results.
I created a MATLAB function block with a modified version of the code above:
function res = fcn(x)
Fs = 96000;
xdft = fft(x);
fftabs = abs(xdft(1:length(x)/2+1));
freq = 0:Fs/length(x):(Fs/2);
[~,maxindex] = max(fftabs);
mx = freq(maxindex);
res = fftabs;
fprintf('The maximum occurs at %2.1f Hz\n',mx );
end
in the following picture you see my current model.

For example, when I play the sound of the note "A" (440 Hertz) into the microphone, I somehow get 653hz as result and not the expectet 440hz. Does anybody know what the problem is?
Thanks! Matthias
0 Kommentare
Antworten (0)
Siehe auch
Kategorien
Mehr zu Audio Processing Algorithm Design finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!