How make a high pass filter and give input to it simultaneously?
9 次查看(过去 30 天)
显示 更早的评论
I want to implement a line coding scheme with the length of bit sequence = 30. After plotting the bit sequence wrt time and its fourier transform, I need to pass it through a High pass filter with a given cutoff frequency (lets say 100Hz). There are functions on matlab like Highpass but it doesn't pass an input signal into it. Hence How can i make a filter which can have a given cutoff frequency and also passes a custom made input (in the code).
len = 30; %length of waveform
waveform = randi([0,1],1,len); %radnom bit generator of length 30
Tb = 1*10^-6; %bit period
freq = 1/Tb; %bits per second
figure;
[t,s] = uni_nrz(waveform, freq);
subplot(1,2,1);
plot(t,s);
xlabel('time');
ylabel('Voltage');
grid on;
title('Unipolar not return to Zero');
function[t,out] = uni_nrz(waveform, freq)
T = length(waveform)/freq; %time of bit sequence
n = 200; %sampling of waveform
N = n*length(waveform);
delta = T/N;
t = 0:delta:T;
out = zeros(1,length(t)); %initialize output signal as 0
for i = 0:length(waveform)-1 %using i+1 to perform operation on the next bit sequence when
%pervious is already operated upon
if waveform(i+1) == 1
out(i*n+1:(i+1)*n) = 5 * 1; %voltage Vo is ±5V
else
out(i*n+1:(i+1)*n) = 5 * 0;
end
end
subplot(1,2,2);
plot(abs(fft(out)));
xlabel('Frequency');
ylabel('Amplitude');
end
0 个评论
回答(2 个)
Paul
2023-2-25
"How can i make a filter which can have a given cutoff frequency and also passes a custom made input (in the code)."
Check out highpass. Use it by itself if you want the feature of "compensates for the delay introduced by the filter." Otherwise use the second output argument to return the digitalFilter object and use that to filter the input.
0 个评论
Star Strider
2023-2-25
‘There are functions on matlab like Highpass but it doesn't pass an input signal into it.’
Yes, it does!
The input signal is the first argument to the highpass function (and related functions). You can then use the second argument (the digital filter object) with filtfilt to filter other signals with the same filter, so it is not necessary to create the same filter each time.
Try something like this —
Fs = 1E+6;
s = randn(1, 30*Fs);
t = linspace(0, numel(s)-1, numel(s))/Fs;
[s_filt1, df] = highpass(s, 100, Fs, 'ImpulseResponse','iir');
figure
plot(t, s)
hold on
plot(t, s_filt1)
hold off
grid
xlim([0 1/100])
s_filt2 = filtfilt(df, s);
figure
plot(t, s)
hold on
plot(t, s_filt2)
hold off
grid
xlim([0 1/100])
.
0 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!