design filter , Hello everyone, I'm trying to run a script I've written that deals with signal modulation and frequency filtering. unfortunately, the software is crashing at runtime while its deal with the "bode", what can i do?
2 次查看(过去 30 天)
显示 更早的评论
Hello everyone, I'm trying to run a script I've written that deals with signal modulation and frequency filtering. unfortunately, the software is crashing at runtime while its deal with the "bode", what can i do?
clc
close all
clear all
m=1;
am=1.8;
fa=20; %400Hz
ta=1/fa;
t=0:ta/999:6*ta;
ym=am*sin(2*pi*fa*t);
figure(1)
subplot(3,1,1);
plot(t,ym)
title('Modulating signal')
ac=am/m;
fc=400000; %400KHz
% tc=1/fc;
% yc=ac*sin(2*pi*fc*t);
yc= am+ac*square(2*pi*fc*t);
subplot(3,1,2);
plot(t,yc);
grid on;
title('Carrier signal')
y=ac+(1+m*sin(2*pi*fa*t)).*square(2*pi*fc*t);
subplot(3,1,3);
plot(t,y);
title('am signal');
grid on
nfft=length(y);
nfft2=2^nextpow2(nfft);
ff=fft(y,nfft2);
figure(2)
plot(abs(ff))
Fs = length(nfft2);
xdft = fftshift(fft(y));
df = Fs/length(y);
freq = -Fs/2:df:Fs/2-df;
plot(freq,abs(xdft))
Fstop = 350;
Fpass = 400;
Astop = 65;
Apass = 0.5;
Fs = 1e3;
d = designfilt('highpassiir','StopbandFrequency',Fstop ,...
'PassbandFrequency',Fpass,'StopbandAttenuation',Astop, ...
'PassbandRipple',Apass,'SampleRate',Fs,'DesignMethod','butter');
figure(3)
fvtool(d);
[a,b]=tf(d);
filter=tf(a,b);
yfilter=y*filter;
figure(4)
bode(y);
0 个评论
采纳的回答
Star Strider
2019-11-18
The bode function is part of the Control System Toolbox (and friends). It takes a system object as an argument. Also, multiplying system objects is the same as connecting them in series, so ‘yfilter’ will not do what you want. If you want the Bode plot of a filter, use the freqz (or freqs) functions, instead. If you want to filter a signal with a Signal Processing Toolbox filter, use the filtfilt function to do the actual filtering.
Please do not name your variables filter or anything else that could overshadow a MATLAB function name.
Your code otherwise appears to be good, and produces a double-sideband-transmitted-carrier AM signal.
2 个评论
Star Strider
2019-11-18
As always, my pleasure!
The freqz funciton will plot the Bode plot of your filter. Please do not multiply it by anything. If you want to use your filter to filter your signal, use the filtfilt function with it.
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Filter Analysis 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!