Fourier Graphs of my lowpass and high pass filtered signals are looking weird

10 views (last 30 days)
Hello everyone,
I am currently doing a project in MATLAB and I am using a lowpass filter in a signal with a cutoff frequency of 30Hz and then I find the fourier transform of it and I graph it. I want to know if the actual graph is right or am I doing something wrong? I am going to attach the part of the code for the filters and plots.
This is the plot that I get for the low pass filter:
It shouldn't go to 0 after 30 Hz? or around 30 Hz?
And for the high pass filter:
I get it to be 0 around until like 190 Hz, but why is it not 270Hz or closer? I did use smaller frequencies for the HPF and they were more accurate until when they stayed 0.
%LPF 30Hz
y_LPF_30 = lowpass(y,30,Fs);
yf_LPF_30 = fft(y_LPF_30);
% 30Hz
%set up
%% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2_LPF30 = abs(yf_LPF_30/L);
P1_LPF30 = P2_LPF30(1:L/2+1);
P1_LPF30(2:end-1) = 2*P1_LPF30(2:end-1);
figure (5)
%plot
subplot(3,2,1);
plot(f,P1_LPF30)
title('Single-Sided Amplitude Spectrum of LPF 30Hz')
xlabel('f (Hz)')
ylabel('|P1(f)|')
%HPF 270Hz
y_HPF_270 = highpass(y,270,Fs);
yf_HPF_270 = fft(y_HPF_270);
%270Hz
%set up
P2_HPF270 = abs(yf_HPF_270/L);
P1_HPF270 = P2_HPF270(1:L/2+1);
P1_HPF270(2:end-1) = 2*P1_HPF270(2:end-1);
%plot
subplot(3,2,6);
plot(f,P1_HPF270)
title('Single-Sided Amplitude Spectrum of HPF 270Hz')
xlabel('f (Hz)')
ylabel('|P1(f)|')
  2 Comments
Nicolas Picon
Nicolas Picon on 11 Dec 2019
Edited: Nicolas Picon on 11 Dec 2019
That typo explains the high pass filter question, oops.
But I don't know what happens with the LPF.
The code that I used for f is:
[y,Fs] = audioread('myvoice.m4a');
L = length(y);
f = Fs*(0:(L/2))/L;
Nicolas Picon
Nicolas Picon on 11 Dec 2019
Also, the original sound signal graph is this:
Unfiltered Sound Signal.JPG
And the Fourier Transform graph of the original signal is this:
Fourier Transform of Original Signal.JPG
I don't know if this helps

Sign in to comment.

Accepted Answer

Ridwan Alam
Ridwan Alam on 11 Dec 2019
Edited: Ridwan Alam on 11 Dec 2019
Last update:
Running your Lowpass code:
%LPF 30Hz
y_LPF_30 = lowpass(y,30,Fs);
yf_LPF_30 = fft(y_LPF_30);
% 30Hz
%set up
%% Compute the two-sided spectrum P2. Then compute the single-sided spectrum P1 based on P2 and the even-valued signal length L.
P2_LPF30 = abs(yf_LPF_30/L);
P1_LPF30 = P2_LPF30(1:L/2+1);
P1_LPF30(2:end-1) = 2*P1_LPF30(2:end-1);
figure
%plot
plot(f,P1_LPF30)
title('Single-Sided Amplitude Spectrum of LPF 30Hz')
xlabel('f (Hz)')
ylabel('|P1(f)|')
gives this output:
untitled.jpg
Update:
For the low-pass try adding some properties such as:
y_LPF_30 = lowpass(y,30,Fs,'StopbandAttenuation',100);
Also, please show us the plots generated by this:
lowpass(y,30,Fs,'StopbandAttenuation',100);
lowpass(___) with no output arguments plots the input signal and overlays the filtered signal.
Hope it helps.
Earlier:
The filters look ok. some example data would be helpful to debug.
Also, it might just be a typo, but you wrote: P2_HPF270 = abs(yf_HPF_220/L);
  5 Comments
Ridwan Alam
Ridwan Alam on 11 Dec 2019
After running
lowpass(y,30,Fs,'Steepness',0.95,'StopbandAttenuation',100)
the result looks like this:
untitled.jpg

Sign in to comment.

More Answers (0)

Categories

Find more on Fourier Analysis and Filtering in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!