Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/fft_core.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % FFT_CORE Simple core method which computes the fft. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: Simple core method which computes the fft. | |
5 % | |
6 % CALL: ao = fft_core(ao, type) | |
7 % | |
8 % INPUTS: ao: Single input analysis object | |
9 % type: The fft type | |
10 % 'plain' - complete non-symmetric | |
11 % 'one' - from zero to Nyquist | |
12 % 'two' - complete symmetric | |
13 % | |
14 % VERSION: $Id: fft_core.m,v 1.7 2011/02/04 17:42:29 luigi Exp $ | |
15 % | |
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
17 function bs = fft_core(bs, type) | |
18 | |
19 % Which data type do we have | |
20 switch class(bs.data) | |
21 case {'tsdata', 'cdata', 'xydata'} | |
22 % Check we have a sample rate | |
23 if strcmp(class(bs.data), 'tsdata') | |
24 fs = bs.data.fs; | |
25 fmin = 0; | |
26 else | |
27 warning('!!! Data has no sample rate: setting to %g', 2+length(bs.data.y)); | |
28 fs = 2+length(bs.data.y); | |
29 fmin = 1; | |
30 end | |
31 % make FFT of data | |
32 xunits = 'Hz'; | |
33 nfft = length(bs.data.y); | |
34 ft = fft(bs.data.y); | |
35 f = utils.math.getfftfreq(nfft,fs,type); | |
36 switch lower(type) | |
37 case 'plain' % get true matlab fft | |
38 f = reshape(f,size(ft)); | |
39 case 'one' | |
40 ft = ft(1:floor(nfft/2)+1); | |
41 f = reshape(f,size(ft)); | |
42 case 'two' | |
43 if size(ft, 1) == 1 | |
44 ft = fftshift(ft); | |
45 else | |
46 ft = fftshift(ft); | |
47 if rem(nfft,2) % odd number of data | |
48 f = f.'; | |
49 else % even number of data | |
50 f = f.'; | |
51 end | |
52 end | |
53 otherwise | |
54 error('### unknown fft type.'); | |
55 end | |
56 % Make new fsdata object | |
57 fsd = fsdata(f, ft, fs); | |
58 fsd.setXunits(xunits); | |
59 fsd.setYunits(bs.data.yunits); | |
60 % make output analysis object | |
61 bs.data = fsd; | |
62 % clear errors | |
63 bs.clearErrors; | |
64 | |
65 otherwise | |
66 error('### You can only fft tsdata, cdata, or xydata AOs.'); | |
67 end | |
68 | |
69 end | |
70 | |
71 | |
72 | |
73 |