[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do YOU handle this disparity in fft?
From: |
Macy |
Subject: |
Re: How do YOU handle this disparity in fft? |
Date: |
Thu, 13 Feb 2014 07:17:57 -0800 |
below are copies of the two fft and ifft related programs that only use half
the spectrum. Why? just easier for me to work in a spectrum that monotonically
increases, and I don't have to include the difficult 'mirrored' half.
fftreal.m
takes in a real time waveform of EVEN length and gives back an ENERGY correct
spectrum from DC to just under Nyquist rate. Just the left half of the fft's
result. Thus, 1 Vdc and 1.414 peak tones come out equal to 1.
ifftreal.m
takes in an ENERGY correct spectrum that goes from DC to just under Nyquist
rate and converts it to a real time waveform that is twice the length of the
number of frequency bins. caveat: since there is no information on the EXACT
Nyquist rate and it is assumed to be zero, the resulting time waveform has a
'small' bit of high frequency, less than 1% caused by noise, not signal
related. Envision just as there is always some residual DC in a random
sequence, there is also some Nyquist rate residual, too. This small amount of
'lost' signal only relates to noise and poses no problem, because any energy at
the exact Nyquist rate is stripped when going back and forth with fftreal and
ifftreal. ONLY a non-linear system will be slightly affected by this addition,
but you can check any potential effect by removing all noise and verify.
That said, what these two functions can be used for:
1. Take time waveforms, combine with ANY noise, including OpAmp style 1/f plus
white noise, or even 'shaped' noise. to produce time waveforms representing
all. Shove through pass-band characteristics and watch the effects of
filtering, etc.
2. Be able to represent extremely complex systems, especially non-linear
systems, by flipping back and forth between the time domain and the frequency
domain, and be capable of injecting noise at any point along that system.
LTspice can be 'fudged' to do similar, just not as fast. .tran analyses are
SLOW! and changing time waveforms of noise strings can get tedious.
In retrospect, should have written
time2freq.m amd freq2time.m and plotfreq.m programs instead!
Doing that would remove the injection of error at the Nyquist rate and possibly
work better analyzing a non-linear system where S/N are in the 3dB ranges.
arrrrggg! now that's just embarrassing.
fftreal.m
function [out,ford]=fftreal(in);
% calculates the 'adjusted' values of the fft, only half the fft is returned
% use the form [b,ford]=fftreal(sig);
% the ordinate, ford, is returned to enable plotting, needs to be adjusted.
% input a realtime waveform a vector only
% out is the adjusted values of the fft in true energy values
% ford is the ordinate of the fft, to accurately plot ford is to be
multiplied by
% the Sampling rate divided by two
if (nargin ~=1)
help fftreal;
return;
endif
[rowsin,columnsin]=size(in);
if( rowsin ~=1)
disp("for now, only accept a vector");
return;
endif
if ( 2*round(columnsin/2+.1) ~= columnsin)
disp("for now, only accept an EVEN vector");
return;
endif
n=round(columnsin/2);
b=sqrt(2)*fft(in)/columnsin;
out=[b(1)/sqrt(2),b(2:n)];
ford=([1:n]-1)/n;
endfunction;
ifftreal.m
function [out,t]=ifftreal(in);
% only left half of fft, but missing the Nyquist value.
% use form [out,t]=ifftreal(in), where
% 'in' is the lower half of an ENERGY correct spectrum
% 'out' is the time real waveform, double in length
% optional 't' is normalized time samples from zero to less than 1.
if (nargin~=1)
help ifftreal;
return;
endif
[rowsin,columnsin]=size(in);
if ( rowsin~=1)
disp("for now, only input a vector");
return;
endif
p=2*columnsin;
t=([1:p]-1)/p;
tempf=[in(1)*sqrt(2),in(2:columnsin),0,conj(in(columnsin:-1:2))];
out=real(sqrt(2)*ifft(tempf)*columnsin);
endfunction;
- How do YOU handle this disparity in fft?, Macy, 2014/02/10
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/11
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/12
- Re: How do YOU handle this disparity in fft?,
Macy <=
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/14
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/15
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/16
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/16