Filter characteristics of smoothdata function ?

1 visualizzazione (ultimi 30 giorni)
Hi all,
I am using a matlab inbuilt function called smoothdata as a low pass filter to remove all the high freqeuncy components from my recorded PPG (photoplethysmography) signal.The sampling frequency was = 100Hz. I want to find out filter characteristics such as frequency response, roll off of my specified smoothdata filter. So is using freqz or fvtool the right way to approach this problem? or is there any suggestions or advice on this please?
fs = 100;
smooth_red= smoothdata(red,'rloess',100); % signal at red wavelength
freqz(smooth_red);
fvtool(smooth_red);
Unrecognized function or variable 'red'.

Risposta accettata

Star Strider
Star Strider il 5 Set 2022
So is using freqz or fvtool the right way to approach this problem?
No. The freqz function wants filter coefficients.
The optimal approach is to use either the fft (or pspectrum) functions to get a Fourier transform of the filtered and unfiltered signals. Then the transfer function (that is what you want to calculate) is —
s = original_signal;
s_filt = filtered_signal;
Fs = 1/(x(2)-x(1));
Fn = Fs/2;
L = numel(signal);
NFFT = 2^nextpow2(L);
FTssf = fft([s(:) s_filt(:)], NFFT)/L;
Fv = linspace(0, 1, NFFT/2+1)*Fn;
Iv = 1:numel(Fv);
transfer_function = FTssf(:,2) ./ FTssf(:,1);
figure
plot(Fv, mag2db(abs(transfer_function(Iv))))
grid
xlabel('Frequency')
ylabel('Power (dB)')
I haven’t tested this, however it should work. The independent variable vector (assumed to be ‘x’ here) must have a constant sampling interval for this to work correctly. The filtered and unfiltered signals must also be the same lengths.
.
  2 Commenti
Suvvi Kuppur Narayana Swamy
Hi,
Thank you very much for the suggestion on this problem. Copying the code i used to perform this task. Its slightly modified as i had better understanding of performing FFTs this way. Please don't mind.
s = red;% orginal signal
Dc_red = smoothdata(red,'rloess',100)% averaging over 100 sample points to get the DC signal
s_filt = DC_red;% fitlered signal
Fs = 100;
Fn = Fs/2;
L = numel(red);
FTssf = fft([s(:) s_filt(:)]);
original_signalspectrum = FTssf(:,1);
original_signalspectrum = original_signalspectrum(1:L/2);
filtered_signalspectrum = FTssf(:,2);
filtered_signalspectrum = filtered_signalspectrum(1:L/2);
f = (0:L/2-1)*(Fs/L);% frequency range
% Check the frequency spectrum of original signal and filtered signal
figure
plot(f,abs(original_signalspectrum))
grid
title('Frequency spectrum of raw signal')
xlabel('Frequency')
ylabel('Amplitude')
figure;
plot(f, abs(filtered_signalspectrum))
grid
title('Frequency spectrum of filtered signal')
xlabel('Frequency')
ylabel('Amplitude')
% Obtain transfer function using frequency spectrum of orginal and filtered signal
transfer_function = filtered_signalspectrum ./ original_signalspectrum;
figure;
plot(f, abs(transfer_function))
grid
xlabel('Frequency')
ylabel('Amplitude')
I have attached the plots i obtained after running this code. Raw signal spectrum contains DC and AC signal components. The Filtered signal goal was to obtain DC of the raw signal and this is clear on seeing the freqeuncy spectrum of filtered signal wherein you see clear only DC component < 1HZ and all the other frequencies above 1Hz are attenuated. As per your suggestion computed transfer by dividing frequency spectrum of filtered signal / frequency spectrum of original signal. I am having trouble interpreting this graph at the end.Any hint or suggestion to understand this better on performance characteristics of filter such as cutoff frequency and roll off. I am aware that smoothdata which is a moving average filter in time domain is great but in frequency domain is worse. But i am trying to understand how to quantify its filter characteristics to a conventional low pass filter or a high pass filter.
Thanks a lot in advance,
Star Strider
Star Strider il 7 Set 2022
It appears to have a narrow biphasic characteristic with frequencies of about 2.2 tp 2.6 and what appears to be a sort of bandstop characteristic at about 4 to 5. The code appears to be correct, so I only used the transfer function plot here.
There is not much to be said about it otherwise, other than it is an interesting investigation into the frequency characteristics of that particular smoothing function when applied to your data. It does not appear to be affecting the isgnal much.
F = openfig(websave('Transfer Function','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1118585/Transfer%20function.fig'));
Lines = findobj(F, 'Type','line');
[Ymax,idx1] = max(Lines.YData)
Ymax = 2.8086
idx1 = 31
FreqMax = Lines.XData(idx1)
FreqMax = 2.4979
[Ymin,idx2] = min(Lines.YData)
Ymin = 0.4694
idx2 = 29
FreqMin = Lines.XData(idx2)
FreqMin = 2.3314
figure
plot(Lines.XData, mag2db(Lines.YData))
grid
xlabel('Frequency')
ylabel('Power (dB)')
title('Transfer Function')
xlim([0 8])
The frequency resolution might have been slightly better had it been zero-padded (using the ‘NFFT’ variable to extned its fft length to a power-of-2 greater than its actual length). I doubt much is lost by not doing that.
.

Accedi per commentare.

Più risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by