Effacer les filtres
Effacer les filtres

How to wrote code for Ramp Filter and show the firgure?

7 vues (au cours des 30 derniers jours)
mohd akmal masud
mohd akmal masud le 18 Mai 2024
Commenté : Image Analyst le 19 Mai 2024
Dear All,
Please help me how to plot the Ramp filter as picture attached.

Réponse acceptée

Abhishek Kumar Singh
Abhishek Kumar Singh le 18 Mai 2024
I am assuming that the filter is linear in frequency domain, i.e., it amplifies the frequency components linearly w.r.t frequency.
Here's a simple MATLAB script you can use to get started that defined a ramp filter and then plots it:
% Define parameters
N = 512; % Number of points in the filter
fs = 1000; % Sampling freq. in Hz
f = fs * (-N/2:N/2-1)/N; % Freq. vector
% Creating the ramp filter in the freq. domain
rampFilter = abs(f);
% Plot
figure;
plot(f, rampFilter);
title('Ramp Filter');
xlabel('Frequency (Hz)');
ylabel('Amplitude');
grid on;
Note that you might need to adjust the filter's length (N), apply a window function to control the filter's side lobes, or normalize the filter's response based on your specific requirements.

Plus de réponses (1)

Image Analyst
Image Analyst le 18 Mai 2024
You can use linspace to create the filter. Like
numPoints = 101; % Whatever
bothRamps = zeros(1, numPoints); % Preallocate
% Make descending ramp with linspace().
leftRamp = linspace(126, 0, 51);
% Make ascending ramp with linspace().
rightRamp = linspace(0, 126, 51);
% Put them each into our filter vector.
bothRamps(1 : 51) = leftRamp;
bothRamps(51 : 101) = rightRamp;
% Create x axis.
x = linspace(-1, 1, numPoints);
% Plot the filter vector.
plot(x, bothRamps, 'b-', 'LineWidth', 2);
grid on;
xlabel('x');
ylabel('Filter Value');
% Put text label in the middle like the example.
text(0, 82, 'Ramp Filter', 'FontSize', 30, 'HorizontalAlignment', 'Center', 'VerticalAlignment', 'Bottom')
  2 commentaires
mohd akmal masud
mohd akmal masud le 19 Mai 2024
THANK YOU VERY MUCH @Image Analyst
Image Analyst
Image Analyst le 19 Mai 2024
You're welcome. Just be aware that my answer gives the x and y range the same as in the picture you wanted to reproduce, unlike the answer that you accepted.

Connectez-vous pour commenter.

Produits


Version

R2023a

Community Treasure Hunt

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

Start Hunting!

Translated by