Created
August 29, 2015 09:54
-
-
Save mick001/16a5dbef925c286ff681 to your computer and use it in GitHub Desktop.
Applying Fourier to a real signal: guitar musical note B. Full article at http://www.firsttimeprogrammer.blogspot.com/2015/05/applying-fourier-to-real-signal-guitar.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Loading wav file | |
[ip fs] = wavread('B.wav'); | |
% B tone | |
B = ip; | |
% Play the recording | |
sound(B,fs); | |
% Plot the recording | |
plot(B); | |
ylabel('Amplitude'); | |
xlabel('samples'); | |
% Take the FFT of the recording | |
n = length(B); | |
track = B(1:n-1); | |
FFT = fft(track); | |
ft_mod = abs(FFT); | |
bins = length(B)-1; | |
% Find the fundamental frequency | |
[max_value, max_location] = max(ft_mod); | |
fundamental_frequency = (max_location-1)*fs/n; | |
display(fundamental_frequency) | |
display(max_location) | |
% Frequency vector | |
w = zeros(1,length(bins)); | |
for k = 1:1:bins | |
w(k) = (k-1)*fs/n; | |
end | |
% Plot (half of) the FFT | |
if mod(length(w),2) == 0 | |
index = length(w)/2; | |
else | |
index = (length(w)-1)/2; | |
end | |
plot(w(1:index),ft_mod(1:index)); hold on; | |
xlabel('Frequency Hz'); | |
ylabel('Magnitude'); | |
title('FTT of the recording'); | |
% Apply a filtering rule (in this case I'm letting through only | |
% frequencies between 200 and 1800) | |
minFreq = 200; %400; | |
maxFreq = 1600 ; %1100; | |
for k= 1:1:length(w) | |
if w(k) < minFreq || w(k) > maxFreq | |
FFT(k) = 0; | |
ft_mod(k) = 0; | |
end | |
end | |
% Plot the edited FFT over the full one | |
plot(w(1:index),ft_mod(1:index)); hold off; | |
% Get back the recording | |
y = ifft(FFT); | |
% Play the result | |
sound(abs(y),fs); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment