excel - frequency to time conversion using MATLAB -
i convert data in frequency domain time domain. in attached excel sheet (book1.xlxs) column frequency. column b , c real , imaginary data (b+jc). attached can see code. not working. have result shown in figure in time domain (green curve part-1).
[num, data, raw] = xlsread('book1.xlsx'); ln=length(raw)-1; %find length of sequence xk=zeros(1,ln); %initilise array of same size of input sequence ixk=zeros(1,ln); %initilise array of same size of input sequence rx = zeros(1,ln); %real value of fft ix = zeros(1,ln); %imaginary value of fft i= 2:length(raw) rx(i-1) = cell2mat(raw(i,2)); ix(i-1) = cell2mat(raw(i,3)); xk(i-1) = sqrt(rx(i-1)^2 + ix(i-1)^2); end n=0:ln-1 k=0:ln-1 ixk(n+1)=ixk(n+1)+(xk(k+1)*exp(i*2*pi*k*n/ln)); end end ixk=10*log(ixk./ln); t=0:ln-1 plot(t, ixk) in image code should give me result similar green curve-part1
instead of doing fft yourself, use built-in matlab functions - easier.
a example mathworks given here. following code have based myself on. passed-in parameter f time domain trace, , fsampling sampling rate. passed-out parameters freq , finv frequency vector , fourier transform, respectively.
function [freq, finv] = fouriertransform(f,fsampling) % fast fourier transform fsampling = round(fsampling); finv = fft(f,fsampling); finv = finv(1:length(finv)/2+1); % truncate out second half, due symmetry finv(2:end - 1) = 2*finv(2:end - 1); % adjust amplitude account truncation finv = finv./length(f); freq = 0:fsampling/2; end
Comments
Post a Comment