Simulink: Microphone input find frequency / FFT
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponses (0)
Voir également
Catégories
En savoir plus sur Audio Processing Algorithm Design dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!