I have a basic knowledge of the fast Fourier and that it transforms the time domain into frequency domain to get all the frequency samples found in a signal or recorded sound ...
i want to create an application that detects all the frequencies in a recorded piano piece and match them with originally detected piano notes and if it catches a match will write the piano sheet based on this concept ... i have this code but i am not sure whether it doesn't work fine ...
The C middle note has originally on a grand piano Frequency of 261.7 but when i use it the output changes over the amplitude of the voice (Ex: 261/262/270 ...etc )
[x,Fs]= readaudio('c4,wav');
xdft = fft(readaudio(c4.wav);
[~,index] = sort(abs(xdft() , 'descend'));
(index(1)*Fs)/length(x) - (fs/length(x));
Also i have tried to implement such code visiting many questions and forums but i don't know how to apply it to my idea in general.(here is the code )
[y,Fs] =audioread('49.wav');
fcuts = [430 438 442 450]; % Frequency Vector (Hz)
mags = [0 1 0]; % Magnitude (Defines Passbands & Stopbands)
devs = [0.05 0.01 0.05]; % Allowable Deviations
[n,Wn,beta,ftype] = kaiserord(fcuts,mags,devs,Fs);
n = n + rem(n,2);
hh = fir1(n,Wn,ftype,kaiser(n+1,beta),'scale');
figure(1)
freqz(hh, 1, 2^14, Fs)
set(subplot(2,1,1), 'XLim', [0 500])% Set Frequency Axis To Show0-500 Hz
set(subplot(2,1,2), 'XLim', [0 500])% Set frequency Axis To Show 0-500 Hz
y_filtered = fftfilt(hh, y);
But basically i don't understand it and how to change the Frequency to catch ... but my vision to what i will do is to pass all the frequencies i got from the recorded file to all the keys filters and using if conditions if a match then will write the symbol of the key to the sheet.
please if someone can explain the code and the process to me as i never used matlab before and kind of weak in its commands
Pitch is not the same as spectral frequency (as returned by a bare FFT magnitude). Repeated/periodic ("pitched") waveforms do not have to look anything like a sine wave.
It's possible for all the frequencies returned by an FFT to be completely different from the perceived pitch (see "psychoacoustics" and "missing fundamental"). Most likely all higher harmonics, but possibly some inharmonic overtones as well. This is especially true for stringed instruments with "big" strings (piano and bass guitar, etc.)
So the problem isn't with your code, but with the fact that you are not using a pitch detection/estimation algorithm, but instead a spectral frequency peak detector.