You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
First of all thanks for this nice library, is a real great tool for signal processing in common lisp. Now I'm a telecommunication ingenieur working as programmer and in my sparse time I like to learn common lisp. know I want to join common lisp with signal processing, so I really enjoy playing with this library, and know how easy is build the samples that I have in matlab using common lisp, and also the freedom of that
The only thing that I believe that should be usefull to add or maybe only add a reference in the readme, is how to well plot the spectrum for human viewing. for example matlab has the function fftshift (you have and example of this when you get the number 654 por the impulse in the vector for 440 Hz tone) also FFT has a reference of this.
Question 3.11. How can I make FFTW put the origin (zero frequency) at the center of its output?
For human viewing of a spectrum, it is often convenient to put the origin in frequency space at the center of the output array, rather than in the zero-th element (the default in FFTW). If all of the dimensions of your array are even, you can accomplish this by simply multiplying each element of the input array by (-1)^(i + j + ...), where i, j, etcetera are the indices of the element. (This trick is a general property of the DFT, and is not specific to FFTW.)
for example for a 440 tone, you can proceed as follow:
(defparameter *Fs* 44100 "sampling frequency")
(defparameter *NN* 65536 "number of samples")
(defparameter *n* (loop for i from 0 below *NN* collect i))
(defparameter *signal* (mapcar (lambda (x) (cos (/ (* 2 pi 440 x) *Fs*))) *n*) )
(defparameter *spectrum* (napa-fft:fft *signal* :scale t))
You can use alexandria rotate by half length of the vector and also plot [-0.5 0.5] intead of [0 1]
as is given the result of the DFT, then of course scale to half Fs
(vgplot:plot
(loop for i from (- (/ *NN* 2)) below (1- (/ *NN* 2)) collect (* (/ i *NN*) *Fs*))
(alexandria:rotate (map 'simple-vector #'abs *spectrum*) (/ *NN* 2)))
;; or proceding like this
(defparameter *signal* (mapcar (lambda (x) (cos (/ (* 2 pi 440 x) *Fs*))) *n*) )
(defparameter *spectrum-shifted* (napa-fft:fft (loop for i from 0 for x in *signal* collect (* (expt -1 i) x)) :scale t))
(vgplot:plot
(loop for i from (- (/ *NN* 2)) below (1- (/ *NN* 2)) collect (* (/ i *NN*) *Fs*))
(map 'simple-vector #'abs *spectrum-shifted*))
getting the same figure:
Also is important the advice of using vector's length with multiple of 2^k, when you do not generate the signal maybe good to zero padding the signal until the next power of two with this:
(defun next-2-power (n)
"Rounding up to next power of 2"
(expt 2 (ceiling (log n 2))))
This things are important for data visualization but this is really not necessar, and also will be important to add the axes correcttly power of spectrum and Hz. So I do not know it it will ne useful to add this in anyway to this library. really the one of multiplying is imilat to use a windowed fft (one nice feature to weel plotting ffts)
The text was updated successfully, but these errors were encountered:
First of all thanks for this nice library, is a real great tool for signal processing in common lisp. Now I'm a telecommunication ingenieur working as programmer and in my sparse time I like to learn common lisp. know I want to join common lisp with signal processing, so I really enjoy playing with this library, and know how easy is build the samples that I have in matlab using common lisp, and also the freedom of that
The only thing that I believe that should be usefull to add or maybe only add a reference in the readme, is how to well plot the spectrum for human viewing. for example matlab has the function fftshift (you have and example of this when you get the number 654 por the impulse in the vector for 440 Hz tone) also FFT has a reference of this.
for example for a 440 tone, you can proceed as follow:
You can use alexandria rotate by half length of the vector and also plot [-0.5 0.5] intead of [0 1]
as is given the result of the DFT, then of course scale to half Fs
;; or proceding like this
getting the same figure:
Also is important the advice of using vector's length with multiple of 2^k, when you do not generate the signal maybe good to zero padding the signal until the next power of two with this:
This things are important for data visualization but this is really not necessar, and also will be important to add the axes correcttly power of spectrum and Hz. So I do not know it it will ne useful to add this in anyway to this library. really the one of multiplying is imilat to use a windowed fft (one nice feature to weel plotting ffts)
The text was updated successfully, but these errors were encountered: