2016-12-16 5 views
-3

Ich habe FFT für Signal (Audiosignal) Code in MATLAB, aber es zeigt (plot) eine Grafik. Ich möchte jedoch nur, dass die Frequenzkomponente in einer Variablen gespeichert wird, aber ich weiß nicht wie. Wenn der Code nicht anwendbar ist, kann mir jemand Code geben, der in Matlab oder in Java funktioniert?FFT in MATLAB oder Java

Hinweis: Ich bin kein Experte in Signalverarbeitung oder MATLAB.


%% Basic Fourier Analysis 
    % This example uses the Fourier transform to identify component 
    % frequencies in a simple signal. 

    %% 
    % Create a time vector |t| and a sinusoidal signal |x| that is a  function of |t|. 
    t = 0:1/50:10-1/50;      
    x = sin(2*pi*15*t) + sin(2*pi*20*t); 

    %% 
    % Plot the signal as a function of time. 
    plot(t,x) 

    %% 
    % Compute the Fourier transform of the signal, and then compute the magnitude 
    % |m| and phase |p| of the signal. 
    y = fft(x);   
    m = abs(y);        
    p = angle(y);      

    %% 
    % Compute the frequency vector associated with the signal |y|, which is 
    % sampled in frequency space. 
    f = (0:length(y)-1)*50/length(y); 



    %% 
    % Plot the magnitude and phase of the signal as a function of frequency. 
    % The spikes in magnitude correspond to the signal's frequency 
    % components. 
    subplot(2,1,1) 
    plot(f,m) 
    title('Magnitude') 

    subplot(2,1,2) 
    plot(f,rad2deg(p)) 
    title('Phase') 

    %% 
    % Compute and plot the inverse transform of $y$, which reproduces the 
    % original data in $x$ up to round-off error. 
    figure 
    x2 = ifft(y); 
    plot(t,x2) 
+1

Bitte zeigen Sie, was Sie ausprobiert haben. Soweit ich weiß, wurde dieser Code nicht von dir geschrieben. – Roxanne

+0

Ja, ich fand es in Matlab-Site –

+0

Ich habe versucht, es so zu speichern h = fft (t, x2) und dann x_h = h.x y_h = h.y –

Antwort

2

Im MATLAB-Code in Ihrer Frage der Vektor m enthält die Größen jedes FFT-Ausgabefach. Jeder Bin entspricht einer Frequenz, so dass dieser Vektor Ihnen eine Magnitude bei jeder Bin-Frequenz gibt. Wenn Sie nach der Frequenz des größten Peaks im Spektrum suchen, suchen Sie einfach den Maximalwert in m und konvertieren Sie dann den Bin-Index dieses Spitzenwerts in eine Frequenz. Die Beziehung zwischen dem Bin-Index und der Frequenz ist gegeben durch:

f = i * Fs/N 

wo i im Index des Faches von Interesse, Fs ist die Abtastrate, N ist die FFT-Größe und f ist die entsprechende Behälter Mittenfrequenz. Eine ausführlichere Erklärung finden Sie unter this question.