# Explanation of the matlab code

조회 수: 260(최근 30일)
Jolini 2013년 6월 16일
댓글: Md Ibrahim 2020년 10월 18일
Hi I foun this 'extract' of a matlab code on the internet. Can someone explain to me line by line whats happening? Im REALLY in need of help.
*
% ------------- % This is code to make the edge detecting filter % ----%
function filter=gaussfilt(N)
% calculate alpha so the filter fills all N points
alpha=N;
first=-(1-N/2)*exp(-(1-N/2)^2/alpha);
count=0;
while first<.1*(-(1530/4000*N-N/2)*exp(-(1530/4000*N-N/2)^2/alpha))
count=count+1;
alpha=N*500*count;
first=-(1-N/2)*exp(-(1-N/2)^2/alpha);
end
for n=1:N
filter(n)=-(n-N/2)*exp(-(n-N/2)^2/alpha); % d/dt of a gaussian
end
filter=filter/sum(abs(filter)); % normalization
return
##### 댓글 수: 7표시숨기기 이전 댓글 수: 6
Md Ibrahim 2020년 10월 18일
vmax=8;
vmin=-vmax;
del=(vmax-vmin)/L;
part=vmin:del:vmax; % level are between vmin and vmax with difference of del
code=vmin-(del/2):del:vmax+(del/2); % Contain Quantized values
[ind,q]=quantiz(s,part,code); % Quantization process
% ind contain index number and q contain quantized values
l1=length(ind);
l2=length(q);
for i=1:l1
if(ind(i)~=0) % To make index as binary decimal so started from 0 to N
ind(i)=ind(i)-1;
end
i=i+1;
end
for i=1:l2
if(q(i)==vmin-(del/2)) % To make quantize value in between the levels
q(i)=vmin+(del/2);
end
end
subplot(3,1,3);
stem(q);grid on; % Display the Quantize values
title('Quantized Signal');
ylabel('Amplitude--->');
xlabel('Time--->');

댓글을 달려면 로그인하십시오.

### 채택된 답변

Muthu Annamalai 2013년 6월 19일
Your code calculates a filter kernel. I haven't run the code, but, it seems to me a kind of Gaussian filter, with some normalizations.
It could be rewritten like,
function filter=gaussfilt(N)
% calculate alpha so the filter fills all N points
alpha=N;
first=-(1-N/2)*exp(-(1-N/2)^2/alpha);
count=0;
% find the standard deviation for the Gaussian
while first<.1*(-(1530/4000*N-N/2)*exp(-(1530/4000*N-N/2)^2/alpha))
count=count+1;
alpha=N*500*count;
first=-(1-N/2)*exp(-(1-N/2)^2/alpha);
end
% calculate the filter kernel
n=1:N
filter =-(n-N/2).*exp(-(n-N/2).^2/alpha);
%normalize kernel & return
HTH
##### 댓글 수: 1표시숨기기 없음
Jolini 2013년 6월 20일
Hi. Thank you for the reply. Yes, its a Gaussian filter. I anyhow made some changes and I've finally understood it. I'm having trouble in finding peaks (maximum) of an enveloped signal. I've posted the question in MATLAB.. Would you be able to go through it and possibly help me out??

댓글을 달려면 로그인하십시오.

### 추가 답변(4개)

varshini rebala 2015년 3월 19일
Can any one explain me what is happing in this code ?
% Selected Mapping (SLM)is one of the techniques used for % peak-to-average power ratio (PAPR) reduction in OFDM systems. % In this .m file it is simulated for a QPSK modulated, 64-subband % OFDM symbols.
clc clear
load ofdm_100000 % this is a .mat file containing 100000 QPSK modulated, % 64-element OFDM symbols. It is available with the % partial_transmit_sequence.m file, previously submitted % by the auther, for free download at the 'file exchange' % web page.
NN=10000; % the test is achieved on 10000 OFDM symbols only. It is % possible to use all of the 100000 symbols, but it will % take more time. N=64; % number of subbands L=4; % oversampling factor C=16; % number of OFDM symbol candidates
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % phase factor matrix [B] generation p=[1 -1 j -j]; % phase factor possible values randn('state', 12345); B=randsrc(C,N,p); % generate N-point phase factors for each one of the % C OFDM candidates %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for i=1:NN % calculate papr of original ofdm time_domain_signal=abs(ifft([ofdm_symbol(i,1:32) zeros(1,(L-1)*N) ofdm_symbol(i,33:64)])); meano=mean(abs(time_domain_signal).^2); peako=max(abs(time_domain_signal).^2); papro(i)=10*log10(peako/meano);
% B*ofdm symbol
p=[];
for k=1:C
p=[p; B(k,:).*ofdm_symbol(i,:)];
end
% Transform Pi to Time Domain and find paprs
for k=1:C
pt(k,:)=abs(ifft([p(k,1:32) zeros(1,(L-1)*N) p(k,33:64)]));
papr(k)=10*log10(max(abs(pt(k,:)).^2)/mean(abs(pt(k,:)).^2));
end
% find papr_min
papr_min(i)=min(papr);
end
figure [cy,cx]=ccdf(papro,0.1); semilogy(cx,cy) % CCDF of PAPR of the original OFDM hold on [cy,cx]=ccdf(papr_min,0.1); semilogy(cx,cy,'r') % CCDF of the modified OFDM (by SLM)
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Sombaran Gupta 2015년 4월 13일
Can anyone explain me from the third line till the end of this code..?? a=imread('kmeans.jpg'); imshow(255-rgb2gray(a)); b=reshape(double(255-rgb2gray(a)),[],1); [idx,c]=kmeans(b,2,'emptyaction','singleton'); Fin_a=reshape(idx,[size(rgb2gray(a))]); [ind1, ind2]=find(Fin_a(:,:)==2); [ind3, ind4]=find(Fin_a(:,:)==1); figure(); imshow(255-rgb2gray(a)); hold on if(length(ind1)<length(ind3)) scatter(ind2,ind1,'g'); else scatter(ind4,ind3,'g');a end
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Tanzila Minhaj 2019년 9월 29일
Can anyone help me understanding the code?
function [sigma] = constitutive_Armstrong_Frederick (e, E, sigma_y, H_k, H_nl)
% The function reconstructs the trend of the stress-strain curve
% according to the constitutive link of Armstrong & Frederick
% e = deformation vector
% E = Young's modulus [Pa]
% sigma_y = yield stress [Pa]
% H_k = instant kinematic work hardening parameter [Pa]
% H_nl = hardening parameter by Armstrong & Frederick [Pa]
% Data initialization
sigma (1) = 0;
alpha (1) = 0;
state (1) = 0;
for n = 1: length (e) -1
% Stress calculation by elastic prediction
sigma_e = sigma (n) + E * (s (n + 1) -e (n));
% Increased effort assessed in the elastic prediction phase
dsigma_e = sigma_e-sigma (n);
% Purified elastic prediction of back stress
sigma_e_tilde = sigma_e-alpha (n);
% Evaluation of the yield function to less than a tolerance
fi (n) = abs (sigma (n) -alpha (n)) - sigma_y;
tol = 0.001;
if abs (fi (n)) <toll
fi (n) = 0;
end
% Recognition of the elastic / plastic phase by the function of
% yield and the direction of deformation
if fi (n) == 0 && (e (n + 1) -e (n)) * (e (n) -e (n-1))> 0
% Plastic phase
state (n + 1) = 1;
% Sign of tensions (+ = traction, - = compression)
sign = sign (dsigma_e);
% Increase in the plastic dlambda multiplier
dlambda = (a * sigma_e_tilde-sigma_y) / (a * (E + H_k) -H_nl * alpha (n));
% Increase in plastic deformation
de_pl = a * dlambda;
% Increase in back stress
Dalfa = H_k * de_pl-H_nl * abs (de_pl) * alpha (n);
% Back stress
alpha (n + 1) = alpha (n) + Dalfa;
% Current voltage
sigma (n + 1) = sign * sigma_y alpha + (n + 1);
else
% Elastic phase
state (n + 1) = 0;
sigma (n + 1) = sigma_e;
de_pl = 0;
alpha (n + 1) = alpha (n);
end
end
end
##### 댓글 수: 0표시숨기기 이전 댓글 수: -1

댓글을 달려면 로그인하십시오.

Ayshath Afra 2020년 4월 5일
Can anyone help me understanding the code?
How to obtain the read cbir function

댓글을 달려면 로그인하십시오.

### 범주

Find more on PHY Components 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!

Translated by