[未答复] MATLAB使用freqz函数时的错误

[复制链接]
youngman123 发表于 2021-1-13 11:53:24
fs=44100;%#ok
[y,fs]=audioread('F:\信号与系统\01处理前的素材.mp3');  %读入音频,fs为采样频率
N=length(y);
t=[0:N-1]/fs;
plot(t,y);xlabel('x(t)');ylabel('y(t)');
title('每个样本的值');grid;%时域图
ft=44100/N;
F=ft:ft:44100;%快速傅里叶变换
Y=fft(y);
magY=abs(Y);phaY=angle(Y); %幅度和相位
subplot(2,1,1);plot(F,magY);title('幅度响应');grid;
axis([0,44100,0,15000])%绘制原始语音信号的幅度响应
subplot(2,1,2);plot(F,phaY);title('相位响应');grid;
axis([0,44100,-4,4])%绘制原始语音信号的相位响应

%滤波器
fp=1800;fs1=2000;
wp=2*pi*fp/fs;ws=2*pi*fs1/fs;%将模拟频率转换为数字角频率
tr_width=ws-wp;%过渡带
M=ceil(13.0725*pi/tr_width)+1;%滤波器所用窗函数的最小长度
wc=(ws+wp)/2;
hd=ideal_lp(wc,M);
w_parzen=(parzenwin(M));%采用parzenwin窗
h=hd.*w_parzen;%时间域乘积对应于频域的卷积
[db,mag,pha,grd,w]=freqz_m(h,1);delta_w=2*pi/1000;
Rp=-(min(db(1:1:wp/delta_w+1)));%计算通带波纹


错误信息:
错误使用 freqz (line 97)
当第一个输入是矩阵时,它必须恰好有 6 列才是有效的 SOS 矩阵。

出错 freqz_m (line 13)
[H,w] = freqz(b,a,1000,'whole');

出错 audio1 (line 26)
[db,mag,pha,grd,w]=freqz_m(h,1);delta_w=2*pi/1000;


网上找的freqz函数:
function [db,mag,pha,grd,w] = freqz_m(b,a)
% Modified version of freqz subroutine
% ------------------------------------
% [db,mag,pha,grd,w] = freqz_m(b,a);
%  db = Relative magnitude in dB computed over 0 to pi radians
% mag = absolute magnitude computed over 0 to pi radians
% pha = Phase response in radians over 0 to pi radians
% grd = Group delay over 0 to pi radians
%   w = 501 frequency samples between 0 to pi radians
%   b = numerator polynomial of H(z)   (for FIR: b=h)
%   a = denominator polynomial of H(z) (for FIR: a=[1])
%
[H,w] = freqz(b,a,1000,'whole');
    H = (H(1:1:501))'; w = (w(1:1:501))';
  mag = abs(H);
   db = 20*log10((mag+eps)/max(mag));
  pha = angle(H);
%  pha = unwrap(angle(H));
  grd = grpdelay(b,a,w);
%  grd = diff(pha);
%  grd = [grd(1) grd];
%  grd = [0 grd(1:1:500); grd; grd(2:1:501) 0];
%  grd = median(grd)*500/pi;

您需要登录后才可以回帖 登录 | 注册

本版积分规则

热门教程
站长推荐
快速回复 返回顶部 返回列表