understanding the matlab code

There is a code for an image which does filtering. Can anyone help me understand this code? Besides I want to implement this filtering technique for 1D .mat format data having 2 cols and 6000 rows.

14 Kommentare

Rik
Rik am 16 Dez. 2022
If you have rows and columns, your data is not 1D. Also, mat files store variables containing data, but do not technically store the data directly, so a .mat file does not actually contain 2 cols and 6000 rows.
But now to your question. You can easily have a peak at the code. It isn't very long and doesn't contain many variables. The main functionality is in the calls to medfilt2. Have you read the documentation for that function? And have you tried this code with a small example to see if you can predict the output correctly?
bruno
bruno am 16 Dez. 2022
When I run this for a random flower picture, in command window I got ans= uint8 0 I have attached screenshot.
But the mat file is ecg signal actually and its time series 1D.
Rik
Rik am 16 Dez. 2022
You didn't actually run this for the image, but for the name of the file containing the image. So you provided a scalar string. I'm surprised you got an output at all and not an error.
An entire image is not actually that small. I was talking about an array of 10x10 at most.
And why do you want to apply this image processing tool to your linear data? What exactly do you want to happen? Perhaps you can write something on your own.
bruno
bruno am 16 Dez. 2022
the file I attached 100.mat above is basically ECG data and I want to filter it using relaxed me dian.
Rik
Rik am 16 Dez. 2022
You didn't attach a mat file, only a screenshot. I'm not asking these questions to tease you or something. It is very unproductive that you ignore half of what I write. You may have noticed that I try to respond to your entire post and I would ask you to do the same.
I suspect you will be better off processing each lead separately with a 1D moving median. The code you linked to, suggest to me that to implement a relaxed median, you only need two or three calls to movmedian, although you will have to check whether that function was already implemented in R2018a.
Image Analyst
Image Analyst am 17 Dez. 2022
You didn't attach anything. 100.mat is not attached. Is it the one I attached from your other question?
And there may be filters that are especially meant for ecg signals than some generic median filter. Try PubMed
What are you going to do with the signal anyway? I mean, WHY does it need to be filtered? What happens if you just use the original signal? Is there some problem with whatever you're trying to do?
bruno
bruno am 17 Dez. 2022
Alright so I did attach it earlier idk why It didnt show. But now I have attached again. Referred to Image Analyst reply, my goal is to filter the signal and get its baseline to 0 and cancel out the noise added from high and low frequencies. Im implementing a paper which asks to do so. But I couldnt get any help related to relaxed me dian filter.
Referred to Rik, well Im sorry but my goal is to apply relax me dian filter on this 100.mat file. Then I will apply fft to get features extracted and Later on I will be converting it into an image for alex net classifier. I have converted this signal 100.mat to rgb but idk what to do now how to implement relaxed median on 100.mat directly.
Rik
Rik am 18 Dez. 2022
Why use a relaxed median filter if you are planning on using an fft later anyway? Wouldn't it be easier to skip that step?
And you still haven't told us how you tried to implement a relaxed median yourself.
bruno
bruno am 18 Dez. 2022
By using relaxed median filter, baseline will reduce to zero and the literature suggests this filter is better in spike noise. Besides I have a mat file as I said Im planning to implement it on that file,
My attempt is this which I reproduced by following what was given for an image. But I still dont get it. If this is correct then the problem is I tried to give my M variable to it with single column at a time but It gives me a verticle line as output.
function [rm]=rmedianon1D(inp,L,U)
n3=inp;
[x y]=size(inp);
%set defaults
if nargin<3
L=3;
U=5;
end
nt=medfilt2(inp);
n1=medfilt2(inp,[L L]);
n2=medfilt2(inp,[U U]);
if n3~=n1 & n3~=n2;
n3=nt;
end
rm=(n3);
plot(rm)
bruno
bruno am 18 Dez. 2022
for better R peak detection alongwith other features I need to perform median filter prior.
Walter Roberson
Walter Roberson am 18 Dez. 2022
Are you expecting that pictures of the ecg signal will be successfully classified by alexnet? As what, "ball", "tree", "turtle"?? Has alexnet been trained on enough ecg signals to be useful??
bruno
bruno am 18 Dez. 2022
yes literature says so. im implementing a paper
Walter Roberson
Walter Roberson am 18 Dez. 2022
When I look around at papers, the ones I find use transfer learning... which requires a dataset of images to train against. Just using the standard pretrained alexnet is not good enough for the papers that I see.
bruno
bruno am 18 Dez. 2022
yes the dataset I be using is MIT BIH and its signal will be converted to images RGB for alexnet input

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Image Analyst
Image Analyst am 18 Dez. 2022

0 Stimmen

I don't know what "relaxed" median filter is, but you can see how I applied a median filter to images in the attached demos. This is after you've converted your signal to an image.
If you want to filter your 1-D signal before you convert it into an image, then you can use medfilt1, but I'm not sure how you would use that in the whole "relaxed" version of median filter (since I don't know what it is).
Alexnet takes 227x227 RGB images. What features of your spectral image do you plan on measuring? And how do you plan on inserting them into the RGB image?

9 Kommentare

bruno
bruno am 18 Dez. 2022
well you can see the difference here. Im not able to understand as not much literature is available. its an ecg signal so i would like to extract qrs, r, rr interval, q, p,s,t points
bruno
bruno am 18 Dez. 2022
in the question statement I have added link, that is relaxed median. But i dont understand its working.
DGM
DGM am 18 Dez. 2022
Bearbeitet: DGM am 18 Dez. 2022
That FEX implementation doesn't really look like what the ijetemr.org link describes. That said, the ijetemr.org link has been obviously just pasted from a PDF without proofreading, so the expressions are essentially unreadable. It's hard to say what's being described, but when they say "relax the order statistic", I don't take that to mean "change the window size".
The way I read this mess:
Yi=RM lu {Wi}= {XiifXiE{[Wi](l),[Wi](u)}
{[Wi](m) otherwise
means that for a given sample position, the output pixel is unchanged if it belongs between the lower and upper order statistics of that sample region. If the pixel value lies outside the specified order statistics, then it's replaced with the central order statistic -- the sample median. This could be implemented using ordfilt2() and some comparisons.
Like I said, the FEX implementation doesn't correspond to what the above student paper describes. That said, I don't have institutional access to the parent paper, and I'm not paying for it. This also might just be a totally different interpretation of what a relaxed median filter is.
"By using relaxed median filter, baseline will reduce to zero"
Not as these noise removal filters are described. You'd do that with a simple median filter
detrended = originalsignal - medfilt2(originalsignal,[5 5]);
I'm not sure what the motivation is here. Does the FEX implementation not work? It doesn't seem to work well, but that's kind of what I expected. For better rejection of dense impulse noise that does not extend to the extreme values, an adaptive median noise removal filter does better (at least compared to this one example). Is it just that it needs to be 1D?
bruno
bruno am 18 Dez. 2022
well Im attaching a document that i captured from a research, it is basically saying relaxed median is used, the algorithm is given. how to do that summation and sorting part here
y= f(x);
fs=360;
window_size= abs((1/fs)*length(x)); %length(x) total samples
bruno
bruno am 18 Dez. 2022
DGM, I dont exactly understand. The paper i have with me is written all over the places. The only thing i can do is to see the impact of whatever I can do.
DGM
DGM am 18 Dez. 2022
If algo.pdf is what you were given to work with, I can see why you're confused. I'm having a hard time figuring out what's even being described. At once it describes using the global median as a filter and then it describes an adaptive filter bound by undescribed criteria.
It asserts that the input is y and then immediately contradicts itself by describing the output as y. It tells you to find the median by sorting the sample, then it tells you to find the median by using median(). It's unclear when it's talking about local and global information, and the expressions it gives confuse both.
Is there any other paperwork that came with this?
bruno
bruno am 18 Dez. 2022
My paper reads ( a signal preprocessing step is required to remove noise in ECG recordings. Remove the average of 500 samples from each sample obtained by ECG to avoid unwanted noise signals in the entering ECG waveform. The signal’s baseline amplitude is reduced to zero due to this action. The filter is tuned to allow low-frequency impulses while attenuating the high frequencies to minimize the noise of the high-frequency components The signal’s baseline amplitude is reduced to zero due to this action. The filter is tuned to allow low-frequency impulses while attenuating the high frequencies contained in the erratic ECG signal to minimize the noise of the high-frequency components. The high pass filter allows high frequencies while attenuating low frequencies to minimize low-frequency noise. denoising is crucial to predict anomalies more accurately. Denoising of the ECG signal is performed using a relaxed median filter. )
well this is what has been written, in order to understand this relaxed median term i tried to search out and found its mathematical form here
https://link.springer.com/article/10.1023/A:1008395514426
Image Analyst
Image Analyst am 18 Dez. 2022
I agree with DGM in the comment above. The description is very confusing, and it's not only due to it being (obviously) written by a non-native English speaker. It's ambiguous, confusing, contradictory, and basically indecipherable. w is not defined, fs is not defined, m is not defined, Step 2 is gibberish, step 4 seems completely unnecessary, "compared" in Step 6 is not defined, and the criteria in step 8 are not listed.
DGM
DGM am 18 Dez. 2022
Regarding the Hamza paper, without institutional access, I'm not going to spend $40 to find out what exactly they're doing. I trust that the Hamza paper is probably a better reference than the prior student paper or algo.pdf, but that's just an assumption.
Remove the average of 500 samples from each sample obtained by ECG to avoid unwanted noise signals in the entering ECG waveform. The signal’s baseline amplitude is reduced to zero due to this action.
To me, that seems like the baseline reduction is done with a box averaging filter instead of a median filter.
fk = ones(500,1)/500; % a box averaging filter kernel (assuming data is a column vector)
xavg = conv(x,fk,'same'); % local average of 500 samples
y = x-xavg; % remove baseline
The filter is tuned to allow low-frequency impulses while attenuating the high frequencies contained in the erratic ECG signal to minimize the noise of the high-frequency components. The high pass filter allows high frequencies while attenuating low frequencies to minimize low-frequency noise.
I'm not sure what filters you're intended to use for this part or what's canonically appropriate for ECG processing.
denoising is crucial to predict anomalies more accurately. Denoising of the ECG signal is performed using a relaxed median filter.
This is kind of the crux of the matter.
I suppose I could write something based on my vague understanding of what a relaxed median filter is, but I might be wrong in that regard.
I have an unpublished 2D adaptive median filter implementation that probably would work, but I'm pretty sure it's going to be dependent on some other things you might not have.

Melden Sie sich an, um zu kommentieren.

DGM
DGM am 18 Dez. 2022

0 Stimmen

I'm just going to throw this out there. See the attached file. I don't know if it's correct WRT the Hamza paper, but it seems to be some sort of plausible noise filter. I implemented this as a 2D filter. If you only need 1D, you might be able to use it as-is, but I haven't tested that. I'm just more used to dealing with 2D cases.
inpict0 = imread('cameraman.tif');
inpict = imnoise(inpict0,'salt & pepper',0.1);
outpict = rmedfilt(inpict,5);
imshow(inpict)
imshow(outpict)
I guess it works, but it's not very good. It doesn't take much noise to break it. Compare to an adaptive median filter:
Maybe I'm missing something.

Produkte

Version

R2018a

Gefragt:

am 16 Dez. 2022

Beantwortet:

DGM
am 18 Dez. 2022

Community Treasure Hunt

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

Start Hunting!

Translated by