-
ejac
I have a filter of say length n and a soundfile of length m.
When I want to convolve them using FFT, I need to zero-pad both to length n+m-1 (if I've understood correctly), before FFT'ing.
How would I go about doing that?I've seen sig~ can be used to generate a stream from a number. But i dont know how to specify a place in an array to write to. As I see it I make a new array of length n+m-1 then first copy the input array and further fill up with zeros?
Or I could save them to files and add the zeros using an audioeditor, but i have quite a few filters and soundrecordings. -
ejac
How to visualize the frequency spectrum of a signal.
I have tried the following:
i write a signal to an array of 1024 points (cosine wave of osc~)
then i read it back with tabread~
do an rfft~
then i try to get the magnitude response from this by squaring both outputs, summing them, and then sqrt~'ing that sum.
And then use a tabwrite to another array (1024 points) to visualize it. But i don't seem to get satisfactory results.Maybe there is a better way to do it?
i added my pd file as an attachment.
EDIT: added updated fixed patch
-
ejac
How to visualize the frequency spectrum of a signal.
I have tried the following:
i write a signal to an array of 1024 points (cosine wave of osc~)
then i read it back with tabread~
do an rfft~
then i try to get the magnitude response from this by squaring both outputs, summing them, and then sqrt~'ing that sum.
And then use a tabwrite to another array (1024 points) to visualize it. But i don't seem to get satisfactory results.Maybe there is a better way to do it?
i added my pd file as an attachment.
EDIT: added updated fixed patch
-
ejac
n+m-1 because when i convolve a signal (length m) with a filter (length n eg. a long ir of a room). Then the result will be length m+n-1.
And if not zeropadded the excess samples will be wrapped around.i got this idea from: http://www.dspguide.com/CH9.PDF
where is stated:"Now consider the more general case in Fig. 9-9. The input signal, (a), is 256
points long, while the impulse response, (b), contains 51 nonzero points. This
makes the convolution of the two signals 306 samples long, as shown in (c).
The problem is, if we use frequency domain multiplication to perform the
convolution, there are only 256 samples allowed in the output signal. In other
words, 256 point DFTs are used to move (a) and (b) into the frequencydomain. After the multiplication, a 256 point Inverse DFT is used to find the
output signal. How do you squeeze 306 values of the correct signal into the
256 points provided by the frequency domain algorithm? The answer is, you
can't! The 256 points end up being a distorted version of the correct signal.
This process is called circular convolution. It is important because you want
to avoid it." -
ejac
Thx, it seems to have been a range/resolution/blocksize problem. I suspected this, but didn't know how to change it, now i do.
I provided the updated version of my magnitude spectrum patch in attachment.