Fast fourier transform in signal processing
Show older comments
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
Answers (1)
Star Strider
on 8 Feb 2017
1 vote
7 Comments
raymon hani
on 8 Feb 2017
Star Strider
on 8 Feb 2017
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
on 17 Feb 2017
Star Strider
on 17 Feb 2017
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
on 17 Feb 2017
Star Strider
on 18 Feb 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
on 18 Feb 2017
Edited: raymon hani
on 18 Feb 2017
Categories
Find more on Frequency Transformations 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!