Cut off frequency doesn't works.

2 次查看(过去 30 天)
Reji G
Reji G 2022-5-5
评论: Reji G 2022-5-10
The change in Cut off frequency doen't reflects in output. How to correct ? Also I wnta to display Y axis in dB.
clc;
close all;
clear all;
Fs=200e3;
Ts=1/Fs;
t=0:Ts:(5e-3-Ts);
y=5*sin(2*pi*1000*t)+5*sin(2*pi*20000*t)+10*sin(2*pi*30000*t);
nfft=length(y);
nfft2=2.^nextpow2(nfft);
fy=fft(y,nfft2);
fy=fy(1:nfft2/2);
xfft=Fs.*(0:nfft2/2-1)/nfft2;
cut_off=1.5e3/Fs/2;
order=32;
h=fir1(order,cut_off);
con=conv(y,h);
fh=fft(h,nfft2);
fh=fh(1:nfft2/2);
mul=fh.*fy;
figure(1)
subplot(4,1,1);
plot(t,y);title('Raw signal');xlabel('Time in Sec'),ylabel('Amplitude');
subplot(4,1,2);plot(xfft,abs(fy/max(fy)));title('Freq domain Spark');xlabel('Frequency in Hz'),ylabel('Magnitude');
subplot(4,1,3);plot(abs(mul/max(mul)));title('Filtered output-Frequency domain');xlabel('Frequency in Hz'),ylabel('Magnitude');
subplot(4,1,4);plot(con);title('Filtered output-Time domain');xlabel('Frequency in Hz'),ylabel('Amplitude');

回答(1 个)

Chunru
Chunru 2022-5-5
Fs=200e3;
Ts=1/Fs;
t=0:Ts:(5e-3-Ts);
y=5*sin(2*pi*1000*t)+5*sin(2*pi*20000*t)+10*sin(2*pi*30000*t);
nfft=length(y);
nfft2=2.^nextpow2(nfft);
fy=fft(y,nfft2);
fy=fy(1:nfft2/2);
xfft=Fs.*(0:nfft2/2-1)/nfft2;
% normalize frequency by Fs/2
% cut_off=1.5e3/Fs/2;
cut_off=1.5e3/(Fs/2);
order=32;
h=fir1(order,cut_off);
con=conv(y,h);
fh=fft(h,nfft2);
fh=fh(1:nfft2/2);
mul=fh.*fy;
figure(1)
subplot(4,1,1);
plot(t,y);title('Raw signal');xlabel('Time in Sec'),ylabel('Amplitude');
subplot(4,1,2);plot(xfft,abs(fy/max(fy)));title('Freq domain Spark');xlabel('Frequency in Hz'),ylabel('Magnitude');
subplot(4,1,3);
plot(xfft, abs(mul/max(mul)));
title('Filtered output-Frequency domain');xlabel('Frequency in Hz'),ylabel('Magnitude');
subplot(4,1,4);
plot((0:length(con)-1)/Fs, con);
title('Filtered output-Time domain');xlabel('Time in Sec'),ylabel('Amplitude');
  7 个评论
Chunru
Chunru 2022-5-6
编辑:Chunru 2022-5-6
>>> I changed the fc value to 49Hz. Still the graph is same as you plotted and uploaded here.
If the cut-off is 49 Hz and signal is 50Hz, you may not able to filter out the signal. The filter response is never an ideal cut off it has transition band. Zoom in the filter response and check out how much attenuation you have. if you change the cut-off to a smaller value eg. 20Hz), you may filter out the signal at 50Hz.
>>> As far as my knowlege concerned, If my cutoff freq is 49Hz then signals upto 49Hz should be available at the output rest of the signals should be rejected. Am I correct ? (If I'm wrong, plz correct me. I'm a beginner).
For ideal filter with a sharp edge, this is true. For any real implemental filter, this is wrong. Again, check out the filter response.
==> Also I need y axis in dB, x axis in frequency. So that I can see the frequency corresponds to -3dB. Any help would be highly appreciated.
The magnitude response of the filter is in dB. If you want to show the spectraum of signal, you can alwase use 20*log10(abs(fft(x))).
Reji G
Reji G 2022-5-10
I have a mixed signal, which is having different signals ranging from 50Hz to 10^6Hz. From this mixed signal I want to extract frequency components less than 450Hz. How can I do it ? Also I want to plot frequency Vs Magnitude in dB(Thereby I can observe the frequency corresponds to -3dB).

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by