Sie sind auf Seite 1von 31

Mtodos Experimentais em Acstica e Vibraes

Experimento 1 - Relatrio

Medio de nvel de presso sonora e


dose de rudo

Bruno de Arajo Fujita


Marcel Pozzobon Borin
Rafael G. L. Andrade
Tiago Belletti Romero

9 de maio de 2017
Sumrio

Lista de Figuras . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . i

1 Introduo 2

2 Medio experimental 3
2.1 Local de medio . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 Equipamento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.3 Procedimento de medio . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5

3 Discusso dos resultados 6


3.1 Nvel de presso sonora . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.2 Dose de rudo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.3 Curvas de Critrio de rudo (NC) . . . . . . . . . . . . . . . . . . . . . . . . 10

4 Concluses 11

Referncias Bibliogrficas 12

Apndices 12

I Apndices 13
A Apndices 14
A.1 Rotina de calibrao . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
A.2 Gravao e anlise dos sinais . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
A.3 Ponderao A . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
A.4 Filtro de bandas de oitava ou frao de oitava . . . . . . . . . . . . . . . . . 16
A.5 Vetor de frequncias de frao de bandas de oitava . . . . . . . . . . . . . . . 17
A.6 Funo arredondamento . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22

Lista de Figuras

2.1 Foto tirada no hall de entrada do CCNE da UFSM. . . . . . . . . . . . . . 3


2.2 Microfone de medio Behringer ECM8000 utilizado. Fonte: [1]. . . . . . . 4

i
1

2.3 Interface de udio Behringer UMC22 utilizada. Fonte: [2]. . . . . . . . . . . 4


2.4 Calibrador B&K 4231. Fonte: [3]. . . . . . . . . . . . . . . . . . . . . . . . 5
2.5 Planta do local com os trs pontos de medio representados. . . . . . . . . 6

3.1 Nvel de presso sonora equivalente, para as trs posies de microfone. . . 7


3.2 Nvel de presso sonora equivalente, ponderado em A, para as trs posies
de microfone. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.3 Nvel de presso sonora mdio espacial. . . . . . . . . . . . . . . . . . . . . 8
3.4 Nvel de presso sonora mdio espacial ponderado em A. . . . . . . . . . . 9
3.5 Adequao do nvel de presso sonora nas curvas de critrio de rudo (NC). 11
Captulo 1

Introduo

O engenheiro acstico deve ser apto e estar familiarizado com procedimentos de medi-
o diversos, dentre eles o mais bsico consiste em medies do nvel de presso sonora em
diversas situaes. Esses dados podem revelar o impacto ambiental provocado pelo rudo
medido, alm de que, a partir deles possvel tambm o clculo da dose de rudo de ambi-
entes. Esse parmetro til na avaliao de ambientes de trabalho e usado nas normas que
regulamentam a exposio do trabalhador ao rudo.
O objetivo deste trabalho utilizar instrumentao disponvel para medir o rudo em
um local onde seja exercida atividade profissional, e assim, avaliar o impacto da presso
sonora sobre os funcionrios em seu local de trabalho. O local escolhido foi o hall de entrada
do Centro de Cincias Naturais e Exatas (CCNE) da Universidade Federal de Santa Maria
(UFSM).

2
Captulo 2

Medio experimental

2.1 Local de medio


O local escolhido foi o hall de entrada do Centro de cincias Naturais e Exatas (CCNE)
da Universidade Federal de Santa Maria (UFSM), com a justificativa de haver pessoas tra-
balhando diariamente no local, e portanto, mitigar os efeitos do rudo em seu ambiente de
trabalho. O local pode ser visto na Figura 2.1. No momento da medio notou-se a presena
constante de dois trabalhadores atuando no local com funes na portaria, e foi possvel per-
ceber um rudo maior causado pelo tumulto de alunos que por ali transitavam especialmente
em horrios de intervalos das aulas. A paisagem sonora do ambiente tambm era composta
por uma constante televiso ligada e com com udio ligado, e haviam tambm mais dois
televisores com videogames em que alunos jogavam especialmente no intervalo das aulas,
aumentado ainda mais a concentrao de gente e, consequentemente, o rudo no local.

Figura 2.1: Foto tirada no hall de entrada do CCNE da UFSM.

3
Captulo 2. Medio experimental 4

2.2 Equipamento
O equipamento selecionado para a realizao das medies foi um alternativo, de baixo
custo. As gravaes foram realizadas no software MATLAB, atravs do ITA Toolbox se
comunicando com uma interface de udio, responsvel pela aquisio dos dados. Os equipa-
mentos e softwares utilizados foram:

Microfone Behringer ECM8000 (Figura 2.2);

Figura 2.2: Microfone de medio Behringer ECM8000 utilizado. Fonte: [1].

Interface de udio Behringer UMC22 (Figura 2.3)

Figura 2.3: Interface de udio Behringer UMC22 utilizada. Fonte: [2].

Notebook Lenovo z40;

Matlab R2013;

ITA Toolbox;

Calibrador 4231 da B&K (Figura 2.4);


2.3. Procedimento de medio 5

Figura 2.4: Calibrador B&K 4231. Fonte: [3].

Cabo XLR;

Pedestal para o microfone;

2.3 Procedimento de medio


Primeiramente, foi feita a calibrao da sensibilidade do microfone, utilizando-se o cali-
brador B&K 4231 emitindo NPS de 94 dB em 1 kHz. A rotina de calibrao encontra-se no
Apndice A.1, e como resultado final ela calcula um fator de calibrao para cada canal do
microfone, que ser utilizado no ps processamento.
Em seguida, foram feitas medies em trs pontos distintos, distribudos no local de
interesse. Uma planta do local com as respectivas posies de microfone na Figura 2.5.
Cada ponto foi medido continuamente por 10 minutos, e os dados foram salvos no com-
putador sem processamento algum. Procurou-se o afastamento de, no mnimo, 1 metro das
paredes e 1,5 metros do cho.
O ps processamento foi feito no Matlab, atravs do uso de filtros em bandas de oita-
vas com a aplicao da ponderao A, quando necessrio. Para isto, utilizou-se a rotina
encontrada no Apndice A.2, que utiliza rotinas auxiliares para aplicar a ponderao A,
filtrar o sinal em bandas de oitava, calcular automaticamente o vetor de frequncias centrais
e funo de arredondamento, rotinas essas encontradas nos Apndices A.3,A.4,A.5 e A.6,
respectivamente.
Figura 2.5: Planta do local com os trs pontos de medio representados.

Captulo 3

Discusso dos resultados

Nesta captulo sero apresentados os resultados de nvel de presso sonora e dose de rudo
medidos em campo.

3.1 Nvel de presso sonora


A presso sonora o valor quadrtico mdio da presso acstica em um determinado
intervalo de tempo, comumente utiliza-se a sigla RMS(Root Mean Square), dada por
s
1 Z T2
PRMS = p(t)2 dt . (3.1)
T2 T1 T1

Os seres humanos so capazes de ouvir frequncias entre 20 Hz e 20 kHz, abaixo desse


limite esto ondas infrassnicas e acima as ultrassnicas. Para cada uma delas h um limiar
de audibilidade, ou seja, o menor valor variao na presso sonora capaz de gerar uma
sensao auditiva, para os humanos esse valor de referncia tomado como 20 Pa.

6
3.1. Nvel de presso sonora 7

O nvel de presso sonora (L) o clculo da potncia de uma onda acstica com base na
presso de referncia, de modo que
PRMS
L = 20 log10 ( )[dB]. (3.2)
Pref
A Figura 3.1 mostra o Nvel de Presso Sonora Equivalente, sem ponderao, durante o
tempo de medio, para cada uma das posies de microfone medidos no local.

Figura 3.1: Nvel de presso sonora equivalente, para as trs posies de microfone.

A Figura 3.2 mostra o Nvel de Presso Sonora Equivalente, com ponderao A, durante
o tempo de medio, para cada uma das posies de microfone medidos no local.
Deve-se notar que a posio 1 possui um maior nvel de presso sonora que as demais.
Este fenmeno ocorre, pois esta medio foi gravada em um horrio de intervalo das aulas
do CCNE, e portanto, o movimento de pessoas no local era consideravelmente maior, o que
aumentou os nveis de presso sonora das mdias e altas frequncias, justamente as regies
correspondentes as frequncias da voz humana.
As curvas de ponderao so utilizadas para relacionar os nveis de presso sonora com a
percepo humana. Dentre as curvas mais utilizadas esto a A e a C, sendo a primeira para
rudo intermitente e a segunda para rudo de impacto.
A Figura 3.3 mostra o NPS mdio espacial das trs posies de microfone, resultando-se,
ento, em um valor nico representativo para cada banda de oitava.
A Figura 3.4 mostra o NPS mdio espacial das trs posies de microfone com a ponde-
rao A.
Os valores exatos das Figuras 3.3 e 3.4 podem ser vistos na Tabela 3.1.
Analisando-se os nveis de presso sonora sem ponderao nota-se que a maior presso
sonora ocorre em torno de 500 Hz. Normalmente, espera-se que o maior rudo de fundo esteja
em baixa frequncia, porm neste caso, nas trs medies o ambiente estava continuamente
preenchido pelo som de uma das televises ligada, gerando-se um aumento nesta regio
mdia de frequncias.
Captulo 3. Discusso dos resultados 8

Figura 3.2: Nvel de presso sonora equivalente, ponderado em A, para as trs posies de
microfone.

Figura 3.3: Nvel de presso sonora mdio espacial.

O nvel de presso sonora equivalente global com e sem ponderao para cada uma das
trs posies de microfone, pode ser visto na Tabela 3.2.

Tabela 3.2: Nvel de presso sonora equivalente global com e sem ponderao para cada
uma das trs posies de microfone.

Posio do microfone 1 2 3
dB 76,4 72,3 73,5
dB(A) 71,8 64 65,2
3.2. Dose de rudo 9

Figura 3.4: Nvel de presso sonora mdio espacial ponderado em A.

Tabela 3.1: NPS em banda de oitava da mdia da mdia espacial, com e sem ponderao.

Banda de oitava (Hz) 31,5 63 125 250 500 1000 2000 4000 8000
dB 67,7 65,4 66,0 68,2 68,8 65,1 60,4 55,5 50,8
dB(A) 42,4 48,5 55,2 61,4 65,3 63,6 60,2 55,6 50,4

O nvel de presso sonora do global equivalente de todas as posies dado na tabela


3.3.

3.2 Dose de rudo


Sabendo que danos ao sistema auditivo se devem no apenas ao nvel de presso sonora
a que o indivduo exposto, mas tambm ao tempo de exposio desse indivduo ao rudo,
faz-se necessria a utilizao de um parmetro que considere o fator tempo. Esse parmetro
a dose de rudo, utilizada principalmente para avaliar ambientes de trabalho, uma vez que
os funcionrios passam diversas horas seguidas nesses ambientes.
o parmetro acstico mais importante na perspectiva do trabalhador e do empregador.
Ao primeiro por relacionar-se a sua sade e ao segundo por ser regulamentada a partir da
NR-15 [5] tendo portanto consequncias severas em caso de no cumprimento.
A dose de rudo um valor percentual, dependente do valor do incremento de duplicao
de dose (L, exchange rate), valor que pode ser diferente de acordo com a norma utilizada.

Tabela 3.3: Nvel de presso sonora equivalente global mdio espacial para as trs posies,

Nvel de presso sonora


dB 74,4
dB(A) 68,5
Captulo 3. Discusso dos resultados 10

No Brasil o valor normatizado de L 3, o que significa que a cada 3dB de incremento, o


tempo de exposio deve ser reduzido pela metade e o a cada decremento de 3dB o tempo
de exposio pode ser dobrado.
O clculo dependente do tempo mximo permitido para determinado NPS, dado pela
Equao 3.3 abaixo:
8
Ti = (LAi LB )/L
, (3.3)
2
em que LAi o NPS com ponderao A medido e LB um valor normaztizado, que para o
Brasil corresponde a 85 dB(A).
A dose ento dada por:
C1 C2 Ci
 
Dose = 100 + + ... + [%], (3.4)
T1 T2 Ti
onde C1 o tempo de exposio de um sujeito ao LAi utilizado no clculo de Ti .
Como as medies foram realizadas por tempo curto se comparado ao expediente dirio
dos funcionrios que trabalham no hall do CCNE, foi calculada a dose projetada (projected
dose) de acordo com as medies realizadas. A dose projetada calculada de acordo com a
Equao 3.5 abaixo:
Dose x8
ProjectedDose = , (3.5)
Tm
em que Tm o tempo de medio da dose de rudo.
Considerando os valores para as medies nos 3 pontos, pode-se fazer o calculo da Dose
para 30 minutos, o que gera um valor de 0, 13%. A dose projetada ento 2, 09%.

3.3 Curvas de Critrio de rudo (NC)


As curvas de critrio NC (Noise Criteria) definem os limites do espectro de banda de
oitava que no devem ser ultrapassados para atender o limite de rudo para uma atividade,
tendo em vista o conforto acstico em funo da comunicao humana. As quantificaes
das curvas em frequncia e a relao entre valores aceitveis para a funo do local analisado
so normalizados atravs da NBR 10152 [4]
A classificao NC de um ambiente pode ser obtida atravs da representao grfica dos
nveis banda de oitava, para determinado espectro de um rudo, junto as curvas de critrio.
O ambiente ser classificado de acordo com a curva mais baixa que no excedida pelo nvel
do rudo em banda de oitava.
A adequao do nvel de presso sonora do sinal, sem ponderao, e as curvas de critrio
de rudo podem ser vistas na Figura 3.5. A partir dela possvel notar que o local se encaixa
na curva NC-70.
A NBR 10152 traz na tabela de valores adequados de Noise Criteria valores de 40-50 para
reas de circulao de pessoas em escolas. Pode-se observar que esses resultados encontrados
esto bem acima do ideal para o conforto acstico.
Figura 3.5: Adequao do nvel de presso sonora nas curvas de critrio de rudo (NC).

Captulo 4

Concluses

Apesar do clculo da dose no ter representado nenhum prejuzo ao trabalhador, a clas-


sificao do ambiente NC-70 est acima do limite para qualquer trabalho humano com carga
horria de 8 horas dirias, havendo prejuzo na comunicao.
Tais resultados demonstram que h uma grande diferena entre perda auditiva do tra-
balhador e o conforto acstico para o mesmo. Esse um exemplo tpico em que o valor
projetado global no realmente representativo da imagem sonora do local, em razo de no
considerar a caracterizao em frequncia. Observa-se que o a energia sonora concentra-se
em mdias e altas frequncias, mas no h energia suficiente para a elevao do NPS a ponto
de infringir os limites de tolerncia normatizados pela NR 15.
Essa classificao precisaria de mais medies para ser efetiva, pois um maior nmero
de amostras deveriam ser adquiridas para diminuir o erro associado a varivel, tendo em
vista que a medio excedeu por pouco a curva NC-65 apenas na banda de 500 Hz. Deve-se
notar tambm o problema da tomada de poucas amostras quanto caracterizao sonora.
Se no local h rudos intermitentes, como foi o caso estudado, a quantidade e a durao das
medies devem ser atenciosamente analisadas pois h o risco de uma errnea tomada de

11
Referncias Bibliogrficas 12

decises em funo de valores no condizentes com a real paisagem sonora.

Referncias Bibliogrficas

[1] Ecm800 ultra-linear measurement condenser microphone. http://www.music-group.


com/Categories/Behringer/Microphones/Condenser-Microphones/ECM8000/p/
P0118. Acessado em: 29/03/2016.
(Citado nas pginas i e 4)

[2] Sound calibrator type 4231. http://www.music-group.com/Categories/Behringer/


Computer-Audio/Audio-Interfaces/UMC22/p/P0AUX. Acessado em: 29/03/2016.
(Citado nas pginas 1 e 4)

[3] Sound calibrator type 4231. http://www.bksv.com/Products/transducers/acoustic/


calibrators/4231?src=fnt. Acessado em: 29/03/2016.
(Citado nas pginas 1 e 5)

[4] ABNT-Associao Brasileira de Normas Tcnicas. NBR 10152 - Nveis de rudo para
conforto acstico.
(Citado na pgina 10)

[5] Ministrio do Trabalho e Previdncia Social. NR 15 - atividades e operaes insa-


lubres. http://www.mtps.gov.br/seguranca-e-saude-no-trabalho/normatizacao/normas-
regulamentadoras, 2011.
(Citado na pgina 9)
Parte I

Apndices

13
Apndice A

Apndices

A.1 Rotina de calibrao


Cdigo A.1: Calibrao do microfone
1 clear all
2 close all
3 clc
4 %%
5
6
7 pause on
8 input('Ponha o Calibrador no Canal 1 e pressione ENTER ');
9
10
11
12 calib_1 = itamsrecord('samplingRate',44100,'nSamples',524288,'fftDegree',19,...
13 'freqRange',[20 22050],'averages',1,'repeats',1,'inputChannels',1);
14
15 calib_1 = calib_1.run;
16 pause off
17
18 pause on
19 input('Ponha o Calibrador no Canal 2 e pressione ENTER ');
20
21
22 calib_2 = itamsrecord('samplingRate',44100,'nSamples',524288,'fftDegree',19,...
23 'freqRange',[20 22050],'averages',1,'repeats',1,'inputChannels',2);
24
25 calib_2 = calib_2.run;
26 pause off
27
28
29
30 %% Calcula o fator de c a l i b r a para os 2 canais
31
32
33 x1 = calib_1.timeData;
34 x2 = calib_2.timeData;
35
36
37 fc = sqrt(2);
38
39 x11 = x1.^2;
40 x12 = x2.^2;
41
42 x31 = mean(x11);
43 x32 = mean(x12);
44
45 x41 = sqrt(x31);
46 x42 = sqrt(x32);
47
48 calib1 = 1./x41;
49 calib2 = 1./x42;

14
A.2. Gravao e anlise dos sinais 15

50 cali = [calib1 calib2];


51
52
53
54
55 save calib cali %K_in K_out

A.2 Gravao e anlise dos sinais


Cdigo A.2: Gravao e ps processamento dos sinais
1 %% G r a v a es ;
2 clear all
3 close all
4 clc
5
6 %%
7
8 pause on
9 input('Posicione os microfones e pressione ENTER ');
10
11 fs=44100;
12 fftdegree=24;
13 nsamples=2^fftdegree;
14
15
16 med = itamsrecord('samplingRate',fs,'nSamples',nsamples,'fftDegree',fftdegree,...
17 'freqRange',[20 22050],'averages',1,'repeats',1,'inputChannels',1);
18
19 med_1 = med.run;
20 pause off
21 save med med_1
22
23 x=med_1.timeData(:,1);
24
25 %% A n lise dados
26
27 B = 1; % Fra c o oitava
28 %Para ajustar a ordem do filtro, ver oitava.m
29
30 Fs = 44100;
31
32
33 color = ['r','k'];
34
35 %% F u n que cria o vetor de frequncias centrais para banda de 1/n de oitava
36 N=B;
37 min_f=20;
38 max_f=20000;
39 SI_prefixes=0;
40 base10=1;
41
42 [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(N, min_f, max_f, SI_prefixes, base10)
;
43 b=fnominal_l_c_u(:,2);
44
45
46
47
48
49 %% P o n d e r a Sinal
50 A = ponderacao(x,fs); % Com P o n d e r a
51 %A = x; % Sem p o n d e r a
52
53 %% Filtrando O sinal em bandas
54
55
56
57 for n = 1:length(b)
58 F0 = b(n);
59 H = oitava(B,F0,Fs);
60 y(:,n) = filter(H,A);
61 end
Apndice A. Apndices 16

62
63 %% Calculando SPL para cada banda
64
65 for n = 1:length(b)
66
67 x1(:,n) = y(:,n);
68
69 x11(:,n) = x1(:,n).^2;
70
71 x31(:,n) = mean(x11(:,n));
72
73 x41(:,n) = (sqrt(x31(:,n))*cali(1)/(20e6));
74
75 SPL(1,n) = 20*log10(x41(:,n));
76 end
77
78
79
80 %%
81
82 k=b;
83
84 semilogx(k,SPL,'linewidth',2)
85
86 grid on
87 xlim([min(b) max(b)])
88 xlabel('frequncia (Hz)')
89 ylabel('SPL [dB]')
90 title(sprintf('1/%d de oitava [Hz]',B))
91 legend('Canal 1')
92 hold all

A.3 Ponderao A
Cdigo A.3: Ponderao A
1 function A = ponderacao(x,fs)
2 d = fdesign.audioweighting('WT,Class','A',2,fs);
3 Hd = design(d);
4
5 A = filter(Hd,x);

A.4 Filtro de bandas de oitava ou frao de oitava


Cdigo A.4: Filtro de frao de oitava
1 function Hd = oitava(B,F0,Fs)
2 %OITAVA Returns a discretetime filter object.
3
4 %
5 % MFile generated by MATLAB(R) 7.10 and the Signal Processing Toolbox 6.13.
6 %
7 % Generated on: 01Jun2015 14:51:16
8 %
9
10 % B = 3; % Bands per octave
11 N = 2; % Order
12 % F0 = 1000; % Center frequency
13 % Fs = 44100; % Sampling Frequency
14
15 h = fdesign.octave(B, 'Class 0', 'N,F0', N, F0, Fs);
16
17 % Hd = design(h, 'butter', ...
18 % 'SOSScaleNorm', 'linf');
19 Hd = design(h, 'butter');
20
21
22 % [EOF]
A.5. Vetor de frequncias de frao de bandas de oitava 17

A.5 Vetor de frequncias de frao de bandas de oitava


Cdigo A.5: Vetor de frequncias de frao de bandas de oitavao
1 function [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(N, min_f, max_f, SI_prefixes
, base10)
2 % % fract_oct_freq_band: Calculates the 1/nth octave band center, lower, and upper bandedge frequency limits
3 % %
4 % % Syntax;
5 % %
6 % % [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(N, min_f, max_f, SI_prefixes,
base10);
7 % %
8 % % **********************************************************************
9 % %
10 % % Description
11 % %
12 % % This program calculates the fractional, 1/N octave band center
13 % % frequencies and the lower and upper bandedge limits of every
14 % % frequency band from min_f to max_f (Hz).
15 % %
16 % % The exact and nominal values of the frequencies are output.
17 % % The exact values are useful for calculations and making filters.
18 % % The nominal values are useful for tables, plots, figures, and graphs.
19 % %
20 % % The frequency band nominal values are rounded to three or more
21 % % significant digits based on the number of bands per octave.
22 % % Full octave and third octave bands are rounded to three significant digits.
23 % %
24 % % The exact and nominal frequency values and character strings are output.
25 % %
26 % % 1000 Hz is a center frequency when N is odd, odd fractional octave bands.
27 % % 1000 Hz is an edge frequency when N is even, even fractional octave bands.
28 % %
29 % % fract_oct_freq_band produces exact and nominal frequency bands which
30 % % satisfy ANSI S1.6R2006 and ANSI S1.11R2014.
31 % %
32 % %
33 % % fract_oct_freq_band is a modification of centr_freq
34 % % centr_freq can be found on Matlab Central File Exchange
35 % % The Matlab ID is 17590.
36 % %
37 % % **********************************************************************
38 % %
39 % % Input Variables
40 % %
41 % % N=3; % 3 three bands per octave.
42 % % % 1 one band per octave.
43 % % % N is the number of frequency bands per octave.
44 % % % N can be any integrer > 0.
45 % % % Default is 3 for third octave bands.
46 % %
47 % % min_f=20; % min_f is the minimum frequency band to calculate (Hz).
48 % % % min_f > 0. Must be graeater than 0.
49 % % % default is 20;
50 % %
51 % % max_f=20000; % max_f is the maximum frequency band to calculate (Hz).
52 % % % max_f > 0. Must be graeater than 0.
53 % % % default is 20000;
54 % %
55 % % SI_prefixes=0; % This parameter controls the output for the character
56 % % % strings of the nominal frequencies.
57 % % % 1 for using SI prefixes (i.e. k for 1000)
58 % % % 0 for not using prefixes.
59 % % % default is SI_prefixes=0;
60 % %
61 % % base10=1; % 1 for using base 10 filter frequencies
62 % % % 0 for using base 2 filter frequencies
63 % % % otherwise base 10 filter frequencies
64 % % % default base 10 filter frequencies
65 % %
66 % % **********************************************************************
67 % %
68 % % Output Variables
69 % %
Apndice A. Apndices 18

70 % % fexact_l_c_u is a 2D array of exact frequency bands in Hz.


71 % % fexact_l_c_u( frequecy bands, [lower=1, center=2, upper =3;] );
72 % %
73 % % fnominal_l_c_u is a 2D array of nominal frequency bands in Hz.
74 % % fnominal_l_c_u{ frequecy bands, [lower=1, center=2, upper =3;] };
75 % %
76 % % fnominal_str_l_c_u is a 2D cell array of nominal frequency band strings in Hz.
77 % % fnominal_str_l_c_ufnominal_l_c_u{ frequecy bands, [lower=1, center=2, upper =3;] };
78 % %
79 % % **********************************************************************
80 %
81 %
82 % Example='1';
83 %
84 % % Full octave band center frequencies from 20 Hz to 20000 Hz
85 % close('all');
86 % [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(1, 20, 20000);
87 % figure(1);
88 % semilogy(fexact_l_c_u(:, 1), ':ro', 'linewidth', 4, 'markersize', 10);
89 % hold on;
90 % semilogy(fexact_l_c_u(:, 2), 'gp', 'linewidth', 4, 'markersize', 10);
91 % semilogy(fexact_l_c_u(:, 3), '.cs', 'linewidth', 4, 'markersize', 10);
92 % semilogy(fnominal_l_c_u(:, 1), '.kx', 'linewidth', 3, 'markersize', 14);
93 % semilogy(fexact_l_c_u(:, 2), ':m*', 'linewidth', 3, 'markersize', 14);
94 % semilogy(fexact_l_c_u(:, 3), 'b+', 'linewidth', 3, 'markersize', 10);
95 % legend({'Exact lower band', 'Exact center', 'Exact upper band', ...
96 % 'Nominal lower band','Nominalcenter', 'Nominal upper band'}, ...
97 % 'location', 'northwest');
98 % set(gca, 'fontsize', 24);
99 % maximize(gcf);
100 %
101 %
102 % % third octave band center frequencies from 20 Hz to 20000 Hz
103 % [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(3, 20, 20000);
104 %
105 % % twelveth octave band center frequencies from 100 Hz to 10000 Hz
106 % [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(12, 100, 10000);
107 %
108 % % twentyfourth octave band center frequencies from 0.001 Hz to 10000000 Hz
109 % [fexact_l_c_u, fnominal_l_c_u, fnominal_str_l_c_u] = fract_oct_freq_band(24, 0.001, 10000000);
110 %
111 %
112 % % **********************************************************************
113 % %
114 % % References
115 % %
116 % % 1) ANSI S1.6R2006 Preferred Frequencies, Frequency Levels, and
117 % % Band Numbers for Acoustical Measurements, 1984.
118 % %
119 % % 2) ANSI S1.112014, (2014). American National Standard Electroacoustics
120 % % Octaveband and Fractionaloctaveband Filters Part 1:
121 % % Specifications (a nationally adopted international standard).
122 % % American National Standards Institute, Acoustical Society of
123 % % America, New York
124 % %
125 % %
126 % % **********************************************************************
127 % %
128 % % fract_oct_freq_band is a modification of centr_freq
129 % % centr_freq can be found on Matlab Central File Exchange
130 % % The Matlab ID is 17590.
131 % %
132 % % Written by Author Eleftheria
133 % %
134 % % Company/University: University of Patras
135 % %
136 % %
137 % % **********************************************************************
138 % %
139 % % List of Dependent Subprograms for
140 % % fract_oct_freq_band
141 % %
142 % % FEX ID# is the File ID on the Matlab Central File Exchange
143 % %
144 % %
145 % % Program Name Author FEX ID#
A.5. Vetor de frequncias de frao de bandas de oitava 19

146 % % 1) sd_round Edward L. Zechmann


147 % %
148 % %
149 % % **********************************************************************
150 % %
151 % %
152 % % Program Modified by Edward L. Zechmann
153 % %
154 % % modified 3 March 2008 Original modification of program
155 % % updated comments
156 % %
157 % % modified 13 August 2008 Updated comments.
158 % %
159 % % modified 18 August 2008 Added rounding last digit to nearest
160 % % multiple of 5. Added Examples.
161 % % Updated comments.
162 % %
163 % % modified 21 August 2008 Fixed a bug in usign min_f and max_f
164 % % which does not include 1000 Hz.
165 % % Zipped the depended program sd_round.
166 % % Updated comments.
167 % %
168 % % modified 18 November 2008 Added additional rounding
169 % %
170 % % modified 8 December 2008 Updated comments.
171 % %
172 % % modified 18 December 2008 Updated comments.
173 % %
174 % % modified 4 January 2008 Changed rounding of the lower and upper
175 % % bandedge frequency limits.
176 % %
177 % % modified 6 October 2009 Updated comments
178 % %
179 % % modified 22 January 2010 Modified the number of significant
180 % % digits for rounding. The number of
181 % % significnat digits increases as the
182 % % number of bands per octave increases.
183 % % This supports high resolution octave
184 % % band analysis.
185 % %
186 % % modified 4 October 2014 Modified the even octave bands to have
187 % % 1000 Hz as an edge frequency.
188 % % Changed the number of significant
189 % % digits calculation for rounding.
190 % % Limited the number of bands per octave
191 % % from 1 to 43.
192 % %
193 % %
194 % % **********************************************************************
195 % %
196 % % Please Feel Free to Modify This Program
197 % %
198 % % See Also: centr_freq, sd_round
199 % %
200
201 if (nargin < 1 || isempty(N)) || isnumeric(N)
202 N=3;
203 end
204
205 % N must be an integrer;
206 N=round(N);
207
208 % N must be between 1 and 43. Filters with more than 43 bands per octave
209 % have machine precision rounding errors in the band edge frequencies.
210 N(N < 1)=1;
211 N(N > 43)=43;
212
213 if (nargin < 2 || isempty(min_f)) || (logical(min_f < 0) || isnumeric(min_f))
214 min_f=20;
215 end
216
217 if (nargin < 3 || isempty(max_f)) || (logical(max_f < 0) || isnumeric(max_f))
218 max_f=20000;
219 end
220
221 if (nargin < 4 || isempty(SI_prefixes)) || isnumeric(SI_prefixes)
Apndice A. Apndices 20

222 SI_prefixes=0;
223 end
224
225 if (nargin < 5 || isempty(base10)) || isnumeric(base10)
226 base10=1;
227 end
228
229 if base10 = 0;
230 base10=1;
231 end
232
233 % Determine if N is odd or even.
234 N=round(N);
235
236 b=mod(N1, 2);
237 % b == 0 if N is even
238 % b == 1 if N is odd
239
240
241 % Now the nominal frequencies can be calculated
242
243 % For base2 filter frequencies
244 %
245 % 2^N=floor(3+n_sd_digits*log10(2));
246
247 % base10 filter frequencies
248 %
249 % G^N=floor(3+n_sd_digits*log10(G));
250
251 % Calculate the base number G
252 if base10 == 1
253 G=10^(3/10);
254 else
255 G=2;
256 end
257
258 % Calculate the maximum number of octave bands above 1000 Hz.
259 Nmax=round(N*ceil(log(max_f/1000)/log(G))+1);
260
261 if Nmax < 1
262 Nmax=1;
263 end
264
265 f_a=zeros(Nmax, 1);
266 f_a(1)=1000*(G.^(b/((1+b)*N)));
267
268 for e1=1:Nmax;
269 % center frequencies over 1000 Hz
270 % Center frequencies are based on a 1/3 octave band
271 % falling exactly at each factor of 10
272 f_a(e1+1, 1)=f_a(e1)*(G.^(1/N));
273 end
274
275 % Remove bands above the extended max_f limit
276 f_a=f_a(f_a < max_f*(G^(0.5/N)));
277
278
279 % Calculate number of bands below 1000 Hz
280 Nmin=round(N*ceil(log(1000/min_f)/log(G))+1);
281
282 if Nmin < 1
283 Nmin=1;
284 end
285
286 f_b=zeros(Nmin, 1);
287 f_b(1)=1000/(G.^(b/((1+b)*N)));
288
289 for e1=1:Nmin;
290 % center frequencies below 1000 Hz
291 % In the base 10 system, the center frequencies fall exactly at each
292 % factor of 10 based on third octave intervals.
293 f_b(e1+1, 1)=f_b(e1)/(G.^(1/N));
294 end
295
296 % Remove bands below the extended min_f limit
297 f_b=f_b(f_b > min_f*(G^(0.5/N)));
A.5. Vetor de frequncias de frao de bandas de oitava 21

298
299 % Concatenate center frequency bands
300 % Make center frequency bands unique
301 fc = unique([f_b;f_a]);
302
303 % Remove bands above the extended max_f limit
304 fc=fc(fc < max_f*(G^(0.5/N)));
305
306 % Remove bands below the extended min_f limit
307 fc=fc(fc > min_f*(G^(0.5/N)));
308
309 % Calculate the number of center frequency bands
310 num_bands=length(fc);
311
312 % fc is the array of exact center frequencies;
313 fc_exact=fc;
314
315 % ***********************************************************************
316 %
317 % Calculate the lower and upper bounds for the lower and upper
318 % band edge frequencies
319 flu = [fc(1)./G.^(1./(2.*N)); fc.*( G.^(1./(2.*N)) )];
320
321 % Form the numeric arrays for the exact lower frequency band edge limits.
322 fl_exact=flu(1:num_bands);
323
324 % Form the numeric arrays for the exact upper frequency band edge limits.
325 fu_exact=flu(1+(1:num_bands));
326
327 % ************************************************************************
328 %
329 % Calculate the number of significant digits for rounding the exact
330 % frequencies into the nominal frequencies.
331 %
332 % Full octave band and third octave band must have 3 significant digits.
333 % the number of digits per ocrtave increases N*log10(G).
334 % This is derived by solving the equation 2^N=floor(3+n_sd_digits*log10(2));
335 % for n_sd_digits.
336 %
337 num_sd_digits=floor(3+N*log10(G));
338 m=10.^(num_sd_digits1);
339
340 % ************************************************************************
341 %
342 % Calculations for nominal frequencies
343 %
344 % Apply appropriate rounding to the center frequencies
345 [fc, fc_str] = sd_round(fc, num_sd_digits, 1, 5, SI_prefixes);
346 [fc2, fc_str2] = sd_round(fc, num_sd_digits, 1, 100, SI_prefixes);
347
348 % If the center frequency rounded to 3 significant digits and the last
349 % digit rounded to the nearest multiple of 5 is within 1% of the center
350 % frequency rounded to 1 significant digit, then round to 1 significant
351 % digit.
352 %
353 ix=find(abs(m*(1fc./fc2)) < 1);
354 fc(ix)=fc2(ix);
355 fc_str(ix)=fc_str2(ix);
356
357 % Nominal frequencies
358 fc_nom=fc;
359 fc_nom_str=fc_str;
360
361
362 % Apply the same rounding technique to the lower and upper frequency
363 % bandedge limits as was applied to the center frequencies.
364 [flu, flu_str] = sd_round(flu, num_sd_digits, 1, 5, SI_prefixes);
365 [flu2, flu_str2] = sd_round(flu, num_sd_digits, 1, 100, SI_prefixes);
366
367
368 % If the center frequency rounded to 3 significant digits and the last
369 % digit rounded to the nearest multiple of 5 is within 1% of the center
370 % frequency rounded to 1 significant digit, then round to 1 significant
371 % digit.
372 %
373 ix=find(abs(m*(1flu./flu2)) < 1);
Apndice A. Apndices 22

374 flu(ix)=flu2(ix);
375 flu_str(ix)=flu_str2(ix);
376
377 % Form the numeric and string arrays for the nominal lower frequency
378 % band edge limits.
379 fl_nom=flu(1:num_bands);
380 fl_nom_str=flu_str(1:num_bands);
381
382 % Form the numeric and string arrays for the nominal upper frequency
383 % band edge limits.
384 fu_nom=flu(1+(1:num_bands));
385 fu_nom_str=flu_str(1+(1:num_bands));
386
387 % Concatenate the outputs
388 fexact_l_c_u=[fl_exact, fc_exact, fu_exact];
389 fnominal_l_c_u=[fl_nom, fc_nom, fu_nom];
390
391 fnominal_str_l_c_u=cell(num_bands, 3);
392 for e1=1:num_bands;
393 fnominal_str_l_c_u{e1, 1}=fl_nom_str{e1};
394 fnominal_str_l_c_u{e1, 2}=fc_nom_str{e1};
395 fnominal_str_l_c_u{e1, 3}=fu_nom_str{e1};
396 end

A.6 Funo arredondamento


Cdigo A.6: Funo de arredondamento
1 function [A2, A_str, real_digitsL, real_digitsR, imag_digitsL, imag_digitsR]=sd_round(A, N, flag2, mult,
SI_prefixes)
2 % % sd_round: Rounds an array to a specified number of Significant Digits, significant figures, digits of
precision
3 % %
4 % % *********************************************************************
5 % %
6 % % Syntax;
7 % %
8 % % [A2, A_str, real_digitsL, real_digitsR, imag_digitsL,...
9 % % imag_digitsR]=sd_round(A, N, flag2);
10 % %
11 % % *********************************************************************
12 % %
13 % % Description
14 % %
15 % % sd_round stands for "Significant Digits Round".
16 % %
17 % % This program rounds a 2d matrix of numbers to a specified number
18 % % of significant digits.
19 % %
20 % % This program support five different styles of rounding the last digit:
21 % % to the nearest integer, up, down, toward zero, and away from zero.
22 % %
23 % % This program supports real and complex numbers.
24 % %
25 % % The program outputs the rounded array, a cell string of the
26 % % rounded matrix the number of digits, to the left and right of the
27 % % decimal place.
28 % %
29 % % This program is useful for presenting scientific data that
30 % % requires rounding to a specific number of significant digits
31 % % for publication.
32 % %
33 % % Significant digits are counted starting from the first nonzero
34 % % digit from the left.
35 % %
36 % %
37 % % *********************************************************************
38 % %
39 % % Input variables
40 % %
41 % % A is the input matrix of number to be rounded.
42 % % default is empty array A=[];.
43 % %
A.6. Funo arredondamento 23

44 % % N is the number of significant digits.


45 % % default is N=3;
46 % %
47 % % flag2 specifiies the style of rounding.
48 % % This program supports four different styles of rounding.
49 % % flag2 == 1 rounds to the nearest integer
50 % % flag2 == 2 rounds up
51 % % flag2 == 3 rounds down
52 % % flag2 == 4 rounds toward zero
53 % % flag2 == 5 rounds away from zero
54 % % otherwise round to the nearest integer
55 % % default is round to the nearest integer
56 % %
57 % % mult is a whole number. The program rounds the last digit to mult.
58 % % It is preferred that mult be between 1 and 9; however, all whole
59 % % numberS 1 are valid input. The program rounds mult to the
60 % % nearest integer and makes sure the value is at least 1.
61 % % default is mult=1;
62 % %
63 % % SI_prefixes=0; % 1 for using SI prefixes (i.e. K for 1000)
64 % % % 0 for not using prefixes.
65 % % % default is SI_prefixes=0;
66 % %
67 % %
68 % % *********************************************************************
69 % %
70 % % Output variables
71 % %
72 % % A2 is the rounded array.
73 % %
74 % % A_str % The rounded array is converted to a cell
75 % % % string format with the specified rounding and showing
76 % % % the trainling zeros.
77 % % % This is convenient for publishing tables in a tab
78 % % % delimited string format
79 % %
80 % % real_digitsL % The number of real digits to the left of the decimal
81 % % % point
82 % %
83 % % real_digitsR % The number of real digits to the right of the decimal
84 % % % point
85 % %
86 % % imag_digitsL % The number of imaginary digits to the left of the
87 % % % decimal point
88 % %
89 % % imag_digitsR % The number of imaginary digits to the right of the
90 % % % decimal point
91 % %
92 % % *********************************************************************
93 % %
94 %
95 % Example1='';
96 % D1=pi; % Double or Complex two dimensional array of numbers
97 % N=3; % Number of significant digits. 3 is the default
98 %
99 % [P1, P1_str]=sd_round(pi, N);
100 %
101 % % P1 should be 3.14 which has 3 significant digits.
102 %
103 % Example2='';
104 % D1=pi/1000000; % Double much smaller than 1
105 % N=3; % Number of significant digits. 3 is the default
106 % flag2=1; % round to the nearest digit
107 % mult=5; % round to a multiple 5
108 %
109 % [P1, P1_str]=sd_round(D1, N, 1, 5);
110 %
111 % % P1_str should be 0.00000315 which has 3 significant digits.
112 % % and the last digit is rounded to the nearest multiple of 5.
113 %
114 % Example3='';
115 % N=4; % N is the number of significant digits
116 % D2=10.^randn(10, 100); % D2 is the unrounded array
117 % [P2, P2_str]=sd_round(D2, N); % P2 is the rounded array
118 % % of real numbers
119 % % P2_str is the cell array of strings of
Apndice A. Apndices 24

120 % % rounded real numbers


121 % Example4='';
122 % D3=log10(randn(10, 100)); % D3 is an unrounded array of complex
123 % % numbers
124 % [P3, P3_str]=sd_round(D3, 4); % P3 is the rounded array of
125 % % complex numbers
126 % % P3_str is the cell array of strings of
127 % % rounded complex numbers
128 %
129 % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
130 % %
131 % % Program Written by Edward L. Zechmann
132 % %
133 % % date 23 November 2007
134 % %
135 % % modified 26 November 2007 updated comments
136 % %
137 % % modified 17 December 2007 added outputs
138 % % real_digitsL
139 % % real_digitsR
140 % % imag_digitsL
141 % % imag_digitsR
142 % %
143 % % modified 28 December 2007 added string output
144 % % fixed bug in real_digitsR
145 % % fixed bug in imag_digitsR
146 % %
147 % % modified 7 January 2008 fixed bug in real_digitsR
148 % % fixed bug in imag_digitsR
149 % % sped up program by only
150 % % converting the array to strings
151 % % if it is an output argument
152 % %
153 % % modified 1 March 2008 Added support for rounding
154 % % to nearest integer, up, down,
155 % % and toward zero
156 % %
157 % % modified 3 March 2008 updated comments
158 % %
159 % % modified 16 March 2008 Changed Program name from
160 % % p_round to sd_round.
161 % % Added another rounding style
162 % % flag2 =5; (away from 0).
163 % % Updated comments.
164 % %
165 % % modified 18 August 2008 Added option to round last digit to a
166 % % multiple of a given number.
167 % % Fixed a bug in rounding powers of 10.
168 % % Improved examples.
169 % %
170 % % modified 21 August 2008 Fixed a bug in rounding numbers less
171 % % than 1. Added an example.
172 % %
173 % % modified 25 August 2008 Modified program to recalculate the
174 % % number of digits after rounding,
175 % % because rounding can change the number
176 % % of digits to the left and right of the
177 % % decimal place. Updated Comments
178 % %
179 % % modified 16 August 2010 Changed K to k for SI prefixes.
180 % %
181 % %
182 % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
183 % %
184 % % Please Feel Free to Modify This Program
185 % %
186 % % See Also: pow10_round, round, ceil, floor, fix, fix2, round2, roundd
187 % %
188
189 flag1=0;
190
191 if (nargin < 1 || isempty(A)) || isnumeric(A)
192 flag1=1;
193 A=[];
194 A2=[];
195 warning('Error in p_round did not Input Matrix A');
A.6. Funo arredondamento 25

196 end
197
198 if isempty(A)
199 flag1=1;
200 A=[];
201 A2=[];
202 warning('Error in p_round Matrix A is Empty');
203 end
204
205 if (nargin < 2 || isempty(N)) || isnumeric(N)
206 N=3;
207 end
208
209 if (nargin < 3 || isempty(flag2)) || isnumeric(flag2)
210 flag2=1;
211 end
212
213 if (nargin < 4 || isempty(mult)) || isnumeric(mult)
214 mult=1;
215 end
216
217 mult=round(mult);
218 if mult < 1
219 mult=1;
220 end
221
222 if (nargin < 5 || isempty(SI_prefixes)) || isnumeric(SI_prefixes)
223 SI_prefixes=0;
224 end
225
226 SI_prefixes=SI_prefixes(1);
227
228 % Number of digits to keep
229 N=round(N);
230
231 if N < 1
232 N=1;
233 end
234
235 if isempty(A)
236 real_digitsL=zeros(size(A));
237 real_digitsR=zeros(size(A));
238 imag_digitsL=zeros(size(A));
239 imag_digitsR=zeros(size(A));
240 else
241 real_digitsL=[];
242 real_digitsR=[];
243 imag_digitsL=[];
244 imag_digitsR=[];
245 end
246
247 letters={'y', 'z', 'a', 'f', 'p', 'n', '\mu', 'm', '', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y'};
248
249 if isequal(flag1, 0)
250 if isnumeric(A)
251
252 if isreal(A)
253
254 B=isinf(A);
255 A(B)=sign(A(B)).*10^15;
256
257
258 % Digit furthest to the left of the decimal point
259 D1=ceil(log10(abs(A)));
260 buf1=D1( abs(A)10.^D1 == 0)+1;
261 D1( abs(A)10.^D1 == 0)=buf1;
262
263 % rounding factor
264 dec=10.^(ND1);
265
266 % Rounding Computation
267 % This program supports five different styles of rounding.
268 % flag2 == 1 rounds to the nearest integer
269 % flag2 == 2 rounds up
270 % flag2 == 3 rounds down
271 % flag2 == 4 rounds toward zero
Apndice A. Apndices 26

272 % flag2 == 5 rounds away from zero


273 % otherwise round to the nearest integer
274
275 buf=dec./mult;
276
277 switch flag2
278
279 case 1
280 A2=1./buf.*round(buf.*A);
281 case 2
282 A2=1./buf.*ceil(buf.*A);
283 case 3
284 A2=1./buf.*floor(buf.*A);
285 case 4
286 A2=1./buf.*fix(buf.*A);
287 case 5
288 A2=sign(A)./buf.*ceil(buf.*abs(A));
289 otherwise
290 A2=1./buf.*round(buf.*A);
291 end
292
293 A2(A==0)=0;
294
295 if isequal( SI_prefixes, 1)
296 regime=floor(log10(abs(A2))./3);
297 regime(regime < 9)=0;
298 regime(regime > 9)=0;
299 else
300 regime=zeros(size(A));
301 end
302
303 A2=A2.*10.^(3.*regime);
304
305 % After rounding recalculate the number of significant digits.
306 % The number of digits to the left and right of the decimal
307 % place can be effected by rounding.
308
309 % Digit furthest to the left of the decimal point
310 D1=ceil(log10(abs(A2)));
311 buf1=D1( abs(A2)10.^D1 == 0)+1;
312 D1( abs(A2)10.^D1 == 0)=buf1;
313
314 % Number of digits to the left of the decimal place
315 real_digitsL=max(D1, 0);
316 real_digitsL(A2==0)=0;
317
318 % rounding factor
319 dec=10.^(ND1);
320
321 % Number of digits to the right of the decimal place
322 real_digitsR=max(ND1, 0);
323 real_digitsR(A2==0)=N;
324
325 else
326
327 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
328
329 % Round the real part
330 Ar=real(A);
331
332 B=isinf(Ar);
333 Ar(B)=sign(Ar(B)).*10^15;
334
335 % Digit furthest to the left of the decimal point
336 D1=ceil(log10(abs(Ar)));
337 buf1=D1( abs(Ar)10.^D1 == 0)+1;
338 D1( abs(Ar)10.^D1 == 0)=buf1;
339
340 % rounding factor
341 dec=10.^(ND1);
342
343 % Rounding Computation
344 % This program supports five different styles of rounding.
345 % flag2 == 1 rounds to the nearest integer
346 % flag2 == 2 rounds up
347 % flag2 == 3 rounds down
A.6. Funo arredondamento 27

348 % flag2 == 4 rounds toward zero


349 % flag2 == 5 rounds away from zero
350 % otherwise round to the nearest integer
351
352 buf=dec./mult;
353
354 switch flag2
355 case 1
356 A2r=1./buf.*round(buf.*Ar);
357 case 2
358 A2r=1./buf.*ceil(buf.*Ar);
359 case 3
360 A2r=1./buf.*floor(buf.*Ar);
361 case 4
362 A2r=1./buf.*fix(buf.*Ar);
363 case 5
364 A2r=sign(Ar)./buf.*ceil(buf.*abs(Ar));
365 otherwise
366 A2r=1./buf.*round(buf.*Ar);
367 end
368
369 A2r(Ar==0)=0;
370
371 if isequal( SI_prefixes, 1)
372 regimeR=floor(log10(abs(A2r))./3);
373 regimeR(regimeR < 9)=0;
374 regimeR(regimeR > 9)=0;
375 else
376 regimeR=zeros(size(A));
377 end
378
379 A2r=A2r.*10.^(3.*regimeR);
380
381 % After rounding recalculate the number of significant digits.
382 % The number of digits to the left and right of the decimal
383 % place can be effected by rounding.
384
385 % Digit furthest to the left of the decimal point
386 D1=ceil(log10(abs(A2r)));
387 buf1=D1( abs(A2r)10.^D1 == 0)+1;
388 D1( abs(A2r)10.^D1 == 0)=buf1;
389
390 % Number of digits to the left of the decimal place
391 real_digitsL=max(D1, 0);
392 real_digitsL(A2r==0)=0;
393
394 % rounding factor
395 dec=10.^(ND1);
396
397 % Number of digits to the right of the decimal place
398 real_digitsR=max(ND1, 0);
399 real_digitsR(A2r==0)=N;
400
401 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
402
403 % Round the imaginary part
404 Ai=imag(A);
405
406 B=isinf(Ai);
407 Ai(B)=sign(Ai(B)).*10^15;
408
409
410 % Digit furthest to the left of the decimal point
411 D1=ceil(log10(abs(Ai)));
412 buf1=D1( abs(Ai)10.^D1 == 0)+1;
413 D1( abs(Ai)10.^D1 == 0)=buf1;
414
415 % rounding factor
416 dec=10.^(ND1);
417
418 % Rounding Computation
419 % This program supports five different styles of rounding.
420 % flag2 == 1 rounds to the nearest integer
421 % flag2 == 2 rounds up
422 % flag2 == 3 rounds down
423 % flag2 == 4 rounds toward zero
Apndice A. Apndices 28

424 % flag2 == 5 rounds away from zero


425 % otherwise round to the nearest integer
426
427 buf=dec./mult;
428
429 switch flag2
430 case 1
431 A2i=1./buf.*round(buf.*Ai);
432 case 2
433 A2i=1./buf.*ceil(buf.*Ai);
434 case 3
435 A2i=1./buf.*floor(buf.*Ai);
436 case 4
437 A2i=1./buf.*fix(buf.*Ai);
438 case 5
439 A2i=sign(Ai)./buf.*ceil(buf.*abs(Ai));
440 otherwise
441 A2i=1./buf.*round(buf.*Ai);
442 end
443
444
445 A2i(Ai==0)=0;
446
447 if isequal( SI_prefixes, 1)
448 regimeI=floor(log10(abs(A2i))./3);
449 regimeI(regimeI < 9)=0;
450 regimeI(regimeI > 9)=0;
451 else
452 regimeI=zeros(size(A));
453 end
454
455 A2i=A2i.*10.^(3.*regimeI);
456
457 % After rounding recalculate the number of significant digits.
458 % The number of digits to the left and right of the decimal
459 % place can be effected by rounding.
460
461 % Digit furthest to the left of the decimal point
462 D1=ceil(log10(abs(A2i)));
463 buf1=D1( abs(A2i)10.^D1 == 0)+1;
464 D1( abs(A2i)10.^D1 == 0)=buf1;
465
466 % Number of digits to the left of the decimal place
467 imag_digitsL=max(D1, 0);
468 imag_digitsL(A2i==0)=0;
469
470 % rounding factor
471 dec=10.^(ND1);
472
473 % Number of digits to the right of the decimal place
474 imag_digitsR=max(ND1, 0);
475 imag_digitsR(A2i==0)=N;
476
477 end
478
479 else
480 warningdlg('Error in sd_round Input Matrix A is not numeric');
481 A2=A;
482 end
483 end
484
485 % % Convert the rounded array to string format with specified
486 % % number of significant digits.
487
488 [m1, n1]=size(A);
489
490 A_str=cell(size(A));
491
492 real_digitsL(isinf(real_digitsL))=15;
493 real_digitsR(isinf(real_digitsR))=15;
494
495 imag_digitsL(isinf(imag_digitsL))=15;
496 imag_digitsR(isinf(imag_digitsR))=15;
497
498 rtd=round(real_digitsL+real_digitsR);
499 itd=round(imag_digitsL+imag_digitsR);
A.6. Funo arredondamento 29

500
501
502 % Output the cell array of strings if it is in the output argument list
503 if nargout > 1 && isequal(flag1, 0)
504
505 % This code formats the rounded numbers into a cell array
506 % of strings.
507 if isreal(A)
508
509 for e1=1:m1
510 for e2=1:n1;
511
512 aa2=num2str(A2(e1, e2), ['%', int2str(rtd(e1, e2)), '.', int2str(real_digitsR(e1, e2)), 'f' ])
;
513 if length(aa2) < N && isequal( SI_prefixes, 1)
514 aa2=num2str(A2(e1, e2),['%', int2str(N), '.', int2str(N), 'f']);
515 end
516
517 if isequal( SI_prefixes, 1)
518 A_str{e1, e2}=[aa2 letters{regime(e1, e2)+9}];
519 else
520 A_str{e1, e2}=aa2;
521 end
522
523 end
524 end
525
526 A2=A2.*10.^(3.*regime);
527
528 else
529
530
531 for e1=1:m1
532 for e2=1:n1;
533
534 aa1=num2str(A2r(e1, e2), ['%', int2str(rtd(e1, e2)),'.', int2str(real_digitsR(e1, e2)), 'f' ])
;
535 if length(aa1) < N && isequal( SI_prefixes, 1)
536 aa1=num2str(A2r(e1, e2),['%', int2str(N), '.', int2str(N), 'f']);
537 end
538
539 aa2=num2str(abs(A2i(e1, e2)), ['%', int2str(itd(e1, e2)),'.', int2str(imag_digitsR(e1, e2)), '
f' ]);
540 if length(aa2) < N && isequal( SI_prefixes, 1)
541 aa2=num2str(abs(A2i(e1, e2)),['%', int2str(N), '.', int2str(N), 'f']);
542 end
543
544 if imag(A2i(e1, e2)) 0
545 aa=' + ';
546 else
547 aa=' ';
548 end
549
550 if isequal( SI_prefixes, 1)
551 A_str{e1, e2}= [aa1, letters{regimeR(e1, e2)+9} aa, aa2, letters{regimeI(e1, e2)+9} 'i'];
552 else
553 A_str{e1, e2}= [aa1, aa, aa2, 'i'];
554 end
555
556 end
557 end
558
559
560
561 % Add the real and imaginary parts together
562 A2=A2r.*10.^(3.*regimeR)+i*A2i.*10.^(3.*regimeI);
563
564 end
565
566 else
567 A_str={};
568 end

Das könnte Ihnen auch gefallen