Why the filter has no output?
59 ビュー (過去 30 日間)
古いコメントを表示
I designed an analoge filter, but it has no signal's output. Can anyone tell me what's wrong in my code?
t=0:.00001:1;
f1=40;f2=300;
wp=400;ws=1000;
x=2*sin(2*pi*f1*t)+0.5*sin(2*pi*f2*t); % signal
[n,wc]=buttord(wp,ws,1,40,'s'); % order and cutoff frequency of the filter
[b,a]=butter(n,wc,'s'); % the parameter of the filter
y=filter(b,a,x); %filtering the signal
subplot(2,1,1);
plot(t,x); % orginal signal
title('the orginal signal');
subplot(2,1,2);
plot(t,y); % filtered signal
title('the filtered signal')
0 件のコメント
回答 (4 件)
Paul
2024 年 12 月 23 日 3:35
編集済み: Paul
2024 年 12 月 23 日 3:40
The function filter is only applicable for a discrete-time filter, not an analog filter. If you want to simulate the output from an analog filter you'll need a different function, something like lsim from the Control System Toolbox. Also, consider using one of the other forms of butter; transfer functions are typically not preferred due to numerical issues (though it may be o.k. in this instance, I didn't check).
0 件のコメント
Star Strider
2024 年 12 月 23 日 3:39
You are designing a continuous filter. All the relevant functions (specifically the filter functions) in the Signal Processing Toolbox work only with discrete (digital) filters.
t=0:0.00001:1;
Fs = 1/t(2)
f1=40;f2=300;
wp=400;ws=1000;
x=2*sin(2*pi*f1*t)+0.5*sin(2*pi*f2*t); % signal
[n,wc]=buttord(wp,ws,1,40,'s'); % order and cutoff frequency of the filter
[b,a]=butter(n,wc,'s'); % the parameter of the filter
figure
freqs(b,a)
y=filter(b,a,x); %filtering the signal <— Not actually
subplot(2,1,1);
plot(t,x); % orginal signal
title('the orginal signal');
subplot(2,1,2);
plot(t,y); % filtered signal
% ------------------ Design Discrete (Digital) Version Of This Filter ------------------
wp=400;ws=1000;
x=2*sin(2*pi*f1*t)+0.5*sin(2*pi*f2*t); % signal
[n,wc]=buttord(2*wp/Fs,2*ws/Fs,1,40); % order and cutoff frequency of the filter
[b,a]=butter(n,wc); % the parameter of the filter
figure
freqz(b, a, 2^16, Fs)
set(subplot(2,1,1), 'YLim', [-5E+2 10], 'XScale','log')
set(subplot(2,1,2), 'XScale','log')
y=filtfilt(b,a,x); %filtering the signal <— Use ‘filtfilt’
subplot(2,1,1);
plot(t,x); % orginal signal
title('the orginal signal');
subplot(2,1,2);
plot(t,y); % filtered signal
Creating a discrete (digital) filter with those passband and stopband frequencies works, however since the signal frequencies are well inside the passband, there is no attenuation.
.
0 件のコメント
Xizeng Feng
2024 年 12 月 23 日 7:33
6 件のコメント
Star Strider
2024 年 12 月 23 日 11:36
You cannot use annalog (continuous) filters with sampled signals. You would have to realise continuous filters in analog hardware. Calculating the component values from the transfer function is not trivial, and it may not be possible. (The transfer function actually has to be improper — the numerator polynomial of higher degree than the denominator polynomial — for it to work.)
Paul
2024 年 12 月 23 日 13:51
移動済み: Paul
2024 年 12 月 23 日 13:53
Running the code gives the result from the text.
f1=5;
f2=60;
t=-0.25:0.00125:0.25;
xc_t=cos(2*pi*f1*t)+cos(2*pi*f2*t);
% plot(t,xc_t);
% xlabel('t');
% ylabel('x_c(t)');
Ts=1/256;
ts=-0.25:Ts:0.25;
xn=cos(2*pi*f1*ts)+cos(2*pi*f2*ts);
Rp=2;
Rs=40;
wp=2*pi*10;
ws=2*pi*50;
This line computes the order and cutoff frequency for a continuous-time filter
[N, wc]=buttord(wp,ws,Rp,Rs,'s')
This line uses N to compute the transfer function of a discrete-time filter and normalizes wc to half the the sampling frequency.
[B, A]=butter(N,wc*Ts*1/pi);
yn=filter(B,A,xn);
stem(ts,yn,'filled','r'), hold on;
plot(t,cos(2*pi*f1*t));
Yields the result from the text.
Not sure why the authors are using buttord for a continuous-time filter and then using those results to design a discrete-time filter. Maybe they were trying to illustrate a point for which we are missing some context.
参考
カテゴリ
Help Center および File Exchange で Analog Filters についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!