How to use a designed filter to convolve a signal.
21 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jason Jeong
am 24 Apr. 2017
Kommentiert: Honglei Chen
am 25 Apr. 2017
I designed a filter using the filter designer but I don't know how to use the exported code. I want to use the coefficients produced from the filter to convolve the signal and the filter together (without exporting and loading the coefficients).
Sample Designed filter:
function Hd = lowpassfilter_0_10
%LOWPASSFILTER_0_10 Returns a discrete-time filter object.
% MATLAB Code
% Generated by MATLAB(R) 9.1 and the DSP System Toolbox 9.3.
% Generated on: 24-Apr-2017 10:42:14
% Equiripple Lowpass filter designed using the FIRPM function.
% All frequency values are in Hz.
Fs = 204; % Sampling Frequency
Fpass = 0; % Passband Frequency
Fstop = 10; % Stopband Frequency
Dpass = 0.057501127785; % Passband Ripple
Dstop = 0.0001; % Stopband Attenuation
dens = 20; % Density Factor
% Calculate the order from the parameters using FIRPMORD.
[N, Fo, Ao, W] = firpmord([Fpass, Fstop]/(Fs/2), [1 0], [Dpass, Dstop]);
% Calculate the coefficients using the FIRPM function.
b = firpm(N, Fo, Ao, W, {dens});
Hd = dfilt.dffir(b);
How do I use this function within a code to convolve a signal and this filter together? Do I have to do something like:
filtered_signal = conv(signal, Hd);
*To explain the process further: Right now I'm just designing the filter in filter designer, exporting the coefficients into an .mat file, and getting the filtered signal using the convolution.
signal = C{1,1}{1,2}; %my data is in C{1,1}{1,2}
uiopen('matlab','Select filter'); %getting the exported coefficients (variable name lowpass)
fsignal = conv(signal,lowpass); %convolving the signal and filter
Is there a better way to do this without exporting and importing into the workspace and just using the exported code above?
0 Kommentare
Akzeptierte Antwort
Honglei Chen
am 24 Apr. 2017
You may want to use
filtered_signal = filter(Hd,signal);
filter and conv is essentially the same except that filter keeps the output the same size as input and save extra samples in the state for the signal in the next frame. If you really want to use conv you can do
filtered_signal = conv(signal, Hd.Numerator);
HTH
4 Kommentare
Honglei Chen
am 25 Apr. 2017
Yes, that is correct. I think I now understand what you mean by the delay. That is not the difference between filter and conv command. Rather it is the group delay introduced by the filtering operation itself.
HTH
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Filter Design finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!