Using Matlab ifft() to convert an exoprted frequency spectrum csv from other tool, how to get right amplitude ?
3 ビュー (過去 30 日間)
古いコメントを表示
Hi, folks:
I have a question, if you could kindly give some suggestions,
I have a csv-like file format exported from other tool, it stores the frequency-spectrum data using the tool's FFT feature of a signal in time domain , the file has the columns of 'freq' and value of complex 'real, imaginary'.
I can successfully read the file from the codes shows below, but I need to use Matlab to convert this to time domain after doing some freq-manipulation. But my problem met here is , I can't get the right amplitude when I at the first try to convert the FFT's data into time domain, it didn't seem as same as the original time data, the shape is 'OK', but I found the amplitude is not correct. Can you help me to correct it ?
I have attached the csv-like file, and the codes is below.
Thank you very much.
% FFT_to_time.m
filename1 = 'FFT.txt';
fileid = fopen(filename1,'r'); % open file for read
str_format = ['%f' char(9) '%f,%f'];
% tline = fgetl(fileid);
C = textscan(fileid, str_format);
fclose(fileid); % close the files id
freq_axis1 = C{1}; % frequency
mag_real = C{2}; % real part
mag_imaginary = C{3}; % imaginary part
C1_cmplx = mag_real+mag_imaginary*i;
mag_db1 = mag2db(abs(C1_cmplx));
plot(log10(freq_axis1),(mag_db1));
legend('filename_of_LTspice_FFT_exporteds Legend');
grid on;
title('FFT analysis');
xlabel('Freq 10^x (Hz)');
ylabel('Signal Mag (dB)');
% time domain, using ifft
n = size(C{1});
figure();
plot(1:1:n,ifft(C1_cmplx,'symmetric'))
grid on;
0 件のコメント
回答 (1 件)
Star Strider
2022 年 3 月 21 日
The signal has an extremely high level of broadband noise, and the recovered time domain signal reflects that.
One option to deal with the broadband noise in the Fourier transform is to use the Savitzky-Golay filter (sgolayfilt) to smooth the Fourier transform (although ideally, this should have been done on the original time domain signal before doing the Fourier transform).
My result —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/935504/FFT.txt', 'VariableNamingRule','preserve')
T1s = arrayfun(@(x)strsplit(cell2mat(x),'\t'), T1{:,1}, 'Unif',0); % Split 'Var1' Into Two Separate Columns
T1s = cell2mat(cellfun(@str2double,T1s, 'Unif',0)); % Convert To Double Values
Freq = T1s(:,1); % Frequency Vector
Re = T1s(:,2); % Real Component Of The Fourier Transform
Im = T1.Var2; % Imaginary Component Of The Fourier Transform
FT1 = Re+1j*Im; % Complex Fourier Transform
Fn = Freq(end); % Nyquist Frequency
Fs = Fn*2; % Sampling Frequency
figure
subplot(2,1,1)
plot(Freq, mag2db(abs(FT1)))
grid
ylabel('Amplitude (dB)')
subplot(2,1,2)
plot(Freq, angle(FT1))
grid
xlabel('Frequency')
ylabel('Phase (rad)')
sgtitle('One-Sided Fourier Transform')
FT2 = [FT1; flipud(conj(FT1))]; % Create Symmetric Two-Sided Fourier Transform
IFT = ifft(FT2,'symmetric'); % Take The Inverse
t = linspace(0,numel(FT2-1),numel(FT2))/Fs; % Time Vector
figure
yyaxis left
plot(t, real(IFT))
ylabel('Real Amplitude')
yyaxis right
plot(t, imag(IFT))
grid
xlabel('Time')
ylabel('Imaginary Amplitude')
title('Recovered Time Domain Signal')
.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!