-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c36be49
commit 757b76e
Showing
14 changed files
with
1,719 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
function beta = PowerLawFit(y,x); | ||
% function beta = PowerLawFit(y,x); | ||
% fits the model y = beta(1) * x .^ beta(2) | ||
% using a reweighted linearized form | ||
|
||
logy = y.*log(y); | ||
sol = pinv(cat(1,y.*ones(size(x)),y.*log(x))')*logy'; | ||
beta = [exp(sol(1)), sol(2)]; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
function fontScale(scale) | ||
% function fontScale(scale) | ||
|
||
H = gcf; | ||
allText = findall(H, 'type', 'text'); | ||
allAxes = findall(H, 'type', 'axes'); | ||
allFont = [allText; allAxes]; | ||
fontSize = get(allFont,'FontSize'); | ||
|
||
newFontSize = LocalScale(fontSize, scale, 2); | ||
set(allFont,{'FontSize'},newFontSize); | ||
|
||
function newArray = LocalScale(inArray, scale, minValue) | ||
n = length(inArray); | ||
newArray = cell(n,1); | ||
for k=1:n | ||
newArray{k} = max(minValue,scale*inArray{k}(1)); | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
function [OptimumTheta MaxContrast]=simContrastvFlip(T1pair,TR,varargin) | ||
%% | ||
% function [OptimumTheta MaxContrast]=simContrastvFlip(T1pair,TR) | ||
% T1pair should be a vector with 2 T1 values | ||
% TR should be the value of the repetition time used | ||
% | ||
% this function plots the signal of a GRE sequence run with repetition time | ||
% TR as a function of the flip angle | ||
% additionally it calculates and plots the contrast that can be generated between | ||
% these two sample and its optimum flip angle | ||
% | ||
% the ouptput from the function are OptimumTheta and MaxContrast | ||
|
||
|
||
if ~exist('T1pair','var') || ~exist('TR','var') | ||
disp('ERROR: T1pair and TR must be specified') | ||
return | ||
end | ||
|
||
if length(T1pair)~=2 | ||
disp('ERROR: T1pair must contain 2 values') | ||
return | ||
end | ||
|
||
if ~exist('tColours','var') | ||
tColours = {[66 122 223]/255,[108 158 80]/255,[223 76 76]/255}; | ||
end | ||
|
||
if nargin>2 | ||
ShowFigure=varargin{1}; | ||
else | ||
ShowFigure=1; | ||
end; | ||
|
||
%% doing all the calculations | ||
|
||
theta = linspace(0,180,1000); | ||
sig = zeros(length(theta),2); | ||
for iT1 = 1:2 | ||
sig(:,iT1) = (1-exp(-TR/T1pair(iT1))).*sin(theta*pi/180)./(1-cos(theta*pi/180)*exp(-TR/T1pair(iT1))); | ||
end | ||
contrast=abs(sig(:,1)-sig(:,2)); | ||
[maximum position]=max(contrast); | ||
OptimumTheta=theta(position); | ||
MaxContrast=maximum; | ||
|
||
|
||
%% plotting the results | ||
if ShowFigure | ||
figure | ||
% set(gcf,'Position',[ 50 679 740 409]) | ||
set(gcf,'Position',[ 36 719 517 400]) | ||
set(gcf,'Color',[1 1 1]); | ||
plot(theta,sig(:,1),'linewidth',2,'color',tColours{1}); hold all | ||
plot(theta,sig(:,2),'linewidth',2,'color',tColours{2}); | ||
h1 = plot(theta,contrast); | ||
set(h1,'linewidth',2,'color','k') | ||
xlabel('Flip Angle (degrees)') | ||
ylabel('Relative signal') | ||
grid on | ||
title(['TR = ' num2str(TR) 'ms']) | ||
legend(['T1 = ' num2str(T1pair(1)) 'ms'], ['T1 = ' num2str(T1pair(2)) 'ms'], 'Contrast'); | ||
xlim([0 180]) | ||
text(45 ,maximum,['Optimum Flip=',num2str(round(OptimumTheta)),'degrees']) | ||
text(45 ,maximum*2,['Max Contrast=',num2str(round(maximum*1000)/1000),' ']) | ||
fontScale(1.2) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
function OptimumTE=simContrastvTE(T2pair,varargin) | ||
%% usage function OptimumTE=simContrastvTE(T2pair,varargin) | ||
% T2pair should be a vector with 2 T2 values | ||
% | ||
% this function plots the signal as a function of the echo time for two | ||
% samples with different T2s | ||
% additionally it calculates the contrast as a function of TE and finds the | ||
% optimum echo time | ||
|
||
|
||
%% check if the correct variables exist | ||
if ~exist('T2pair','var') | ||
disp('ERROR: T2pair must be specified') | ||
return | ||
end | ||
|
||
if length(T2pair)~=2 | ||
disp('ERROR: T2pair must contain 2 values') | ||
return | ||
end | ||
|
||
if ~exist('tColours','var') | ||
tColours = {[66 122 223]/255,[108 158 80]/255,[223 76 76]/255}; | ||
end | ||
if nargin>1 | ||
ShowFigure=varargin{1}; | ||
else | ||
ShowFigure=1; | ||
end; | ||
|
||
%% compute signal evolution as function of echo time | ||
|
||
TE_vals = linspace(0,200,1000); | ||
sig = zeros(length(TE_vals),2); | ||
for iT2 = 1:2 | ||
sig(:,iT2) = (exp(-TE_vals/T2pair(iT2))); | ||
end | ||
contrast=abs(sig(:,1)-sig(:,2)); | ||
[maximum position]=max(contrast); | ||
OptimumTE=TE_vals(position); | ||
|
||
|
||
|
||
|
||
%% plot results | ||
if ShowFigure | ||
figure | ||
% set(gcf,'Position',[ 50 679 740 409]) | ||
set(gcf,'Position',[ 75 306 400 400]) | ||
set(gcf,'Color',[1 1 1]); | ||
|
||
plot(TE_vals,sig(:,1),'linewidth',2,'color',tColours{1}); hold all | ||
plot(TE_vals,sig(:,2),'linewidth',2,'color',tColours{2}); | ||
h1 = plot(TE_vals,contrast); | ||
set(h1,'linewidth',2,'color','k') | ||
xlabel('TE (ms)') | ||
ylabel('Relative signal') | ||
grid on | ||
legend(['T2 = ' num2str(T2pair(1)) 'ms'], ['T2 = ' num2str(T2pair(2)) 'ms'], 'Contrast'); | ||
text(OptimumTE ,0.5,['Optimum TE=',num2str(round(OptimumTE)),'ms']) | ||
|
||
fontScale(1.2) | ||
end; |
Oops, something went wrong.