# R 语言线性回归应用：拟合 iOS 录音波形图

## 引言

1. 录音时绘制音频波形， 音频以 wav 格式保存
2. 再次进入界面，加载 wav，重新渲染音频波形

Lp~=−80+6log2prms dB\tilde{L_p} = -80 + 6 \log_{2} {p_{rms}}\ dB ​L​p​​​~​​=−80+6log​2​​p​rms​​ dB

## 数据收集

# input.csv
x,y
189.215346535,-38.973255
308.318069307,-37.262684
295.73019802,-31.176888
216.20049505,-32.602692
324.167079208,-33.863483
360.544554455,-34.272976
...


## 建立线性回归模型

dat <- read.csv('data/input.csv')
model <- lm(y ~ log(x,2), dat)
summary(model)

Call:
lm(formula = y ~ log(x, 2), data = dat)

Residuals:
Min      1Q  Median      3Q     Max
-9.8691 -2.1822 -0.2096  1.7669 13.9694

Coefficients:
Estimate Std. Error t value Pr(>|t|)
(Intercept) -50.54969    0.41839  -120.8   <2e-16 ***
log(x, 2)     2.96202    0.04657    63.6   <2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

Residual standard error: 3.362 on 1745 degrees of freedom
Multiple R-squared:  0.6986,	Adjusted R-squared:  0.6985
F-statistic:  4045 on 1 and 1745 DF,  p-value: < 2.2e-16

0 条评论