Signal Analyzer Lowpass filter overshoots input signal

5 vues (au cours des 30 derniers jours)
tired
tired le 29 Avr 2024
Commenté : Mathieu NOE le 3 Mai 2024
Hi everyone,
i am trying to apply a lowpass filter from the signal analyzer app to a simulink signal.
As you can see in the screenshot, i am trying to allow frequencies only below 5 cycles/min - other than that i am using the default parameters.
When i apply the filter to the signal and compare it to the original signal, the filtered signal overshoots the original one.
As i am new to filtering, i would like to ask if there is a way to filter the signal without overshooting?
Thanks for any help
  2 commentaires
Mathieu NOE
Mathieu NOE le 29 Avr 2024
hello
it's rather difficult to make an opinion and suggestion based only on this picture
can you share some data ?
tired
tired le 29 Avr 2024
Modifié(e) : tired le 29 Avr 2024
Hi,
yeah sure.
i had to zip the file cause its rather big
To use the data in the signal analyzer app i use a timeseries that is generated from "to workspace" block in simulink

Connectez-vous pour commenter.

Réponse acceptée

Mathieu NOE
Mathieu NOE le 30 Avr 2024
hello again
so here you can see your signals (in time and frequency domain) before and after low pass filtering (I used here filtfilt instead of filter to avoid phase distorsion if that is important for your application)
here a view on the first samples
code :
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% load signal
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
load('load_data.mat') % Fs = 10 Hz
time = ans(1,:)'; % in s
signal = ans(2,:)';
dt = mean(diff(time)); %
Fs = 1/dt;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% low pass filter section %%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%allow frequencies only below 5 cycles/min (= 0.0833 Hz)
fc = 0.0833; % Hz
N_bpf = 2; % filter order
[b,a] = butter(N_bpf,2/Fs*fc);
signal_filtered = filtfilt(b,a,signal);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% FFT parameters
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
NFFT = 1000; %
OVERLAP = 0.75; % percentage of overlap
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% display 1 : time domain plot
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
figure(1),
plot(time,signal,'b', time,signal_filtered,'r');grid on
title(['Time plot / Fs = ' num2str(Fs) ' Hz / raw data ']);
xlabel('Time (s)');ylabel('Amplitude');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% display 2 : averaged FFT spectrum
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
[freq, spectrum_raw] = myfft_peak(signal,Fs,NFFT,OVERLAP);
[freq, spectrum_filtered] = myfft_peak(signal_filtered,Fs,NFFT,OVERLAP);
figure(2),semilogx(freq,20*log10(spectrum_raw),'b',freq,20*log10(spectrum_filtered),'r');grid on
df = freq(2)-freq(1); % frequency resolution
title(['Averaged FFT Spectrum / Fs = ' num2str(Fs) ' Hz / Delta f = ' num2str(df,3) ' Hz ']);
xlabel('Frequency (Hz)');ylabel('Amplitude (dB (L))');
legend('raw','filtered');
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [freq_vector,fft_spectrum] = myfft_peak(signal, Fs, nfft, Overlap)
% FFT peak spectrum of signal (example sinus amplitude 1 = 0 dB after fft).
% Linear averaging
% signal - input signal,
% Fs - Sampling frequency (Hz).
% nfft - FFT window size
% Overlap - buffer percentage of overlap % (between 0 and 0.95)
[samples,channels] = size(signal);
% fill signal with zeros if its length is lower than nfft
if samples<nfft
s_tmp = zeros(nfft,channels);
s_tmp((1:samples),:) = signal;
signal = s_tmp;
samples = nfft;
end
% window : hanning
window = hanning(nfft);
window = window(:);
% compute fft with overlap
offset = fix((1-Overlap)*nfft);
spectnum = 1+ fix((samples-nfft)/offset); % Number of windows
% % for info is equivalent to :
% noverlap = Overlap*nfft;
% spectnum = fix((samples-noverlap)/(nfft-noverlap)); % Number of windows
% main loop
fft_spectrum = 0;
for i=1:spectnum
start = (i-1)*offset;
sw = signal((1+start):(start+nfft),:).*(window*ones(1,channels));
fft_spectrum = fft_spectrum + (abs(fft(sw))*4/nfft); % X=fft(x.*hanning(N))*4/N; % hanning only
end
fft_spectrum = fft_spectrum/spectnum; % to do linear averaging scaling
% one sidded fft spectrum % Select first half
if rem(nfft,2) % nfft odd
select = (1:(nfft+1)/2)';
else
select = (1:nfft/2+1)';
end
fft_spectrum = fft_spectrum(select,:);
freq_vector = (select - 1)*Fs/nfft;
end
  6 commentaires
tired
tired le 3 Mai 2024
okay, i see.
Thanks again for your help and the detailed information that you provided!
Very much appreciated!
Have a great weekend.
Mathieu NOE
Mathieu NOE le 3 Mai 2024
as always, my pleasure
and have a nice week end too

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2024a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by