How to perform multiple filtering steps using matlab(signal processing)

Below is the example I am working on so far. It needs work to make each iteration apart of a loop in MATLAB.
The filter I used for 128hz filtering is:
Band Pass filter
chebychev II
sample frequency of 10000
lower stop 126hz
lower pass 127hz
128 hz
upper pass 129hz
upper stop 130hz
<>
>> ym3am128 <1st filtering step>
>> ym3am128_106 >> <2nd filtering step>
>> ym3am128_106_88 <3rd filtering step>
The order of steps might look something like this...
...................
At this point I manually find the peaks from a periodogram plot and then use the freq found to apply another filter to generate the next periodogram plot. I need help to automate this activity.
I want to combine the below steps make them automatic(loop).
>> ym3am128_106 = filter(Hd_106hz, ym3am128); plot(periodogram(ym3am128_106))
AND
>> ym3am128_106_88 = filter(Hd_88hz, ym3am128_106); plot(periodogram(ym3am128_106_88))
....................
Any suggestions?

 采纳的回答

I would use a simple fft (link) rather than the more computationally-intensive periodogram. Then use the findpeaks (link) function to isolate the peaks and their frequencies. Design your Chebyshev Type II filter code as a function, and use filtfilt to do the filtering.
Prototype code:
Fs = 200; % Sampling Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency (Hz)
Wp = ([0.5 97])/Fn; % Stopband Frequency (Normalised)
Ws = ([0.1 99])/Fn; % Passband Frequency (Normalised)
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design
[sos,g] = zp2sos(z,p,k); % Convert To Second-Order-Section For Stability
figure
freqz(sos, 2^16, Fs) % Filter Bode Plot
filtered_signal = filtfilt(sosn, gn, original_signal); % Filter Signal

4 个评论

Thank you for these inputs. If I wanted to make the prototype code into a loop where the resulting frequency is the next input frequency, what would be the simplest modification of this code?
As always, my pleasure.
I described a filter bank loop calculation in How to shape the spectrum of an audio waveform? (link).
The essence of the code changed to use the Chebyshev Type II design and tested is here:
Fs = 8200; % Samping Frequency (Hz)
Fn = Fs/2; % Nyquist Frequency
pf = linspace(20,4000,17); % Passband Frequency Edges
cf = pf(1:end-1)+(pf(2)-pf(1))/2; % Centre Frequencies
Rp = 1; % Passband Ripple (dB)
Rs = 50; % Stopband Ripple (dB)
for k1 = 1:length(cf)
Wp = [pf(k1) pf(k1+1)]/Fn; % Passband For This Filter
Ws = ([pf(k1) pf(k1+1)] .* [0.995 1.01])/Fn; % Stopband For This Filter
[n,Ws] = cheb2ord(Wp,Ws,Rp,Rs); % Filter Order
[z,p,k] = cheby2(n,Rs,Ws); % Filter Design;
[sos{k1},g{k1}] = zp2sos(z,p,k);
end
figure(1)
freqz(sos{1})
hold on
for k1 = 2:16
freqz(sos{k1},2^16,Fs)
end
hold off
Define your filter passband edges in ‘pf’. You might want to create this in a (Nx2) matrix of passband edges instead. If so, change the ‘Wp’ assignment in the loop to accommodate the matrix. (Ths stopbands will be calculated automatically unless you want to specify them as well.) The second-order-section and gain vectors will exist in the ‘sos’ and ‘g’ cell arrays. Once you are satisfied with the filter performance, it might be easier to save them to a .mat file so you can quickly load them again rather than re-designing them each time.
caesar buie’s edited Comment, copied from above:
Thank you for these inputs. If I wanted to make the prototype code into a loop where the resulting frequency is the next input frequency, what would be the simplest modification of this code?
I am not certain what you are asking. In my original code, I used consecutive elements of ‘pf’ to define the adjacent passband edge frequencies.
If you want to define ‘pf’ as a (Nx2) matrix of passband frequencies for ‘N’ passbands, the only modification of my code would be:
Wp = pf(k1,:)/Fn;

请先登录,再进行评论。

更多回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Signal Processing Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by