%************************************************************************** 
%*File name  : Noise_Maker.m
%*Author     : DLS
%*Description: This script lets you add AWGN to '.08' raw extension 
%*             files from a source folder of present working directory to 
%*             destination directory based on SNR using matlab.
%**************************************************************************
clear all 
clc
close all
SNR = input('Enter SNR: ');
FolderSource = input('Enter Source Folder name: ','s');
FolderDestination = input('Enter Destination Folder name: ','s');
tic
mkdir(FolderDestination);
FolderSearchPath = fullfile(FolderSource, '*.08');
dinfo = dir(FolderSearchPath);
for K = 1 : length(dinfo)
 clear A z fid snr_file source_file;
 source_file = fullfile(FolderSource, dinfo(K).name);
 fid = fopen(source_file);
 A   = fread(fid, Inf, 'int16','b')/65536;
 z = awgn(A,SNR,'measured');
 fclose(fid); 
 snr_file = fullfile(FolderDestination, dinfo(K).name);
 fid = fopen(snr_file,'w');
fwrite(fid, z*65536, 'int16','b');
fclose(fid);
end
copyfile('Single_Player.m',FolderDestination);
copyfile('All_Player.m',FolderDestination);
disp('Operation completed');
toc
