How can I use lowpass filter while keeping x-axis and y-axis range at log ??

9 views (last 30 days)
How can I use lowpass filter while keeping x-axis and y-axis range at log ??

Answers (1)

Tanmay Das
Tanmay Das on 30 Dec 2021
Hi,
You may use the 'loglog' function to plot x- and y-coordinates using a base 10 logarithmic scale on the x-axis and the y-axis. The following code give you better understanding:
% Create a signal sampled at 1 kHz for 1 second. The signal contains two tones, one at 50 Hz and
% the other at 250 Hz, embedded in Gaussian white noise of variance 1/100. The high-frequency tone
% has twice the amplitude of the low-frequency tone.
fs = 1e3;
t = 0:1/fs:1;
x = [1 2]*sin(2*pi*[50 250]'.*t) + randn(size(t))/10;
% Lowpass-filter the signal to remove the high-frequency tone. Specify a passband frequency of 150 Hz.
% Display the original and filtered signals, and also their spectra.
[y,d] = lowpass(x,150,fs); %d is the designed digital filter
% [H,W] = freqz(D,N) returns the N-point complex frequency response
% vector H and the N-point frequency vector W in radians/sample of the
% digital filter, D. The frequency response is evaluated at N points
% equally spaced around the upper half of the unit circle. If N is not
% specified, it defaults to 8192.
[h,w] = freqz(d);
x1 = w/pi;
y1 = 20*log10(abs(h));
% Log-Log scale plot
loglog(x1,y1)
where 'lowpass' function filters the input signal x using a lowpass filter, x has been sampled at a rate of fs hertz and fpass=150 is the passband frequency of the filter in hertz.. You may look into 'digitalFilter' documentation for further information.

Products

Community Treasure Hunt

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

Start Hunting!