Cut off frequency doesn't works.
8 views (last 30 days)
Show older comments
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');
0 Comments
Answers (1)
Chunru
on 5 May 2022
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');
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!