Simulink: Microphone input find frequency / FFT
2 views (last 30 days)
Show older comments
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 Comments
Answers (0)
See Also
Categories
Find more on Audio Processing Algorithm Design in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!