Re: Chopping up a wav file and re-writing to disk



Oli wrote:


Thanks Peter, I had a feeling I had missed something simple out,
but
didn't see that little error!

One more thing, do you know how I wouls go about plotting the
frequency spectrum of this 30 exerpt?

I tried 'plot(x,Fs)', but it displays nothing on the graph...

I am not quite sure why you expect that little plot to give you a
frequency spectrum, my understanding is that x is a fragment of your
time domain waveform, and Fs is your sample rate.

To get your frequency response you need to convert your time domain
waveform into the frequency domain - this is what the Fast Fourier
transform does

Freq_Response = fft(x);

The output of this operation gives you both the magnitude and phase
information of each frequency component, represented as a complex
number. If you are not interested in the phase, you can do one of two
things.

1) Compute the amplitude (magnitude) of each component

Magnitude = abs(Freq_Response);

2) Compute the power in each component

Power = Freq_Response*conj(Freq_Response);

To display this nicely go

Display_Freq = fftshift(Power); or
Display_Freq = fftshift(Magnitude);

Depending what you want to investigate, then try

plot(Display_Freq);

What you should see is a nice symmetrical waveform about the centre.
The centre point is DC or 0Hz, and represents the mean
power/amplitude of your segment of sound, To the right each sample
increases the frequency by 1/30Hz, so 30 samples upstream you are
looking at the power/magnitude of the signal at 1Hz. Going leftwards
your frequency is diminishing by 1/30Hz and represents the negative
frequencies, thus 30 samples downstream you have the component at
-1Hz, and because we have thrown away the phase information, it is
exactly the same values as the +1Hz component. Because of this
symmetry, many people will ignore the negative frequency components -
but if you do remember to double the value of all your frequency
components other than DC.

If you count the number of samples to your left from the DC point you
will find that the maximum negative frequency represented on this
graph is -Fs/2, and the maximum positive frequency is Fs/2.

You may want to scale your output logarithmically to get the power in
decibels.

Regards

Dave Robinson
.



Relevant Pages

  • Re: Chopping up a wav file and re-writing to disk
    ... Dave Robinson wrote: ... waveform into the frequency domain - this is what the Fast Fourier ... The output of this operation gives you both the magnitude and phase ... many people will ignore the negative frequency components ...
    (comp.soft-sys.matlab)
  • Re: Generating Time Waveform From Frequency Data
    ... with the magnitude and phase data. ... The first entry is ... I need to convert it to time domain. ...
    (comp.soft-sys.matlab)
  • Re: Envelope of Speech
    ... also a Hilbert Transformer (to creat the imaginary part of a complex ... waveform which I can take the magnitude of) but neither of these ...
    (comp.dsp)
  • Re: negative hex
    ... negative frequency corresponds to putting a negative number ... That walks a waveform table backwards. ... polyphase waveform set that spins a motor clockwise, ... the motor will spin CCW. ...
    (sci.electronics.design)
  • Re: negative hex
    ... negative frequency corresponds to putting a negative number ... That walks a waveform table backwards. ... polyphase waveform set that spins a motor clockwise, ... the motor will spin CCW. ...
    (sci.electronics.design)

Loading