Fast fourier transform in signal processing

i know how to read a wave file using
[y,Fs] = waveread(x.wave);
and i have a good knowledge about the fast fourier in getting the frequency domain amplitudes and the magnitudes ,but in image processing, i guess it is easy to get them in sound. what i want to build is an FFT based filters that catches the frequency of 440hz of a piano note 'A' or by recording a piano piece of music then catching all the frequencies found...
i Also know that the FFT converts the time domain signal into frequency domain ... how do i catch this into Mat lab using sort of sinusoidal equations ?
Please attach any concerning links or videos that explains what helps me in details

Réponses (1)

Star Strider
Star Strider le 8 Fév 2017

1 vote

If you want to do filtering in the frequency domain, use the fftfilt (link) function.

7 commentaires

raymon hani
raymon hani le 8 Fév 2017
How do i first thing get the fastfourier of the wav file ? And then how to use this filter to compare it to each piano note frequency ? I need matlab guide
The only guide you actually need is the documentation for the functions you want to use.
The documentation for the fast Fourier transform fft (link) function will give you all the information you need to use it. Specifically pay attention to the code between the first (top) two plot figures.
This code designs a simple FIR filter that will work with fftfilt (assuming a sampling frequency of 44100 Hz)). You will use the sampling frequency returned by your wavread call:
Fs = 44100; % Sampling Frequency (Hz)
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 Show 0-500 Hz
set(subplot(2,1,2), 'XLim', [0 500]) % Set Frequency Axis To Show 0-500 Hz
The plot in figure(1) demonstrates the frequency domain characteristics of the filter. It is good to always do that sort of plot so you know the filter does what you want it to do.
To do the actual filtering, use the fftfilt function as:
y_filtered = fftfilt(hh, y);
using the variables you defined and assigned in your code.
raymon hani
raymon hani le 17 Fév 2017
Thank a lot for this huge help i appreciate that a lot but could you please explain further what is fcuts, mags , devs ??what are those matrices and how can i replace them using my [y,Fs] audioread ??
My pleasure.
With respect to the variables, they are copied (with necessary changes) from the documentation on kaiserord (link). Please do not replace any of them, if you want to get the 440 Hz range of your signal. That code should work with your signal just as I wrote it.
The only change you need to make to my code is to delete the ‘Fs’ assignment (unless it is the same as your ‘Fs’), since you will import ‘Fs’ from your audioread call.
To do the actual filtering, use the filtfilt function:
y_filtered = fftfilt(hh, y);
raymon hani
raymon hani le 17 Fév 2017
Thanks a lot for your help again :D the thing is that what i want to do at the end that i will insert a .wav or mp3 file having a piece of music containing all the notes i want then match them with my database with already saved keys ... if they match of found then will write the note for example A ...
let me demonstrate it better ... a piece of music containing Notes (A4 , C4 and D#) which has 3 different frequencies ... when my code runs it should detects what is the frequency of each one of these and then match it in the already declared one ...
Now how do i apply your code with that idea ??
Star Strider
Star Strider le 18 Fév 2017
My code will filter the Fourier-transformed signal. The amplitude of the returned signal for any filter must be above some threshold you choose. I would run each filter (for each frequency) for every signal, and if the amplitude (or relative amplitude) is above a certain threshold, assign a position in a vector a 1, or if absent, a 0. So the vector for each song would have one entry for each note in the same location in the vector. Then I would use the Statistics and Machine Learning Toolbox knnsearch function on your vector with respect to the other vectors in you database to ‘classify’ it as being closest to the others.
This assumes that I understand your question.
raymon hani
raymon hani le 18 Fév 2017
Modifié(e) : raymon hani le 18 Fév 2017
i guess you got my basic idea of the project but generally my issue is that i don't know which variable in your code will give me the final frequency ...
in other words i want to pass all the song frequencies to all the filters and when it catches a match would assign 1 or whatever command i choose , then assign a sequence of if conditions that would ask if the filter frequency equals the frequency of the song ? ... but i don't know which variable in your code holds my frequency ? ( will be hh ?? or what ??)then how do i change the filter to accept when i have another frequency than 440hz ? for example 261.5 this time ??

Connectez-vous pour commenter.

Tags

Modifié(e) :

le 18 Fév 2017

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by