- #1
roam
- 1,271
- 12
I want to write a Matlab code which removes all frequency components from a .wav sound file except those within ##±25 Hz## of ##523 Hz## as well as its harmonics (up to the Nyquist frequency). I want to do this without using any built in filters.
Here is my code so far:
But this code doesn't work. When I run the code it takes forever and freezes, and there is no output. What is wrong here?
Any help with fixing this code is greatly appreciated.
Here is my code so far:
Code:
[s, Fs] = wavread('chord.wav'); % Reading the .wav sound file
sNew = zeros(size(s)); % creating a matrix of zeros the size of s
for i = 1:length(sNew)
for N=1:1:(Fs/(2*(523+25))); % number of harmonics up to Nyquist freq
while abs(s-(523.*N))<25 % while within ±25 range of each of the harmonics
sNew(i)=1; % replace the 0 element in sNew with a 1
end
end
end
sFiltered=sNew.*s; % multiplying ones & zeros matrix with s to remove unwanted freqs
wavplay(sFiltered,Fs); % playing the resulting filtered sound
But this code doesn't work. When I run the code it takes forever and freezes, and there is no output. What is wrong here?
Any help with fixing this code is greatly appreciated.
Last edited: