Merge remote-tracking branch 'origin/main'
This commit is contained in:
@@ -132,7 +132,7 @@ classdef ChannelFreqResp < handle
|
||||
|
||||
fstarget = Target.fs;
|
||||
|
||||
% Build new frequencie axis (with current fs)
|
||||
% Build new frequency axis (with current fs)
|
||||
fnew = linspace(0,fstarget/2,length(Target)/2+1);
|
||||
fnew = fnew(2:end-1);
|
||||
|
||||
@@ -154,7 +154,7 @@ classdef ChannelFreqResp < handle
|
||||
|
||||
%smoothing takes time and sometimes the result looks odd,
|
||||
%however the performance is most of the time better
|
||||
smoothing = 1;
|
||||
smoothing = 0;
|
||||
if smoothing
|
||||
iH = smooth(fnew,iH,0.1,'loess')';
|
||||
end
|
||||
@@ -163,16 +163,10 @@ classdef ChannelFreqResp < handle
|
||||
% angle (-pi,pi) at lowest frequency
|
||||
iH = iH.*exp(-1j*angle(iH(1))); % to be checked (<- not from silas, so what needs to be checked?)
|
||||
|
||||
% Phase difference between lowest and hiughest frequency
|
||||
% component -> but what is this for? dPhase is not used...
|
||||
noncausal = 0;
|
||||
if noncausal
|
||||
dPhase = angle(iH(end))-angle(iH(1));
|
||||
end
|
||||
|
||||
% normalize complex freq. resp. by magnitude at the first
|
||||
% five frequencies -> should be the vaue at f=0=DC component?
|
||||
iH = iH./mean(abs(iH(1:100))); %why 1:5??
|
||||
iH = iH./mean(abs(iH)); %why 1:5??
|
||||
|
||||
% set maximum amplification
|
||||
% set als values higher than hmax to hmax and keep the
|
||||
@@ -191,19 +185,20 @@ classdef ChannelFreqResp < handle
|
||||
|
||||
% iH(1) is DC ---> iH(end) is High Freq.
|
||||
H_inv = [iH(1) iH fliplr(conj(iH)) conj(iH(1))];
|
||||
H_inv = [iH(1) iH 0 fliplr(conj(iH))];
|
||||
|
||||
H_inv = [iH(1) iH iH(end) fliplr(conj(iH)) conj(iH(1))];
|
||||
% H_inv = [iH(1) iH iH(end) fliplr(conj(iH)) conj(iH(1))];
|
||||
|
||||
obj.H_apply = H_inv;
|
||||
|
||||
Target.signal = real((ifft( ( fft(real( Target.signal )) .* H_inv' ) )));
|
||||
|
||||
Target.signal = real((ifft( ( fft(real( Target.signal' )) .* H_inv ) )));
|
||||
Target.signal = Target.signal';
|
||||
|
||||
end
|
||||
|
||||
function plot(obj)
|
||||
|
||||
figure(55551);
|
||||
figure(55);
|
||||
clf;
|
||||
|
||||
Havg = obj.H;
|
||||
@@ -290,6 +285,7 @@ classdef ChannelFreqResp < handle
|
||||
end
|
||||
|
||||
function data = load(obj, options)
|
||||
|
||||
% Function to load data from a specified file and path.
|
||||
arguments
|
||||
obj
|
||||
@@ -334,12 +330,20 @@ classdef ChannelFreqResp < handle
|
||||
% Load the data from the specified file
|
||||
loadedData = load(fullFileName);
|
||||
|
||||
% Replace whole obj here.. is this save or unsave?!
|
||||
fn = fieldnames(loadedData.obj);
|
||||
for n = 1:numel(fn)
|
||||
try
|
||||
obj.(fn{n}) = loadedData.obj.(fn{n});
|
||||
if ~strcmp(fieldnames(loadedData),'obj')
|
||||
% user want to load a moveit precomp file
|
||||
obj.H = 1./loadedData.uFF;
|
||||
obj.faxis = loadedData.f;
|
||||
else
|
||||
|
||||
% Replace whole obj here.. is this save or unsave?!
|
||||
fn = fieldnames(loadedData.obj);
|
||||
for n = 1:numel(fn)
|
||||
try
|
||||
obj.(fn{n}) = loadedData.obj.(fn{n});
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
fprintf('Frequency response information successfully loaded from %s\n', fullFileName);
|
||||
@@ -373,26 +377,29 @@ classdef ChannelFreqResp < handle
|
||||
|
||||
function [rH] = estHfromDMT(obj, data_in, ref_in)
|
||||
|
||||
%! Dont (circ)shift the signal here as this would remove the phase information!
|
||||
%tested with a butterworth filter this exactly reconstructs the
|
||||
%phase and the magnitude. However, the option is here
|
||||
estimatephase = 1;
|
||||
|
||||
if ~estimatephase
|
||||
Nfft = 2*obj.Nacq + 1 ;
|
||||
data_in = reshape(data_in,1,length(data_in));
|
||||
ref_in = reshape(ref_in,1,length(ref_in));
|
||||
|
||||
if length(data_in) ~= length(ref_in)
|
||||
% 0. cross-correlate the received signal with its reference to extract the periods
|
||||
corr = abs(ifft( fft(data_in(1:length(ref_in))).* conj(fft(ref_in)) )) ;
|
||||
corr = abs(ifft( fft(data_in(1:length(ref_in))) .* conj(fft(ref_in)) )) ;
|
||||
|
||||
% find max
|
||||
[~, peak] = max(corr) ;
|
||||
peak=max(1,peak-1);
|
||||
|
||||
data_in = circshift(data_in,-peak) ;
|
||||
%Y = data_in(peak:peak+(Nfft+obj.Ncp)*obj.Navg-1) ;
|
||||
%! Dont (circ)shift the signal here (if signals are equally long) as this would remove the phase information!
|
||||
%tested with a butterworth filter this exactly reconstructs the
|
||||
%phase and the magnitude. However, the option is here
|
||||
|
||||
% data_in = circshift(data_in,-peak) ;
|
||||
data_in = data_in(peak:peak+(Nfft+obj.Ncp)*obj.Navg-1) ;
|
||||
end
|
||||
|
||||
% 1. Reshape signal to a matrix to support noise averaging
|
||||
Nfft = 2*obj.Nacq + 1 ;
|
||||
|
||||
|
||||
Y = reshape(data_in, Nfft+obj.Ncp, obj.Navg).' ;
|
||||
|
||||
X = reshape(ref_in, Nfft + obj.Ncp, obj.Navg).' ;
|
||||
|
||||
Reference in New Issue
Block a user