High pass butterworth filter
Show older comments
I have written a code for implementing High Pass Butter Worth Filter. However, on running the code, I am constantly getting the same error as attached below. I have used parentheses and it still shows the same error. I am unable to understand and rectify it. Kindly help with the same.
Code:
clc;
clear all;
close all;
img=imread('Cameraman.jpg');
hb=butterhp(img,15,1);
hb=butterhp(img,15,1);
af=fftshift(fft2(img)); %FT
fftshow(af);
afhb=af.*hb; %Convolution with ButterWorth Filter
fftshow(afhb);
Function File:
function [out] = butterhp(im,d,n) %wc=cut off frequency and n=order
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
h=size(im,1);
w=size(im,2);
[x,y]=meshgrid(-floor(w/2):floor(w-1)/2; -floor(h/2):floor(h-1)/2);
out=1./(1.+(d./x.^2+y.^2).^0.5).^(2*n));
end
Error:

Answers (1)
Walter Roberson
on 24 Jun 2021
[x,y]=meshgrid(-floor(w/2):floor(w-1)/2; -floor(h/2):floor(h-1)/2);
^
You cannot use ; to separate parameters. You can only use ; inside [] and {} (and, of course, in quoted strings and comments.)
3 Comments
Jake Cooper
on 24 Jun 2021
You had an extra ) in the assignment to out ... but you almost certainly were missing a ( in the same assignment, so the ) was probably correct.
im = imread('cameraman.tif');
out = butterhp(im, 100, 7);
imagesc(uint8(out))
function [out] = butterhp(im,d,n) %wc=cut off frequency and n=order
%UNTITLED4 Summary of this function goes here
% Detailed explanation goes here
h=size(im,1);
w=size(im,2);
[x,y]=meshgrid(-floor(w/2):floor(w-1)/2, -floor(h/2):floor(h-1)/2);
out=1./(1.+(d./(x.^2+y.^2).^0.5).^(2*n));
end
Jake Cooper
on 25 Jun 2021
Categories
Find more on Butterworth 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!