1

周波数領域信号の最大振幅を見つけようとしていますが、最大値は 0 Hz 付近で発生しているようです。を減算するmean of my signalなどのいくつかの方法を試し、使用も試みdetrendましたが、うまくいかないようです。

clear all;
clear max;
clc;

[song,FS] = wavread('c scale fast.wav');
sound(song,FS);

P = 20000;
N=length(song);                     % length of song
t=0:1/FS:(N-1)/FS;                  % define time period


song = sum(song,2);                        
song=abs(song);

% d = fdesign.bandpass('N,Fst1,Fp1,Fp2,Fst2',120,59,60,1000,1001,44100);
% h = design(d,'window');
% x = filter(h,song);

% Plot time domain signal
figure(1);
          subplot(2,1,1)
          plot(t,3*song)
          title('Wave File')
          ylabel('Amplitude')
          xlabel('Length (in seconds)')
          %ylim([-1.1 1.1])
          xlim([0 N/FS])

%----------------------Finding the envelope of the signal-----------------%
% Gaussian Filter
x = linspace( -1, 1, P);                      % create a vector of P values between -1 and 1 inclusive
sigma = 0.335;                                % standard deviation used in Gaussian formula
myFilter = -x .* exp( -(x.^2)/(2*sigma.^2));  % compute first derivative, but leave constants out
myFilter = myFilter / sum( abs( myFilter ) ); % normalize

% Plot Gaussian Filter
         subplot(2,1,2)       
         plot(myFilter)
         title('Edge Detection Filter')

% fft convolution
myFilter = myFilter(:);                         % create a column vector
song(length(song)+length(myFilter)-1) = 0;      %zero pad song
myFilter(length(song)) = 0;                     %zero pad myFilter
edges =ifft(fft(song).*fft(myFilter));

tedges=edges(P:N+P-1);                      % shift by P/2 so peaks line up w/ edges
tedges=tedges/max(abs(tedges));                 % normalize

%---------------------------Onset Detection-------------------------------%
% Finding peaks
maxtab = [];
mintab = [];
x = (1:length(tedges));
min1 = Inf;
max1 = -Inf;
min_pos = NaN; 
max_pos = NaN;

lookformax = 1;
for i=1:length(tedges)

    peak = tedges(i:i);
  if peak > max1, 
      max1 = peak;
      max_pos = x(i); 
  end
  if peak < min1, 
      min1 = peak;
      min_pos = x(i); 
  end

  if lookformax
    if peak < max1-0.01
      maxtab = [maxtab ; max_pos max1];
      min1 = peak; 
      min_pos = x(i);
      lookformax = 0;
    end  
  else
    if peak > min1+0.05
      mintab = [mintab ; min_pos min1];
      max1 = peak; 
      max_pos = x(i);
      lookformax = 1;
    end
  end
end
% % Plot song filtered with edge detector          
         figure(2)
         plot(1/FS:1/FS:N/FS,tedges)
         title('Song Filtered With Edge Detector 1')
         xlabel('Time (s)')
         ylabel('Amplitude')
         ylim([-1 1.1])
         xlim([0 N/FS])

         hold on;

         plot(maxtab(:,1)/FS, maxtab(:,2), 'ro')
         plot(mintab(:,1)/FS, mintab(:,2), 'ko')

max_col = maxtab(:,1);
peaks_det = max_col/FS; 
No_of_peaks = length(peaks_det);

%  song = detrend(song);
%---------------------------Performing FFT--------------------------------%
 for i = 2:No_of_peaks

    song_seg = song(max_col(i-1):max_col(i)-1);
    L = length(song_seg);    
    NFFT = 2^nextpow2(L); % Next power of 2 from length of y
    seg_fft = fft(song_seg,NFFT);%/L;

    f = FS/2*linspace(0,1,NFFT/2+1);
    seg_fft2 = 2*abs(seg_fft(1:NFFT/2+1));
    L5 = length(song_seg);

    figure(1+i)
    plot(f,seg_fft2)
    title('Frequency spectrum of signal')
    xlabel('Frequency (Hz)')
    %xlim([0 2500])
    ylabel('|Y(f)|')
    ylim([0 300])


 end

これを回避し、各ループの最大値を正しく特定するにはどうすればよいですか?

4

1 に答える 1

0

ちょっと、頻度が何回発生したかを示すグラフもプロットしています。

これは私が使用しているコードです:

[wave,freq]  = audioread('Our_song.wav');
disp(freq);
dt  = 1/ freq;
Stoptime = 1;
t = (0:dt:Stoptime-dt);
n = length(wave)-1;
df = freq/n;
figure;
f = 0:freq/n:99999*freq/n;
ff=abs(fft(wave))/n;
fflength= length(ff);
ffpart=ff(1:100000)
plot(f,ffpart);

最大値だけを出力する方法がわかりません。このソリューションに問題があるかどうか教えてください。

于 2014-06-14T08:18:52.660 に答える