[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do YOU handle this disparity in fft?
From: |
peter |
Subject: |
Re: How do YOU handle this disparity in fft? |
Date: |
Wed, 12 Feb 2014 14:33:59 +0100 (CET) |
User-agent: |
SquirrelMail/1.4.8-21.el5.centos |
> By the way, be very careful naming variables mnemonically. I just labeled
> the 'sig with noise' as 'sign'. Well, you can see the problem when I went
> to do something else.
>
> The program below allows you to preserve the energy in an 'actual' voltage
> waveform. Both, a 1 Vrms signal is returned as 1 and a DC signal of 1 Vdc
> is returned as 1.
>
> You can easily add noise density function by putting in the value,
> vn=Vrms/rtHz, as
> noisesignal = vn*randn(1,vectorlength)*sqrt(samplingratepersec/2);
> where vn is the noise density function in v/rtHz, and
> vectorlength matches the signal length you add it to, and
> samplingratepersec is the sampling rate
>
> 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, remember to adjust
> it.
> % 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 the packet length.
>
> 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;
>
>
> and, please, NO snickering at how simple this program is, it took a LONG
> time to get here.
This function is part of LTFAT (pkg install -forge ltfat) just better
documented and calling FFTW directly, but not including your sqrt(2)
normalization of the first and last sample (DC and Nyquest terms). There
is also a ifftreal function for getting back again.
Cheers,
Peter
Cheers,
Peter.
- 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?,
peter <=
- Re: How do YOU handle this disparity in fft?, Macy, 2014/02/13
- 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