gpt4 book ai didi

matlab - 在 matlab 中绘制短时傅里叶变换(注意窗口大小和步长)

转载 作者:行者123 更新时间:2023-12-03 02:10:59 26 4
gpt4 key购买 nike

需要帮助,因为有点迷失了这一点。我正在尝试绘制下面的代码,其中我产生了白噪声并使用 STFT 进行带通滤波,但现在我需要将信号绘制成每个 channel 的两个图表。结果应该是图表。对于图 1a.,横轴应该是频率,纵轴应该是幅度。对于(2).b,横轴为时间,纵轴为频率,用颜色表示幅度。

function newwhitenoise()
L = 5000; %Sample length for the random signal
Pause = 10000; %Sample Pause Gap
mu = 0;
sigma = 2;

%Need to see left signal is not displaying
Left_signal = sigma*randn(L,1) + mu;
Right_signal = sigma*randn(L,1) + mu;

Long_signal = [Left_signal zeros(L,1); zeros(Pause,2); zeros(L,1) Right_signal];

%Player Object
soundRecord(Long_signal);


disp([Left_signal zeros(L,1)]);
%sound(Long_signal, Fs);

%Plots subplots in graph
%figure
%subplot(211);
%plot(Left_signal, 'b'); grid on;
%subplot(212);
%plot(Right_signal, 'r'); grid on;
end

function signalplayer(signal)
%load(signal);
fs = 44100; %Sample Frequency
obj = audioplayer(signal,fs);
play(obj);
end

function soundRecord (signal)
fs = 44100; %Sample Frequency
recObj = audiorecorder(44100, 16, 2);
get(recObj)

%save sound to wave file
%filename = 'location.flac';
audiowrite('input.wav',signal, fs);


if ~exist('inFile')
inFile = 'input.wav';
end

if ~exist('outFile')
outFile = 'output.wav';
end

if ~exist('frameWidth')
frameWidth = 4096; % size of FFT frame, better be a power of 2
end
frameHop = frameWidth/2;

analWindow = hanning(frameWidth);

[inBuffer, Fs] = wavread(inFile);

x = [inBuffer(:,1); linspace(0, 0, frameWidth)']; % use left channel only, zeropad one frame at the end

clear inBuffer;

numSamples = length(x);

numFrames = floor(numSamples/frameHop)-1;

% disp(frameWidth);
% disp(numSamples);
% disp(frameHop);
% disp(numFrames);
% disp(size(analWindow));
% disp(size(transpose(analWindow)));

y = linspace(0, 0, numSamples)';


n = 0; % init sample pointer. unlike MATLAB, i like counting from 0

for frameIndex = 1:numFrames

xWindowed = x(n+1:n+frameWidth) .* analWindow; % get and window the input audio frame

X = fft(fftshift(xWindowed)); % do the FFT

Y = X; % copy the input spectrum to output

% do whatever processing to Y that you like

yWindowed = fftshift(real(ifft(Y))); % convert back to time domain, toss the imaginary part
%disp(size(x(1:frameWidth)));
%disp(size(yWindowed));

y(n+1:n+frameWidth) = y(n+1:n+frameWidth) + yWindowed;

n = n + frameHop;
end

wavwrite(y, Fs, 'output.wav');

最佳答案

对于图 1,请尝试 pwelch对于图 2,请尝试 spectrogram .pwelch基本上是 STFT 平方幅度的平均值。 spectrogram函数返回信号的 STFT,因此它在时域中对信号进行操作。
使用相同的输入参数调用这两个函数,并且在没有输出的情况下调用时,将结果绘制在当前轴上。
如果您希望频率轴是图 2 中的垂直 (y),请使用选项 'yaxis'spectrogram 的电话中.我建议您查看这两个函数的文档。

关于matlab - 在 matlab 中绘制短时傅里叶变换(注意窗口大小和步长),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24044832/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com