【问题标题】:How would i down-sample a .wav file then reconstruct it using nyquist? - in MATLAB我将如何对 .wav 文件进行下采样,然后使用 nyquist 重建它? - 在 MATLAB 中
【发布时间】:2011-05-31 09:07:16
【问题描述】:

这一切都在 MATLAB 2010 中完成

我的目标是显示以下结果:欠采样、奈奎斯特率/过采样

首先,我需要对 .wav 文件进行下采样以获得不完整/或公正的数据流,然后我可以重新构建。

这是我要做什么的流程图所以流程是模拟信号 -> 采样模拟滤波器 -> ADC -> 重采样 -> 重采样 -> DAC -> 重建模拟滤波器

需要达到的目标:

F= 频率

F(Hz=1/s) E.x. 100Hz = 1000(循环/秒) F(s)= 1/(2f)

示例问题:1000 赫兹 = 最高 频率 1/2(1000hz) = 1/2000 = 5x10(-3) sec/cyc 或采样率 5毫秒

这是我第一个使用 matlab 进行信号处理的项目。

到目前为止我有什么。

% Fs = frequency sampled (44100hz or the sampling frequency of a cd)

[test,fs]=wavread('test.wav'); % loads the .wav file
left=test(:,1);

% Plot of the .wav signal time vs. strength

time=(1/44100)*length(left);
t=linspace(0,time,length(left));
plot(t,left)
xlabel('time (sec)');
ylabel('relative signal strength')

**%this is were i would need to sample it at the different frequecys (both above and below and at) nyquist frequency.*I think.***

soundsc(left,fs) % shows the resaultant audio file , which is the same as original ( only at or above nyquist frequency however) 

谁能告诉我如何让它变得更好,以及如何在不同的频率下进行采样?

这是.wav 文件http://www.4shared.com/audio/11xvNmkd/piano.html

编辑:

%Play decimated file ( soundsc(y,fs) ) 
%Play Original file ( soundsc(play,fs ) )
%Play reconstucted File ( soundsc(final,fs) )

[piano,fs]=wavread('piano.wav'); % loads piano
play=piano(:,1); % Renames the file as "play"

t = linspace(0,time,length(play));          % Time vector
x = play;
y = decimate(x,25);

stem(x(1:30)), axis([0 30 -2 2])   % Original signal
title('Original Signal')
figure
stem(y(1:30))                        % Decimated signal
title('Decimated Signal')

%changes the sampling rate

fs1 = fs/2;
fs2 = fs/3;
fs3 = fs/4;
fs4 = fs*2;
fs5 = fs*3;
fs6 = fs*4;

wavwrite(y,fs/25,'PianoDecimation');


%------------------------------------------------------------------

%Downsampled version of piano is now upsampled to the original
[PianoDecimation,fs]=wavread('PianoDecimation.wav'); % loads piano
play2=PianoDecimation(:,1); % Renames the file as "play

%upsampling
UpSampleRatio = 2;  % 2*fs = nyquist rate sampling
play2Up=zeros(length(PianoDecimation)*UpSampleRatio, 1);
play2Up(1:UpSampleRatio:end) = play2; % fill in every N'th sample

%low pass filter

ResampFilt = firpm(44, [0 0.39625 0.60938 1], [1 1 0 0]);


fsUp = (fs*UpSampleRatio)*1;
wavwrite(play2Up,fsUp,'PianoUpsampled');

%Plot2
%data vs time plot
time=(1/44100)*length(play2);
t=linspace(0,time,length(play2));
stem(t,play2)
title('Upsampled graph of piano')
xlabel('time(sec)');
ylabel('relative signal strength')



[PianoUpsampled,fs]=wavread('PianoUpsampled.wav'); % loads piano
final=PianoUpsampled(:,1); % Renames the file as "play"


%-------------------------------------------------------------
%resampleing
[piano,fs]=wavread('piano.wav'); % loads piano
x=piano(:,1); % Renames the file as "play"
m = resample(x,3,2);

原文: http://www.4shared.com/audio/11xvNmkd/piano.html

新: http://www.4shared.com/audio/nTRBNSld/PianoUs.html

【问题讨论】:

  • 你是什么意思,从我之前问过的关于使用 msp430 微控制器的奈奎斯特采样的问题来看,这与此无关。
  • 这意味着您单击绿色复选标记回答您之前的问题之一,就像 in this question 所做的那样。它奖励作者加分,并允许未来的用户和搜索者查看哪个答案最有帮助。
  • 对我关于 msp430 板的问题最有帮助是的。 . .

标签: matlab audio signal-processing resampling


【解决方案1】:

最简单的方法是将采样率更改一个整数因子。 下采样包括通过低通滤波器运行数据然后丢弃样本,而上采样包括插入样本然后通过低通滤波器运行数据(也称为重建滤波器或插值滤波器)。当过滤步骤被跳过或做得不好时,就会发生混叠。因此,为了显示锯齿的效果,我建议您根据需要简单地丢弃或插入样本,然后以新的采样率创建一个新的 WAV 文件。要丢弃样本,您可以:

DownSampleRatio = 2;
%# Normally apply a low pass filter here
leftDown = left(1:DownSampleRatio:end); %# extract every N'th sample
fsDown = fs/DownSampleRatio;
wavwrite(leftDown, fsDown, filename);

要创建示例,您可以:

UpSampleRatio = 2;
leftUp = zeros(length(left)*UpSampleRatio, 1);
leftUp(1:UpSampleRatio:end) = left; %# fill in every N'th sample
%# Normally apply a low pass filter here
fsUp = fs*UpSampleRatio;
wavwrite(leftUp, fsUp, filename);

您可以只播放写入的 WAV 文件来聆听效果。

顺便说一句,您要求改进您的代码 - 我更喜欢将 t 向量初始化为 t = (0:(length(left)-1))/fs;

【讨论】:

  • 完成后它们听起来是否应该一样,当我尝试时,听起来完全不一样。
  • 两个进程都引入了别名,所以不,它们听起来不应该一样。您必须 (a) 确保原始信号的能量不高于 fsDown/2,并且 (b) 包括我上面提到的低通滤波步骤,以使它们听起来相同。
  • 是的,我添加了一个低通滤波器,我在顶部编辑代码以便您可以看到它。
  • 首先,低通滤波器很弱。您需要确保它衰减 fsDown/2 以上的所有内容。其次,在上采样中,您需要将其应用于上采样数据。
  • 低通滤波器?它适用于两者,但是更好的低 lass 过滤器会代替当前的过滤器吗?而不是像克利福德所说的那样进行下采样抽取会更好。 mathworks.com/help/toolbox/signal/decimate.html 我需要找到一种方法将其实现为音频文件而不是正弦波。
【解决方案2】:

您需要的 DSP 技术称为decimation

【讨论】:

  • 是的,我正在网上阅读,我看到了这个。 mathworks.com/help/toolbox/signal/decimate.html 。我试图弄清楚如何用音频文件而不是正弦波来实现它。那么,y=decimate(x,r) 是 x = 音频文件,而 r 是其抽取的因子?
  • @Andrew:他们的示例数据不是正弦波,它是两个正弦波的总和,而音频信号(与任何其他信号一样)是多个不同幅度的正弦波的总和,频率和相位。使用表示音频流的变量和数学生成的变量之间没有区别。您只需使用您的音频样本变量代替它们的 x 变量。 Matlab 有一个函数可以将 WAV 文件读入这样的变量中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2010-12-27
  • 1970-01-01
  • 1970-01-01
  • 2021-11-13
  • 1970-01-01
  • 2015-08-17
  • 1970-01-01
相关资源
最近更新 更多