Matlab读取S2P文件

时间:2024-10-13 06:26:12

1、请查看S2P文件是否如下格式# hz S ma R 50# HZ S RI R 50

2、保存以下脚本function [FRE S11 S21 S12 S22 noise] = ReadS2P(f足毂忍珩ilename) file = fopen(filename); file_temp_s = fopen(".s_parameter_temp.t", 'w'); file_temp_n = fopen(".noise_temp.t", "w"); status = 0; sParameter_context = []; nNoise_context = []; paramete_type = ''; while 1 line = fgetl(file); if(length(line) == 0) continue; end; if(~ischar(line)) break;end if(status == 0 && line(1) == '#') status = 1; paramete_type = line; continue; end if((status == 1 || status == 2) && line(1) ~= '!') status = 2; %sParameter_context = strcat(sParameter_context, line); fprintf(file_temp_s, "%s\n", line); end if(status == 2 && line(1) == '!') status = 3; end if(status == 3 && line(1) ~= '!') %nNoise_context = strcat(nNoise_context, line); fprintf(file_temp_n, "%s\n", line); end end fclose(file_temp_n); fclose(file_temp_s); file_temp_s = dlmread(".s_parameter_temp.t"); file_temp_n = dlmread(".noise_temp.t"); para_list = split(paramete_type, ' '); FRE = file_temp_s(:,1); if(strcmp(para_list(4), 'MA') || strcmp(para_list(4), 'ma')) temp = 2; S11 = file_temp_s(:,temp); temp = temp + 2; S21 = file_temp_s(:,temp); temp = temp + 2; S12 = file_temp_s(:,temp); temp = temp + 2; S22 = file_temp_s(:,temp); temp = temp + 2; end if(strcmp(para_list(4), 'RI') || strcmp(para_list(4), 'ri')) temp = 2; S11 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; S12 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; S21 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; S22 = sqrt(file_temp_s(:,temp).*file_temp_s(:,temp) + file_temp_s(:,temp+1).*file_temp_s(:,temp+1));temp = temp + 2; end if(strcmp(para_list(4), 'DB') || strcmp(para_list(4), 'db')) temp = 2; S11 = file_temp_s(:,temp); temp = temp + 2; S21 = file_temp_s(:,temp); temp = temp + 2; S12 = file_temp_s(:,temp); temp = temp + 2; S22 = file_temp_s(:,temp); temp = temp + 2; end noise = file_temp_n;end

3、测试代码[S1_FRE S1_S11 S1_S21 S1_S12 S1_S22 S1_Noise] = ReadS2P('data.s2p');

© 手抄报圈