read.m

来自「几个很好的OFDM仿真程序」· M 代码 · 共 46 行

M
46
字号
% read
%input_type==2
%file_input_type==3
% ******************FILE INPUT SETUP*********************************
if input_type == 2

	if file_input_type == 1
		%binary file input
	end

	if file_input_type == 2
		%text file input
		file = fopen(file_name,'rt');
		data_samples = fread(file,'char');
		fclose(file);
		data_in = zeros(1,8*length(data_samples));
		for i = 1:length(data_samples)
			data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples(i));
		end
	end

    %**********************************************************************
    %*****************
	if file_input_type == 3
		%sound file input
        file_name;
		data_samples=wavread(file_name);
		%needs to be normalized from -1:1 to 0:255 for 8 bit conversion
		data_samples_resized = round(128*data_samples +127);
        length(data_samples_resized);
      	data_in = zeros(1,8*length(data_samples_resized));
		for i = 1:length(data_samples_resized)
			data_in(1 + (i-1)*8:(i-1)*8 + 8) = eight2bin(data_samples_resized(i));
		end
        
        data_in;
	end
	
	if file_input_type == 4
		%image file input
		[data_in,map]=imread(file_name);	% read image and corresponding color map for display
		
	end

end

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?