complex ifft output for hermitian input
2 次查看(过去 30 天)
显示 更早的评论
I have some S11 data (complex) from a simulation and I want to find the corresponding time response. The values are for positive frequencies (5-15 GHz). So, I added conjugates at negative frequencies and padded zeros for frequencies in between. So, I expected the output of the MATLAB ifft to give a real response but got complex values with significat imaginary part. I have added my code and the data here. Can you point at what I am doing wrong?
clc
clear
close all
%% Read values from the file
s11 = readmatrix("Rect_sheet_4.csv");
posFreq = s11(:, 1) * 1e9; %positive frequencies
posVal = s11(:, 2);
%% Conjugates at negative frequencies
negFreq = -flip(posFreq);
negVal = conj(flip(posVal));
%% Adding zeros in between
step = posFreq(2) - posFreq(1);
zeroFreq = (negFreq(end)+step : step : posFreq(1)-step)';
zeroVal = zeros(length(zeroFreq), 1);
%% Merging all frequencies
val = [negVal; zeroVal; posVal];
freq = [negFreq; zeroFreq; posFreq];
%% Plot S11
figure
subplot(2, 1, 1)
plot(freq, real(val), '-.')
title('Real S11')
subplot(2, 1, 2)
plot(freq, imag(val), '-.')
title('Imaginary S11')
%% IFFT
timeResp = ifftshift(ifft(val));
fs = freq(end)-freq(1);
ts = 1/fs;
n = length(freq);
t = (0:n-1)*ts;
%% Plot time response
figure
plot(t, real(timeResp))
title('Real of time resp')
figure
plot(t, imag(timeResp))
title('Imag of time resp')
0 个评论
采纳的回答
Paul
2022-11-19
Hi Md.
I didn't inspect the whole code, but did notice that the calcuation of timeResp seemed to have the ifft/ifftshift operations in the wrong order. Is the result below closer to what you expect?
clc
clear
close all
%% Read values from the file
s11 = readmatrix("https://www.mathworks.com/matlabcentral/answers/uploaded_files/1199773/Rect_sheet_4.csv");
posFreq = s11(:, 1) * 1e9; %positive frequencies
posVal = s11(:, 2);
%% Conjugates at negative frequencies
negFreq = -flip(posFreq);
negVal = conj(flip(posVal));
%% Adding zeros in between
step = posFreq(2) - posFreq(1);
zeroFreq = (negFreq(end)+step : step : posFreq(1)-step)';
zeroVal = zeros(length(zeroFreq), 1);
%% Merging all frequencies
val = [negVal; zeroVal; posVal];
freq = [negFreq; zeroFreq; posFreq];
%% IFFT
% timeResp = ifftshift(ifft(val));
timeResp = ifft(ifftshift(val));
fs = freq(end)-freq(1);
ts = 1/fs;
n = length(freq);
t = (0:n-1)*ts;
%% Plot time response
figure
plot(t, real(timeResp))
title('Real of time resp')
figure
plot(t, imag(timeResp))
title('Imag of time resp'
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!