フィルターのクリア

Signal Analyzer Lowpass filter overshoots input signal

6 ビュー (過去 30 日間)
tired
tired 2024 年 4 月 29 日
コメント済み: Mathieu NOE 2024 年 5 月 3 日
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 件のコメント
Mathieu NOE
Mathieu NOE 2024 年 4 月 29 日
hello
it's rather difficult to make an opinion and suggestion based only on this picture
can you share some data ?
tired
tired 2024 年 4 月 29 日
編集済み: tired 2024 年 4 月 29 日
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

サインインしてコメントする。

採用された回答

Mathieu NOE
Mathieu NOE 2024 年 4 月 30 日
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 件のコメント
tired
tired 2024 年 5 月 3 日
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 2024 年 5 月 3 日
as always, my pleasure
and have a nice week end too

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSpectral Measurements についてさらに検索

製品


リリース

R2024a

Community Treasure Hunt

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

Start Hunting!

Translated by