DSPro
Newbie level 4
- Joined
- Dec 28, 2013
- Messages
- 6
- Helped
- 0
- Reputation
- 0
- Reaction score
- 0
- Trophy points
- 1
- Activity points
- 84
close all; clear all; clc;
% Discrete sample frequency 10kHz
fsamp = 10e3;
Tsamp = 1/fsamp;
% Sine frequency 1 kHz
fsine = 1000;
Tsine = 1/fsine;
% Number of complete sine periods to simulate
N_sines = 2.3;
% Number of samples needed
Nsamps = N_sines*Tsine/Tsamp;
% Vector of all sampling times
t = 0:Tsamp:Tsamp*(Nsamps-1);
% Time-domain signal
x = sin(2*pi*fsine*t);
% Compute FFT (i.e. DFT)
Y = fft(x);
% Plot time-domain signal
plot(t,x); title('Time-domain x[n]'); grid on;
% Sort out frequency axis and plot magnitude spectrum
df = fsamp/Nsamps;
f = [ -(ceil((Nsamps-1)/2):-1:1)*df 0 (1:floor((Nsamps-1)/2))*df ];
figure();
plot(f, fftshift(abs(Y)),'--x'); title('DFT Magnitude Spectrum, |Y[f]|');
grid on;
For our hearing, it doesn't matter what came in the past or what will come in the future... our perception of a sound within a given time interval is somewhat unaffected by what happened long before or after that interval (excluding extreme things like getting deafened by a loud bang, etc etc). If we are listening to a perfect 1kHz sine, then a properly-configured FFT (i.e. where discontinuities have been accounted for with correct alignment or windowing) will draw a nice picture of what we perceive.Is FFT terrible at representing the actual frequencies we hear, even if we account for the nonlinear nature of our hearing?
I'm not sure I fully understand your questions, and I don't know so much about the DTFT, but perhaps I can say a few things to help.
Neither can change the frequencies present. After all, computing the inverse transform will get us back to exactly where we started. In fact, what do we even mean by "the frequencies present"? If we observe a million perfect 1kHz sine waves in a row (discretely sampled at interval Tsamp), then it may be practical to treat this as a periodic signal, x[n] = sin[2*pi*1000*n*Tsamp] (so, "only 1kHz is present"). That is, for any n; not just within the million cycles we observed, but last week or next year too. This may seem stupid, but it does sometimes have important consequences.
Consider, for example, that we don't observe exactly 1,000,000 sine periods, but instead observe 1,000,000.1. Intuitively, "the frequencies present" are still exactly the same -- always a perfect 1kHz tone (but this time we just recorded it for a tiny bit longer). However, if we compute the DFT, we now find some other frequencies are present in the spectrum. Why? Because the DFT is based on the assumption that the observed signal will repeat periodically forever. So, when we have an exact integer number of cycles (e.g. 1,000,000), we can start again at the beginning (i.e. repeat the signal periodically) and the sine wave continues perfectly in its cycle. However, with 1,000,000.1 cycles recorded, there is a misalignment; the end does not continue neatly back into the start -- there is a discontinuity (i.e. the non-zero end value has to jump suddenly to zero-valued sin(0), creating something that is not a perfect sine).
In practice, we are not interested in this discontinuity -- we would prefer to see a spectrum with only 1kHz showing up... the rest is just artifacts of the measurement process. Therefore, we commonly use a "window" function (e.g. Blackman, Hanning, Hamming, Gaussian, etc.) which basically attenuates the edges of the time-domain signal, so that these discontinuities contribute less to the final spectrum.
I don't know if you have Matlab or GNU Octave, but this short code demonstrates what I have said. Just change "N_sines" from an integer (e.g. 2) to a non-integer (e.g. 2.3) to see the effects on the spectrum:
Code:close all; clear all; clc; % Discrete sample frequency 10kHz fsamp = 10e3; Tsamp = 1/fsamp; % Sine frequency 1 kHz fsine = 1000; Tsine = 1/fsine; % Number of complete sine periods to simulate N_sines = 2.3; % Number of samples needed Nsamps = N_sines*Tsine/Tsamp; % Vector of all sampling times t = 0:Tsamp:Tsamp*(Nsamps-1); % Time-domain signal x = sin(2*pi*fsine*t); % Compute FFT (i.e. DFT) Y = fft(x); % Plot time-domain signal plot(t,x); title('Time-domain x[n]'); grid on; % Sort out frequency axis and plot magnitude spectrum df = fsamp/Nsamps; f = [ -(ceil((Nsamps-1)/2):-1:1)*df 0 (1:floor((Nsamps-1)/2))*df ]; figure(); plot(f, fftshift(abs(Y)),'--x'); title('DFT Magnitude Spectrum, |Y[f]|'); grid on;
This is an interesting question:
For our hearing, it doesn't matter what came in the past or what will come in the future... our perception of a sound within a given time interval is somewhat unaffected by what happened long before or after that interval (excluding extreme things like getting deafened by a loud bang, etc etc). If we are listening to a perfect 1kHz sine, then a properly-configured FFT (i.e. where discontinuities have been accounted for with correct alignment or windowing) will draw a nice picture of what we perceive.
Similarly, if the signal is really a continuous loop of 2.3 sines making a strange clicky hum (perfectly plausible in theory)... then a differently-configured FFT will draw a very nice picture of that too.
At some point we'll stop listening to this annoying sound, or go crazy or die... at which point the FFT will cease to provide a useful picture of what we perceive.
When processing DTF you assume that signal is periodic with N-captured (windowed) samples as period.
About zeropadding: http://www.control.isy.liu.se/student/tsrt78/zeropadding.pdf
What I still don't understand is when you add zeroes, it appears that the FFT only gains resolution. I would just intuitively think that say a single cycle of sine wave padded by 1 zero is going to be a radically different signal from a sine wave padded by 2 zeroes, or an infinte amount
But back to the question... what does a single cycle sine wave padded by infinite (or at least some) zeros actually look like on the FFT?
Code:What I still don't understand is when you add zeroes, it appears that the FFT only gains resolution. I would just intuitively think that say a single cycle of sine wave padded by 1 zero is going to be a radically different signal from a sine wave padded by 2 zeroes, or an infinte amount
yes ofc it will, because dtf frequency resolution is equall to fs/N so example:
1Mhz sine wave sampled with 16 Mhz frequency and we got 16 samples from it. Now out DTF resolution is 1Mhz so we'll get only 1 bin at 1mhz spot. If you add 1 zero to the signal now resolution is equall to 0,941 Mhz and your signal tone will spread to other bins (leakage).
They idea of padding zeros is that if u pad in this example 16 zeros res = -.5Mhz 48 zeros => 0.25 Mhz => infinitive number of zeros => DTF equals FFT.
Code:But back to the question... what does a single cycle sine wave padded by infinite (or at least some) zeros actually look like on the FFT?
Now if u got samples of just single sinwave your DTF will get you single bin,(because signal in math operation will be copied form -inf to inf for calculation purpose).
If u pad zeros from inf to inf then you will get DTF that equalls to FFT of signal -inf equals 0 then single sin and then 0. Hard to type it sry.
Ok i found Example on web what im talking about
https://www.ee.iitm.ac.in/~csr/teaching/intro_dsp/lecnotes/dft_spectral_analysis.pdf slide 31-37
If u pad zeros from inf to inf then you will get DTF that equalls to FFT of signal -inf equals 0 then single sin and then 0. Hard to type it sry.
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?
We use cookies and similar technologies for the following purposes:
Do you accept cookies and these technologies?