Generated filter reduces signal time

Hi All
I desgined a filter with the following data, but it reduced the signal time to half , after filtering. is there a reason ? how to resolve?
function y = myFilter(x)
persistent Hd;
if isempty(Hd)
N = 3; % Order
Fstop1 = 55; % First Stopband Frequency
Fpass1 = 65; % First Passband Frequency
Fpass2 = 9998; % Second Passband Frequency
Fstop2 = 10000; % Second Stopband Frequency
Fs = 256000; % Sampling Frequency
h = fdesign.bandpass('n,fst1,fp1,fp2,fst2', N, Fstop1, Fpass1, Fpass2, ...
Fstop2, Fs);
Hd = design(h, 'equiripple');
set(Hd,'PersistentMemory',true);
end
y = filter(Hd,x);
end

Risposte (1)

Star Strider
Star Strider il 18 Dic 2020

0 voti

The ‘y’ output should be the same length as the ‘x’ input. The filter should not change that.
It is important not to confuse time duration with frequency. The frequency displayed will only be up to the Nyquist frequency, half the original sampling frequency. (The Nyquist frequency is the highest frequency that can be uniquely resolvable in a sampled signal.)

6 Commenti

Thank you Star!
Though I'm filtering a time series signal. So why should I see half of the total time in the filtered signal?
My pleasure!
I cannot reproduce the error you report.
This simulation works as I wouild expect it to, using the filter you designed:
x = randn(1,1E4);
t = linspace(0, 1, numel(x))/Fs;
y = filter(Hd,x);
figure
subplot(2,1,1)
plot(t, x)
grid
subplot(2,1,2)
plot(t, y)
grid
Both signals are the same lengths.
The only thing I can think of that might be the reason is that half of your signal is in the stopband of the filter, so it would emerge as zero. No other explanation makes sense.
farzad
farzad il 18 Dic 2020
Modificato: farzad il 18 Dic 2020
Thank you so much!
So on this basis how'd you suggest a passband filter design setting
Sampling rate 256k
Range of interest 65hz to 10k
My pleasure!
If the filter is doing what you want it to do, I wouldn’t change anything.
However, since it’s a FIR filter, an order of 3 is likely much too short. I would start with an order of about 48, and then increase that until you get what you want, unless it’s working optimally as a 48-order filter. Longer filters are less efficient, and with this filter, an order of 256 or less will likely do what you want it to do. I wouldn’t increase it much beyond that unless it isn’t.
Thank you very much! seems a good filtering. well there is a disturbing sinusoidal wave inside the signal, possibly from the electricty that feeds the accelerometer, I want to filter it out. it should be around 50 to 60Hz
If you want to filter out the mains frequency noise, the easiest way would be to use the bandstop function, introduced in R2018a. If you have an earlier version, it’s easy to design a IIR bandstop filter:
Fs = 256000; % Sampling Frequency
Fn = Fs/2; % Nyquist Frequency
Ws = [48 62]/Fn; % Stopband Frequency (Normalised)
Wp = [0.99 1.01].*Ws; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple
Rs = 90; % Passband Ripple (Attenuation)
[n,Wp] = ellipord(Wp,Ws,Rp,Rs); % Elliptic Order Calculation
[z,p,k] = ellip(n,Rp,Rs,Wp,'stop'); % Elliptic Filter Design: Zero-Pole-Gain
[sos,g] = zp2sos(z,p,k); % Second-Order Section For Stability
figure
freqz(sos, 2^20, Fs) % Filter Bode Plot
set(subplot(2,1,1), 'XLim',Wp*Fn.*[0.8 1.2]) % Optional
set(subplot(2,1,2), 'XLim',Wp*Fn.*[0.8 1.2]) % Optional
Use filtfilt to do the actual filtering:
y = filtfilt(sos,g,x);
Experiment with the ‘Ws’ frequencies to get the result you want. (The ‘Wp’ frequencies are calculated automatically from them.)

Accedi per commentare.

Richiesto:

il 18 Dic 2020

Commentato:

il 18 Dic 2020

Community Treasure Hunt

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

Start Hunting!

Translated by