a_1 = 1;
a_2 = sqrt(0.1);
l = -10:10;
t = 1e-6;
N = 10^6 ;
SNR = 0:10; % Valeurs du SNR en dB
a = 1/sqrt(2) ;
Es = 2*a^2 ;
QPSK = [1+1i, 1-1i, -1-1i, -1+1i];
X_QPSK = sqrt(Es/2)*(QPSK(randi(length(QPSK),1,N)));
W = [0, 250000,50000, 500000, 1000000] ; % Vecteur des frequences
H = cell(zeros(1,length(W))) ;
Vecteur_convolution = cell(zeros(1,length(W))) ; % convolution output
Sortie = cell(zeros(1,length(W))) ;
h0 = a_1*sinc(l)+ a_2*sinc(l-t*W(1));
h1 = a_1*sinc(l)+ a_2*sinc(l-t*W(2));
h2 = a_1*sinc(l)+ a_2*sinc(l-t*W(3));
h3 = a_1*sinc(l)+ a_2*sinc(l-t*W(4));
h4 = a_1*sinc(l)+ a_2*sinc(l-t*W(5));
H{1,1} = h0 ;
H{1,2} = h1 ;
H{1,3} = h2 ;
H{1,4} = h3;
H{1,5} = h4;
for i = 1:length(W)
Vecteur_convolution{1,i} = conv(X_QPSK, H{i}) ;
Sortie{1,i} = Vecteur_convolution{i(10:lenght(X_QPSK ))} % Not correct
end
% By the way, if I write it like this, it works. But I'm trying to make it compact if possible
Sconv0 = conv(x_QPSK,h0);
S0 = Sconv0(length(SNR):length(SNR)+length(X_QPSK) - 1);
% Pour W = 50 KHz
Sconv50K = conv(x_QPSK,h1);
S50K = Sconv50K(length(SNR):length(SNR)+length(X_QPSK) - 1);
% Pour W = 250 KHz
Sconv250K = conv(x_QPSK,h2);
S250K = Sconv250K(length(SNR):length(SNR)+length(X_QPSK) - 1);
% Pour W = 500 KHz
Sconv500K = conv(x_QPSK,h3);
S500K = Sconv500K(length(SNR):length(SNR)+length(X_QPSK) - 1);
% Pour W = 1 MHz
Sconv1M = conv(x_QPSK,4);
S1M = Sconv1M(length(SNR):length(SNR)+length(X_QPSK) - 1);
Good morning folks. I'm not sure what I'm trying to do is possible in Matlab, but here it goes. I'm doing a convolution and storing the output in " Vecteur_convolution", so it's a 1x5 cell. Because the convolution increases the number of points, I only want to retrieve my sample number back (1.000.000) instead of (1000010) and store it into the "Sortie" 1x5 cell.Any help would be appreciated.
Related
The following is my implementation of a paper for cauchy noise removal.
The psnr value of the noisy image is 19 as the paper but when I compute the psnr value for the restored image un, it returns 17 which is even smaller than the psnr value of the noisy image. I guess there is something wrong in psnr computation with my code.
%%
clear memory;
clear all
close all
clc;
%% Initialization
refimg = im2double(imread('cameraman256.png')); % original image
img_height = size(refimg,1);
img_width = size(refimg,2);
refimg = refimg(1:img_height,1:img_width);
padNum = 5;
refimg = padarray(refimg,[padNum,padNum],'symmetric');
[mm,nn]=size(refimg);
img_height = size(refimg,1);
img_width = size(refimg,2);
%% Producing the degraded image
A = 1; % A =1 for image denoising
sz = size(refimg);
rng(0);
r1 = randn(sz); % (using randn because I don't have the statistics toolbox)
r2 = randn(sz);
n = 0.02; % the noise level
u0 = refimg + n.*(r1./r2);
u0 = min(u0,1); % clamp large values to 1
u0 = max(u0,0); % clamp small values to 0
figure(1); imshow(u0(padNum+1:mm-padNum,padNum+1:nn-padNum),'border','tight');
%% Initial values for the primal-dual algorithm
tol = 1e-3;
nIter = 1e3;
options.order = 1; options.bound = 'sym';
un = u0;
wn = u0;
bun = un;
bwn = wn;
pxn = zeros(ny,nx);
pyn = zeros(ny,nx);
q = zeros(ny,nx);
[gxn,gyn] = grad(u0,options);
bgxn = gxn;
bgyn = gyn;
gamma = sqrt(2)/10;
lambda = 0.7;
mu = 6.25;
tau = 0.3;
sigma = 0.3;
%% Primal-dual Algorithm
for j = 1:nIter
%%%%%%%%%%solve the subproblem p
[ux,uy]=grad(bun,options);
pxn = pxn+sigma*(bgxn-ux);
pyn = pyn+sigma*(bgyn-uy);
%%%%%%%%%%%solve the subproblem q
AUk = Au(bun);
q = q+sigma*(bwn-AUk);
%%%%%%%%%%solve the subproblem g
goldxn = gxn;
goldyn = gyn;
txn = gxn-tau*pxn;
tyn = gyn-tau*pyn;
sn = max(1e-6,sqrt(txn.^2+tyn.^2));
gxn = txn./sn.*max(0,sn-tau);
gyn = tyn./sn.*max(0,sn-tau);
%%%%%%%%%%%solve the subproblem wn
u_medfilter = medfilt2(u0);
wold = wn;
a = mu.*lambda.*tau+1;
b = -(mu.*lambda.*tau.*(2.*u0+u_medfilter)-tau.*q+2.*u0+wold);
c = tau.*lambda+mu.*lambda.*tau.*(gamma.^2+u0.^2+2.*u_medfilter.*u0)-2.*tau.*q.*u0+...
gamma.^2+u0.^2+2.*wold.*u0;
d = -tau.*lambda.*u0-mu.*lambda.*tau.*u_medfilter.*(gamma.^2+u0.^2)+tau.*q.*(gamma.^2+u0.^2)...
-wold.*(gamma.^2+u0.^2);
qval = (3.*a.*c-(b.^2))./(9.*(a.^2));
rval = (9.*a.*b.*c-27.*(a.^2).*d-2.*(b.^3))./(54.*(a.^3));
deltaval = qval.^3+rval.^2;
wn = nthroot(rval+real(sqrt(deltaval)),3)+nthroot(rval-real(sqrt(deltaval)),3)-((b)./(3.*a));
%%%%%%%%%%%solve the subproblem un
uold = un;
Asqk = Atu(q);
un = un+tau*(Asqk-div(pxn,pyn,options)); % the restored image
% un = min(1,max(0.01,un));
if (norm(un-uold, 'fro')/norm(uold,'fro')<tol)
break;
end
bun = 2*un-uold;
bwn = 2*wn-wold;
bgxn = 2*gxn-goldxn;
bgyn = 2*gyn-goldyn;
% PSNR_restoredimage = psnr(refimg(padNum+1:mm-padNum,padNum+1:nn-b
padNum),un(padNum+1:mm-padNum,padNum+1:nn-padNum))
end
%% Dispaly results
New_un = un;
refimg = refimg(padNum+1:mm-padNum,padNum+1:nn-padNum);
u0 = u0(padNum+1:mm-padNum,padNum+1:nn-padNum);
u_medfilter = u_medfilter(padNum+1:mm-padNum,padNum+1:nn-padNum);
New_un = New_un(padNum+1:mm-padNum,padNum+1:nn-padNum);
PSNR_noisy = psnr(refimg,u0)
PSNR_med = psnr(refimg,u_medfilter)
PSNR_restoredimage = psnr(New_un,refimg)
figure(2); imshow([refimg,u_medfilter,New_un],'border','tight');
%%
The problem was not in psnr computation. The problem with my code in this question was that I was considering the denoising case but I had forgotten to omit the blur kernel in primal-dual algorithm. Also, the initial parameters corresponding to the deblurring case must be zero. The following is the corrected code. Now the psnr value is 28 similar to the paper.
%%
clear;
%% Initialization
refimg = im2double(imread('cameraman256.png')); % original image
img_height = size(refimg,1);
img_width = size(refimg,2);
refimg = refimg(1:img_height,1:img_width);
%% Producing the noisy image
sz = size(refimg);
rng(0);
r1 = randn(sz); % (using randn because I don't have the statistics toolbox)
r2 = randn(sz);
n = 0.02; % the noise level
u0 = refimg + n.*(r1./r2);
u0 = min(u0,1); % clamp large values to 1
u0 = max(u0,0); % clamp small values to 0
figure(1); imshow(u0,'border','tight');
%% Initial values for the primal-dual algorithm
init = u0;
[ny,nx] = size(init);
tol = 1e-3;
nIter = 1e3;
options.order = 1; options.bound = 'sym';
un = u0;
wn = zeros(ny,nx);
bun = un;
bwn = zeros(ny,nx);
pxn = zeros(ny,nx);
pyn = zeros(ny,nx);
q = zeros(ny,nx);
[gxn,gyn] = grad(u0,options);
bgxn = gxn;
bgyn = gyn;
gamma = sqrt(2)/10;
lambda = 0.7;
mu = 6.25;
tau = 0.3;
sigma = 0.3;
%% Primal-dual Algorithm
for j = 1:nIter
%%%%%%%%%%solve the subproblem p
[ux,uy]=grad(bun,options);
pxn = pxn+sigma*(bgxn-ux);
pyn = pyn+sigma*(bgyn-uy);
%%%%%%%%%%%solve the subproblem q
AUk = bun;
q = q+sigma*(bwn-AUk);
%%%%%%%%%%solve the subproblem g
goldxn = gxn;
goldyn = gyn;
txn = gxn-tau*pxn;
tyn = gyn-tau*pyn;
sn = max(1e-6,sqrt(txn.^2+tyn.^2));
gxn = txn./sn.*max(0,sn-tau);
gyn = tyn./sn.*max(0,sn-tau);
%%%%%%%%%%%solve the subproblem wn
u_medfilter = medfilt2(u0);
wold = wn;
a = mu.*lambda.*tau+1;
b = -(mu.*lambda.*tau.*(2.*u0+u_medfilter)-tau.*q+2.*u0+wold);
c = tau.*lambda+mu.*lambda.*tau.*(gamma.^2+u0.^2+2.*u_medfilter.*u0)-2.*tau.*q.*u0+...
gamma.^2+u0.^2+2.*wold.*u0;
d = -tau.*lambda.*u0-mu.*lambda.*tau.*u_medfilter.*(gamma.^2+u0.^2)+tau.*q.*(gamma.^2+u0.^2)...
-wold.*(gamma.^2+u0.^2);
qval = (3.*a.*c-(b.^2))./(9.*(a.^2));
rval = (9.*a.*b.*c-27.*(a.^2).*d-2.*(b.^3))./(54.*(a.^3));
deltaval = qval.^3+rval.^2;
wn = nthroot(rval+real(sqrt(deltaval)),3)+nthroot(rval-real(sqrt(deltaval)),3)-((b)./(3.*a));
%%%%%%%%%%%solve the subproblem un
uold = un;
Asqk = q;
un = un+tau*(Asqk-div(pxn,pyn,options)); % the restored image
if (norm(un-uold, 'fro')/norm(uold,'fro')<tol)
break;
end
bun = 2*un-uold;
bwn = 2*wn-wold;
bgxn = 2*gxn-goldxn;
bgyn = 2*gyn-goldyn;
end
%% Dispaly results
PSNR_noisy = psnr(u0,refimg)
PSNR_med = psnr(u_medfilter,refimg)
PSNR_restoredimage = psnr(un,refimg)
figure(2); imshow([refimg,u_medfilter,un],'border','tight');
%%
I am writing a for loop to calculate the value of four different variables. The first variable is M. M increases from 10^2 to 10^5,
M = [10^2,10^3,10^4,10^5];
The other three variables needed for the table are shown in the code below.
confmc
confcv
confmcSize/confcvSize
I first create a for loop to iterate through the four different values of M. I then create the table outside of the for loop.
How could I adjust the implementation so that the table displays all four values of M?
randn('state',100)
%%%%%% Problem and method parameters %%%%%%%%%
S = 5; E = 6; sigma = 0.3; r = 0.05; T = 1;
Dt = 1e-2; N = T/Dt; M = [10^2,10^3,10^4,10^5];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
for k=1:numel(M)
%%%%%%%%% Geom Asian exact mean %%%%%%%%%%%%
sigsqT= sigma^2*T*(N+1)*(2*N+1)/(6*N*N);
muT = 0.5*sigsqT + (r - 0.5*sigma^2)*T*(N+1)/(2*N);
d1 = (log(S/E) + (muT + 0.5*sigsqT))/(sqrt(sigsqT));
d2 = d1 - sqrt(sigsqT);
N1 = 0.5*(1+erf(d1/sqrt(2)));
N2 = 0.5*(1+erf(d2/sqrt(2)));
geo = exp(-r*T)*( S*exp(muT)*N1 - E*N2 );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Spath = S*cumprod(exp((r-0.5*sigma^2)*Dt+sigma*sqrt(Dt)*randn(M(k),N)),2);
% Standard Monte Carlo
arithave = mean(Spath,2);
Parith = exp(-r*T)*max(arithave-E,0); % payoffs
Pmean = mean(Parith);
Pstd = std(Parith);
confmc = [Pmean-1.96*Pstd/sqrt(M(k)), Pmean+1.96*Pstd/sqrt(M(k))];
confmcSize = [(Pmean+1.96*Pstd/sqrt(M(k)))-(Pmean-1.96*Pstd/sqrt(M(k)))];
% Control Variate
geoave = exp((1/N)*sum(log(Spath),2));
Pgeo = exp(-r*T)*max(geoave-E,0); % geo payoffs
Z = Parith + geo - Pgeo; % control variate version
Zmean = mean(Z);
Zstd = std(Z);
confcv = [Zmean-1.96*Zstd/sqrt(M(k)), Zmean+1.96*Zstd/sqrt(M(k))];
confcvSize = [(Zmean+1.96*Zstd/sqrt(M(k)))-(Zmean-1.96*Zstd/sqrt(M(k)))];
end
T = table(M,confmc,confcv,confmcSize/confcvSize)
The current code returns
T =
1×4 table
M confmc confcv Var4
_____ ____________________ ____________________ ______
1e+05 0.096756 0.1007 0.097306 0.097789 8.1622
How could I change my implementation so that all four values of M are computed?
I just modified few things.Take a look at the following code.
randn('state',100)
%%%%%% Problem and method parameters %%%%%%%%%
S = 5; E = 6; sigma = 0.3; r = 0.05; T = 1;
Dt = 1e-2; N = T/Dt; M = [10^2,10^3,10^4,10^5];
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
confmc = zeros(numel(M), 2);
confcv = zeros(numel(M), 2);
confmcSize = zeros(numel(M), 1);
confcvSize = zeros(numel(M), 1);
for k=1:numel(M)
%%%%%%%%% Geom Asian exact mean %%%%%%%%%%%%
sigsqT= sigma^2*T*(N+1)*(2*N+1)/(6*N*N);
muT = 0.5*sigsqT + (r - 0.5*sigma^2)*T*(N+1)/(2*N);
d1 = (log(S/E) + (muT + 0.5*sigsqT))/(sqrt(sigsqT));
d2 = d1 - sqrt(sigsqT);
N1 = 0.5*(1+erf(d1/sqrt(2)));
N2 = 0.5*(1+erf(d2/sqrt(2)));
geo = exp(-r*T)*( S*exp(muT)*N1 - E*N2 );
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Spath = S*cumprod(exp((r-0.5*sigma^2)*Dt+sigma*sqrt(Dt)*randn(M(k),N)),2);
% Standard Monte Carlo
arithave = mean(Spath,2);
Parith = exp(-r*T)*max(arithave-E,0); % payoffs
Pmean = mean(Parith);
Pstd = std(Parith);
confmc(k,:) = [Pmean-1.96*Pstd/sqrt(M(k)), Pmean+1.96*Pstd/sqrt(M(k))];
confmcSize(k,1) = [(Pmean+1.96*Pstd/sqrt(M(k)))-(Pmean-1.96*Pstd/sqrt(M(k)))];
% Control Variate
geoave = exp((1/N)*sum(log(Spath),2));
Pgeo = exp(-r*T)*max(geoave-E,0); % geo payoffs
Z = Parith + geo - Pgeo; % control variate version
Zmean = mean(Z);
Zstd = std(Z);
confcv(k,:) = [Zmean-1.96*Zstd/sqrt(M(k)), Zmean+1.96*Zstd/sqrt(M(k))];
confcvSize(k,1) = [(Zmean+1.96*Zstd/sqrt(M(k)))-(Zmean-1.96*Zstd/sqrt(M(k)))];
end
T = table(M',confmc,confcv,confmcSize./confcvSize)
In short, I just used a matrix instead of a vector or scalar as the members of the table. In your code, the variables (confmc, confcv, confmcSize, confcvSize) were getting overwritten.
I've encountered a serious problem whan compiling my math work on matlab so can someone help me with this error so this is the matlab code:
% Main program for solving the system F C
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
clear X;
clear x;
clear y;
clear z;
clear U;
clear V;
clear W;
clear MSx;
clear MSy;
clear MSz;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Données du problème
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
N = input('Donner le nombre des points de discretisation dans le temp N=');
a = 0;
b = 50;
T = b-a;
k = T/N;
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
x = 1;
y = 1.5;
z = 0.3;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
t = zeros(N+1,1);
for n = 1:N+1
t(n) = (n-1)*k;
end
MSx = zeros(N+1,1);
MSy = zeros(N+1,1);
MSz = zeros(N+1,1);
%
MSx(1,1) = x;
MSy(1,1) = y;
MSz(1,1) = z;
%
U = x;
V = y;
W = z;
%
X = zeros(3,1);
X = [U; V; W];
%
T1 = 0.2*N/T;
T2 = 0.5*N/T;
%
for n = 1:T1
t(n) = (n-1)*k;
%
Un = U;
Vn = V;
Wn = W;
%
X = [Un; Vn; Wn];
%
U = U + k*MSy(n,1)-k*8*MSx(n,1);
%
V = V+k*MSz(n,1)-k*1.02*MSy(n,1);
%
W = W+ k*[cos(sqrt(2)*t(n))+cos(sqrt(3)*t(n))+1/(1+t(n)^2)-(1/(1+t(n)^2)-3.02)*MSz(n,1)+(9.02*(1/(1+t(n)^2)-1)-1.02)*MSy(n,1)- 64*(1/(1+t(n)^2)-1)*MSx(n,1)-0.0004*sin(sqrt(2)*t(n))*(MSy(n,1)-8*MSx(n,1))
-0.0001*cos(sqrt(3)*t(n))*(abs(MSx(1,1)+1)-abs(MSx(1,1)-1)+abs(MSx(1,1)+1)-abs(MSx(1,1)-1))];
%
MSx(n+1,1) = U;
MSy(n+1,1) = V;
MSz(n+1,1) = W;
end
%U = MSx(T1+1,1);
%V = MSy(T1+1,1);
%W = MSz(T1+1,1);
%
for n = T1+1:T2
t(n) = (n-1)*k;
%
Un = U;
Vn = V;
Wn = W;
%
X = [Un; Vn; Wn];
%
U = U+k*(MSy(n,1)-8*MSx(n,1));
V = V+k*(MSz(n,1)-1.02*MSy(n,1));
W = W+ k*[cos(sqrt(2)*t(n))+cos(sqrt(3)*t(n))+1/(1+t(n)^2)-(1/(1+t(n)^2)-3.02)*MSz(n,1)+(9.02*(1/(1+t(n)^2)-1)-1.02)*MSy(n,1)- 64*(1/(1+t(n)^2)-1)*MSx(n,1)-0.0004*sin(sqrt(2)*t(n))*(MSy(n,1)-8*MSx(n,1))
-0.0001*cos(sqrt(3)*t(n))*(abs(MSx(1,1)+1)-abs(MSx(1,1)-1)+abs(MSx(n-T1,1)+1)-abs(MSx(n-T1,1)-1))] ;
%
%
MSx(n+1,1) = U;
MSy(n+1,1) = V;
MSz(n+1,1) = W;
end
%V = MSy(T2+1,1);
%W = MSz(T2+1,1);
%
for n = T2+1:N
t(n) = (n-1)*k;
%
Un = U;
Vn = V;
Wn = W;
%
X = [Un;Vn;Wn];
%
U = U+k*(MSy(n,1)-8*MSx(n,1));
%
V = V+k*(MSz(n,1)-1.02*MSy(n,1));
%
W = W+ k*[cos(sqrt(2)*t(n))+cos(sqrt(3)*t(n))+1/(1+t(n)^2)-(1/(1+t(n)^2)-3.02)*MSz(n,1)+(9.02*(1/(1+t(n)^2)-1)-1.02)*MSy(n,1)- 64*(1/(1+t(n)^2)-1)*MSx(n,1)-0.0004*sin(sqrt(2)*t(n))*(MSy(n,1)-8*MSx(n,1))
-0.0001*cos(sqrt(3)*t(n))*(abs(MSx(n-T2,1)+1)-abs(MSx(n-T2,1)-1)+abs(MSx(n-T1,1)+1)-abs(MSx(n-T1,1)-1))];
%
MSx(n+1,1) = U;
MSy(n+1,1) = V;
MSz(n+1,1) = W;
end
%
tv = t(1:1:N+1,1);
tv1 = t(1:1:N+1,1);
Su = MSx(1:1:N+1,1);
Sv = MSy(1:1:N+1,1);
Sw = MSz(1:1:N+1,1);
plot(tv,Su,'-')
hold all
plot(tv,Sv,'-')
hold all
plot (tv, Sw,'-')
So when it ask me to give an input like:
"Donner le nombre des points de discretisation dans le temp N="
I give it a number like 50000 so it gives me that error :
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Error in third (line 75)
MSz(n+1,1) = W;
It is because your W is not a singleton, which means a scalar in this case.
You wrote W as
W = W+ k*[cos(sqrt(2)*t(n))+cos(sqrt(3)*t(n))+1/(1+t(n)^2)-(1/(1+t(n)^2)-3.02)*MSz(n,1)+(9.02*(1/(1+t(n)^2)-1)-1.02)*MSy(n,1)- 64*(1/(1+t(n)^2)-1)*MSx(n,1)-0.0004*sin(sqrt(2)*t(n))*(MSy(n,1)-8*MSx(n,1))
-0.0001*cos(sqrt(3)*t(n))*(abs(MSx(1,1)+1)-abs(MSx(1,1)-1)+abs(MSx(1,1)+1)-abs(MSx(1,1)-1))];
If you want to change line in the middle of an expression, you need to add three dots, i.e. ... at the end of the line.
So you need to replace the line with:
W = W+ k*[cos(sqrt(2)*t(n))+cos(sqrt(3)*t(n))+1/(1+t(n)^2)-(1/(1+t(n)^2)-3.02)*MSz(n,1)+(9.02*(1/(1+t(n)^2)-1)-1.02)*MSy(n,1)- 64*(1/(1+t(n)^2)-1)*MSx(n,1)-0.0004*sin(sqrt(2)*t(n))*(MSy(n,1)-8*MSx(n,1))...
-0.0001*cos(sqrt(3)*t(n))*(abs(MSx(1,1)+1)-abs(MSx(1,1)-1)+abs(MSx(1,1)+1)-abs(MSx(1,1)-1))];
You also have a multiplicity of this problem further down.
I am trying to reconstruct an image using the projections from the Neutron image scanner. I am using the following code. I am not able to obtain a meaningful reconstructed image.
Can anybody advise me on where I am going wrong.
much appreciated,
Vani
filename = strcat(' Z:\NIST_Data\2016\SEPT\example reconstructed\carboxylic\carboxylic reconstructed part 3\Coral\',srcFiles(i).name);
I=imread(filename);
P = im2double(I);
if i == 1
array3d = P;
else
array3d = cat(3, array3d, P);
end
end
num = size(array3d,3);
for p = 1:num
PR = double(squeeze(array3d(p,:,:)));
[L,C]=size(PR);
w = [-pi : (2*pi)/L : pi-(2*pi)/L];
Filt = abs(sin(w));
Filt = Filt(1:463);
for i = 1:C,
IMG = fft(PR(:,i));
end
FiltIMG = IMG*Filt; %FiltIMG = filter (b, a, IMG);
% Remove any remaining imaginary parts
FIL = real(FiltIMG);
% filter the projections
%filtPR = projfilter(PR);
%filtPR = filterplus(PR);
filtPR = FIL;
THETA=0:180;
% figure out how big our picture is going to be.
n = size(filtPR,1);
sideSize = n;
% convert THETA to radians
th = (pi/180)*THETA;
% set up the image
m = length(THETA);
BPI = zeros(sideSize,sideSize);
% find the middle index of the projections
midindex = (n+1)/2;
% set up x and y matrices
x = 1:sideSize;
y = 1:sideSize;
[X,Y] = meshgrid(x,y);
xpr = X - (sideSize+1)/2;
ypr = Y - (sideSize+1)/2;
% loop over each projection
%figure
%colormap(jet)
%M = moviein(m);
for i = 1:m
tic
disp(['On angle ', num2str(THETA(i))]);
% figure out which projections to add to which spots
filtIndex = round(midindex + xpr*sin(th(i)) - ypr*cos(th(i)));
% if we are "in bounds" then add the point
BPIa = zeros(sideSize,sideSize);
spota = find((filtIndex > 0) & (filtIndex <= n));
newfiltIndex = filtIndex(spota);
BPIa(spota) = filtPR(newfiltIndex(:),i);
%keyboard
BPI = BPI + BPIa;
toc
%imagesc(BPI)
%M(:,i) = getframe;
%figure(2)
%plot(filtPR(:,i));
%keyboard
end
BPI = BPI./m;
h=figure
imagesc(BPI)
saveas(h,sprintf('filtsli-FIG%d.tif',p));end
Okay, so i'm struggling with this one. The code below works to how i need it to, however, i'm sure it could be shorter and simpler. I am aware that i could possibly use a for loop in order to make it shorter i just don't know how, could anyone point me in the right direction in doing this. Thanks :)
if it's not clear form the code what i'm trying to do. I'm trying to convolve separate signals and room impulse responses together using a different process other than the convolution function
close all;
clear all;
[x Fs] = wavread('bass.wav');
[x2] = wavread('drums.wav');
[x3] = wavread('bongo.wav');
[x4] = wavread('shaker.wav');
[x5] = wavread('gtr.wav');
hrir = wavread('HRIR_RR.wav');
hrir2 = wavread('HRIR_RL.wav');
hrir3 = wavread('HRIR_FR.wav');
hrir4 = wavread('HRIR_FL.wav');
hrir5 = wavread('HRIR_C.wav');
hrir_L = hrir(:,1);
hrir_R = hrir(:,2);
hrir_L2 = hrir2(:,1);
hrir_R2 = hrir2(:,2);
hrir_L3 = hrir3(:,1);
hrir_R3 = hrir3(:,2);
hrir_L4 = hrir4(:,1);
hrir_R4 = hrir4(:,2);
hrir_L5 = hrir5(:,1);
hrir_R5 = hrir5(:,2);
L = length(x) + length(hrir) -1; % Output data length
X = fft([x ; zeros(length(hrir_L),1)]);
HL = fft([hrir_L ; zeros(length(x),1)]);
HR = fft([hrir_R ; zeros(length(x),1)]);
L2 = length(x2) + length(hrir2) -1; % Output data length
X2 = fft([x2 ; zeros(length(hrir_L2),1)]);
HL2 = fft([hrir_L2 ; zeros(length(x2),1)]);
HR2 = fft([hrir_R2 ; zeros(length(x2),1)]);
L3 = length(x3) + length(hrir3) -1; % Output data length
X3 = fft([x3 ; zeros(length(hrir_L3),1)]);
HL3 = fft([hrir_L3 ; zeros(length(x3),1)]);
HR3 = fft([hrir_R3 ; zeros(length(x3),1)]);
L4 = length(x4) + length(hrir4) -1; % Output data length
X4 = fft([x4 ; zeros(length(hrir_L4),1)]);
HL4 = fft([hrir_L4 ; zeros(length(x4),1)]);
HR4 = fft([hrir_R4 ; zeros(length(x4),1)]);
L5 = length(x5) + length(hrir5) -1; % Output data length
X5 = fft([x5 ; zeros(length(hrir_L5),1)]);
HL5 = fft([hrir_L5 ; zeros(length(x5),1)]);
HR5 = fft([hrir_R5 ; zeros(length(x5),1)]);
out_L = zeros(L,1); % output buffer
out_R = zeros(L,2);
out_L2 = zeros(L2,1); % output buffer
out_R2 = zeros(L2,2);
out_L3 = zeros(L3,1); % output buffer
out_R3 = zeros(L3,2);
out_L4 = zeros(L4,1); % output buffer
out_R4 = zeros(L4,2);
out_L5 = zeros(L5,1); % output buffer
out_R5 = zeros(L5,2);
out_L = ifft(X .* HL); % multiplication of fft results & ifft
out_R = ifft(X .* HR);
out_L2 = ifft(X2 .* HL2); % multiplication of fft results & ifft
out_R2 = ifft(X2 .* HR2);
out_L3 = ifft(X3 .* HL3); % multiplication of fft results & ifft
out_R3 = ifft(X3 .* HR3);
out_L4 = ifft(X4 .* HL4); % multiplication of fft results & ifft
out_R4 = ifft(X4 .* HR4);
out_L5 = ifft(X5 .* HL5); % multiplication of fft results & ifft
out_R5 = ifft(X5 .* HR5);
out_L = out_L + out_L2 + out_L3 + out_L4 + out_L5;
out_R = out_R + out_R2 + out_R3 + out_R4 + out_R5;
out = [out_L out_R];
sound(out, Fs)
You could try using cell arrays. These are general containers for all types of data:
fn = {'a.wav','b.wav','c.wav'}
for i=1:length(fn)
h{i} = wavread(fn{i})
hrir_L{i} = h{i}(:,1);
hrir_R{i} = h{i}(:,2);
....
end