help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Strange behaviour of FFT


From: Jörg Kampmann
Subject: Strange behaviour of FFT
Date: Mon, 19 Jul 2004 20:33:20 +0200
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.5) Gecko/20031007


I am using the attached little program in order to test the limits etc.
of "fft(a,n)"

I generate a superposition of sinewaves of 0.1 s duration and apply fft
on it in order to get the power spectrum of the sinewaves.

Strange things seem to happen, perhaps somebody is able to help me or
clarify matters:

when you run the Simulation02 you discover (with 10 Superpositions as
indicated in variable "SuperPos") that a 200, 400, 600 etc. Hz you get
nice power spectra peaks as expected. However at values in between I get
strange effects at the footing area of the power spectra peaks, which
you can easily observe.

I assume that stems from the way I construct the variable "ySinewave"
and "tone".

I would like to get some practical hints on how to best use fft. The
tutorial/documentation does not say much about it ...

Thanks in advance
Joerg


#! /usr/bin/octave -qf
#########################################################
## (C) 2004 IBK-Consult, D-31228 Peine
##     Simulation of sinewave based signals (superposition)
##     on which fft is applied
##
##      2004-07-16 JK
#########################################################
t = ( -4096:1:4095 )';  # x- or t-axis for generated signal
                        # these parameters used with "sinetone":
rate = 81920 ;          # sampling intervall for signal generated here
sec = 0.1 ;             # duration of signal sample in  seconds
ampl = 1 ;              # amplification of signal 

lowFreq = 100 ;         # lower base frequency, to start with
hiFreq = 1600 ;         # upper base frequency, to end with
deltaFreq = 50 ;        # stepwise frequency increase by deltaFreq
SuperPos = 10 ;         # this many components (superpositions) in a 
                        # signal (tone)



for freq = lowFreq:deltaFreq:hiFreq

    tone = 0 ;
    for ii = 1:SuperPos 
        frq = freq*ii ;
        ySinetone = sinetone( frq, rate, sec, ampl ) ;
        tone = tone + (-1.0**ii) / ii .* ySinetone ;
    endfor

    TitleString = sprintf( "Base Freq = %d", freq );
    data = [ t, tone ];
    
    # output form of signal ... to look at ... 
    gplot [-6000:6000] [-2.6:2.6]  data with lines title TitleString

    printf( "Base Frequency: %d ", freq ) ; 
    fflush( stdout ) ;

    input( "Continue with <enter>", "s" );

    ########################################################
    ## Now fast Fourier Transform of "y"
    ########################################################

    fft_data = fft( tone, 2048 );

    for ii = 1:(SuperPos + freq )
#       printf( "FFT-Value %d ->real = %6.2f - imag = %6.2f\n", \
#               ii, real( fft_data(ii) ), imag( fft_data(ii) ) ) ;

        # compute element of power spectrum

        xx(ii) = ( real( fft_data(ii) )**2 + imag( fft_data(ii) )**2 )**0.5 ;
    endfor

    ############################################

    TitleString = sprintf( "Power Spectrum for Freq = %d", freq ) ;
    x1 = (1 : SuperPos + freq )';
    data = [ x1, xx];
    gplot [0:(SuperPos + freq )][0:1000] \
                      data using 1:2  title TitleString

    fflush(stdout) ;
    input( "Continue" ) ;


endfor

#########################################################


reply via email to

[Prev in Thread] Current Thread [Next in Thread]